placeholder gun and scripts merge

This commit is contained in:
Alexey 2025-07-14 19:33:59 +03:00
commit 464c5ecfd5
7 changed files with 130 additions and 2 deletions

View file

@ -0,0 +1,49 @@
extends BaseFireMode
## Firemode that fires automatically
class_name AutoFireMode
## Delay between shots [br]
@export var fire_delay : float
## Is fire mode on delay?
var cooldown : bool = false
## Reference to cooldown scene timer
var cooldown_timer : SceneTreeTimer = null
func _on_fire_begin(_tree : SceneTree) -> void:
cooldown = false
check_unfinished_timer(cooldown_timer,on_cooldown_timeout)
func _process(tree : SceneTree) -> void:
if can_fire() :
return
if _fire():
on_fire(tree)
## Invoked when cooldown has ended
func on_cooldown_timeout() -> void:
cooldown = false
cooldown_timer = null
## Checks if timer is unfinished and unbounds to avoid errors
func check_unfinished_timer(timer : SceneTreeTimer, bounded_callable : Callable) -> void:
if timer == null:
return
timer.timeout.disconnect(bounded_callable)
## Checks if can fire
func can_fire() -> bool:
return cooldown
## Invoked when fired
func on_fire(tree : SceneTree) -> void:
cooldown = true
cooldown_timer = tree.create_timer(fire_delay)
cooldown_timer.timeout.connect(on_cooldown_timeout)

View file

@ -0,0 +1 @@
uid://dsvgbyeerw1ld

View file

@ -15,10 +15,15 @@ func _fire() -> bool:
## Invoked when fire button is just pressed or reload ended while fire button is still pressed ## Invoked when fire button is just pressed or reload ended while fire button is still pressed
func _on_fire_begin() -> void: func _on_fire_begin(tree : SceneTree) -> void:
pass pass
## Invoked when fire button is just released or reload started while fire button is still pressed ## Invoked when fire button is just released or reload started while fire button is still pressed
func _on_fire_end() -> void: func _on_fire_end(tree : SceneTree) -> void:
pass
## Invoked every process frame on active fire mode
func _process(tree : SceneTree) -> void:
pass pass

View file

@ -0,0 +1,43 @@
extends AutoFireMode
## Fire mode that fires in bursts
class_name BurstFireMode
## Amount of bullets in burst
@export_range(1,25,1,"or_greater") var burst_amount : int = 1
## Time to reload a burst
@export var reload_time : float
## Amount of bullets currently [br]
## Resets in _on_fire_end
var current_amount : int = 0
## Is burst currently reloading
var reloading : bool = false
## Reference to reload scene timer
var reload_timer : SceneTreeTimer = null
func _on_fire_begin(_tree : SceneTree) -> void:
super._on_fire_begin(_tree)
current_amount = 0
reloading = false
check_unfinished_timer(reload_timer,on_reload_timeout)
func on_fire(tree : SceneTree) -> void:
super.on_fire(tree)
current_amount += 1
if current_amount >= burst_amount:
reloading = true
reload_timer = tree.create_timer(reload_time)
reload_timer.timeout.connect(on_reload_timeout)
## Invoked when reload has ended
func on_reload_timeout() -> void:
reloading = false
current_amount = 0
reload_timer = null

View file

@ -0,0 +1 @@
uid://msfvntjnawy5

View file

@ -0,0 +1,28 @@
extends BaseFireMode
## Firemode that fires single time [br]
## Has optional fire delay
class_name SingleFireMode
## Delay between shots [br]
## Values equal or less than 0 remove delay completely
@export var fire_delay : float
## Is fire mode on delay?
var cooldown : bool = false
func _on_fire_begin(tree) -> void:
if cooldown:
return
if _fire() == false or fire_delay <= 0:
return
cooldown = true
tree.create_timer(fire_delay).timeout.connect(on_cooldown_timeout)
## Invoked when cooldown has ended
func on_cooldown_timeout() -> void:
cooldown = false

View file

@ -0,0 +1 @@
uid://ckexgw71dd5jc