Cleanup
This commit is contained in:
@@ -19,27 +19,16 @@ const HUGE_COST_EXPONENT: int = 1000000
|
|||||||
|
|
||||||
## Currency target updated by this generator.
|
## Currency target updated by this generator.
|
||||||
@export var currency: GameState.CurrencyType = GameState.CurrencyType.gold
|
@export var currency: GameState.CurrencyType = GameState.CurrencyType.gold
|
||||||
## Data resource containing balancing values and defaults.
|
## Data resource containing balancing values and defaults (required).
|
||||||
@export var data: CurrencyGeneratorData
|
@export var data: CurrencyGeneratorData
|
||||||
## Enables per-cycle automatic production when true.
|
## Enables per-cycle automatic production when true.
|
||||||
@export var is_automatic: bool = true
|
@export var is_automatic: bool = true
|
||||||
## If true, `_on_pressed` buys one generator instead of granting click currency.
|
## If true, `_on_pressed` buys one generator instead of granting click currency.
|
||||||
@export var press_buys_generator: bool = true
|
@export var press_buys_generator: bool = true
|
||||||
## Extra multiplier applied to automatic production output.
|
|
||||||
@export var run_multiplier: float = 1.0
|
|
||||||
## Fallback unlocked state when `data` is not assigned.
|
|
||||||
@export var starts_unlocked: bool = true
|
|
||||||
## Fallback availability state when `data` is not assigned.
|
|
||||||
@export var starts_available: bool = true
|
|
||||||
|
|
||||||
## Manual click reward fallback when no data is assigned.
|
|
||||||
@export var click_mantissa: float = 1.0
|
|
||||||
## Exponent for fallback click reward when no data is assigned.
|
|
||||||
@export var click_exponent: int = 0
|
|
||||||
## Cooldown between click/hover grants when no data is assigned.
|
|
||||||
@export var click_cooldown_seconds: float = 0.2
|
|
||||||
## If true, hovering grants click reward every cooldown without pressing.
|
## If true, hovering grants click reward every cooldown without pressing.
|
||||||
@export var grants_click_while_hovering: bool = false
|
@export var grants_click_while_hovering: bool = false
|
||||||
|
## Extra multiplier applied to automatic production output.
|
||||||
|
@export var run_multiplier: float = 1.0
|
||||||
|
|
||||||
## True while the pointer is inside the generator Area2D.
|
## True while the pointer is inside the generator Area2D.
|
||||||
var _mouse_entered: bool = false
|
var _mouse_entered: bool = false
|
||||||
@@ -96,6 +85,8 @@ func _ready() -> void:
|
|||||||
_generator_id = _resolve_generator_id()
|
_generator_id = _resolve_generator_id()
|
||||||
_ensure_registered()
|
_ensure_registered()
|
||||||
cycle_progress_seconds = 0.0
|
cycle_progress_seconds = 0.0
|
||||||
|
if data == null:
|
||||||
|
push_error("CurrencyGenerator '%s' is missing CurrencyGeneratorData." % String(name))
|
||||||
|
|
||||||
## Updates click cooldown/click grants and runs automatic production cycles.
|
## Updates click cooldown/click grants and runs automatic production cycles.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
@@ -204,7 +195,7 @@ func _on_pressed() -> void:
|
|||||||
if not is_available_to_player():
|
if not is_available_to_player():
|
||||||
return
|
return
|
||||||
|
|
||||||
if data != null and press_buys_generator:
|
if press_buys_generator:
|
||||||
buy(1)
|
buy(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -227,28 +218,28 @@ func _try_handle_mouse_click() -> void:
|
|||||||
|
|
||||||
## Grants one click/hover reward if cooldown has elapsed.
|
## Grants one click/hover reward if cooldown has elapsed.
|
||||||
func _try_grant_click_currency() -> void:
|
func _try_grant_click_currency() -> void:
|
||||||
|
if data == null:
|
||||||
|
return
|
||||||
if _remaining_click_cooldown_seconds > 0.0:
|
if _remaining_click_cooldown_seconds > 0.0:
|
||||||
return
|
return
|
||||||
|
|
||||||
_add_currency(_get_click_value())
|
_add_currency(_get_click_value())
|
||||||
_remaining_click_cooldown_seconds = _get_click_cooldown_seconds()
|
_remaining_click_cooldown_seconds = _get_click_cooldown_seconds()
|
||||||
|
|
||||||
## Resolves click reward from data, with exported fallback when data is missing.
|
## Resolves click reward from data.
|
||||||
func _get_click_value() -> BigNumber:
|
func _get_click_value() -> BigNumber:
|
||||||
if data != null:
|
if data == null:
|
||||||
|
return BigNumber.from_float(0.0)
|
||||||
return BigNumber.new(data.click_mantissa, data.click_exponent)
|
return BigNumber.new(data.click_mantissa, data.click_exponent)
|
||||||
return BigNumber.new(click_mantissa, click_exponent)
|
|
||||||
|
|
||||||
## Resolves click cooldown from data, with exported fallback when data is missing.
|
## Resolves click cooldown from data.
|
||||||
func _get_click_cooldown_seconds() -> float:
|
func _get_click_cooldown_seconds() -> float:
|
||||||
if data != null:
|
if data == null:
|
||||||
|
return 0.0
|
||||||
return maxf(data.click_cooldown_seconds, 0.0)
|
return maxf(data.click_cooldown_seconds, 0.0)
|
||||||
return maxf(click_cooldown_seconds, 0.0)
|
|
||||||
|
|
||||||
## Resolves hover-only click-grant mode from data, with exported fallback.
|
## Resolves hover-only click-grant mode from node configuration.
|
||||||
func _grants_click_while_hovering() -> bool:
|
func _grants_click_while_hovering() -> bool:
|
||||||
if data != null:
|
|
||||||
return data.grants_click_while_hovering
|
|
||||||
return grants_click_while_hovering
|
return grants_click_while_hovering
|
||||||
|
|
||||||
## Returns this generator's resolved state id.
|
## Returns this generator's resolved state id.
|
||||||
@@ -334,17 +325,17 @@ func _ensure_registered() -> void:
|
|||||||
GameState.register_generator(_generator_id, _default_unlocked_state(), _default_available_state())
|
GameState.register_generator(_generator_id, _default_unlocked_state(), _default_available_state())
|
||||||
_is_registered = true
|
_is_registered = true
|
||||||
|
|
||||||
## Default unlocked state used at registration time.
|
## Default unlocked state loaded from generator data.
|
||||||
func _default_unlocked_state() -> bool:
|
func _default_unlocked_state() -> bool:
|
||||||
if data != null:
|
if data == null:
|
||||||
|
return false
|
||||||
return data.starts_unlocked
|
return data.starts_unlocked
|
||||||
return starts_unlocked
|
|
||||||
|
|
||||||
## Default available state used at registration time.
|
## Default available state loaded from generator data.
|
||||||
func _default_available_state() -> bool:
|
func _default_available_state() -> bool:
|
||||||
if data != null:
|
if data == null:
|
||||||
|
return false
|
||||||
return data.starts_available
|
return data.starts_available
|
||||||
return starts_available
|
|
||||||
|
|
||||||
## Area2D callback: pointer entered generator interaction region.
|
## Area2D callback: pointer entered generator interaction region.
|
||||||
func _on_area_2d_mouse_entered() -> void:
|
func _on_area_2d_mouse_entered() -> void:
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ extends Resource
|
|||||||
@export var click_mantissa: float = 1.0
|
@export var click_mantissa: float = 1.0
|
||||||
@export var click_exponent: int = 0
|
@export var click_exponent: int = 0
|
||||||
@export var click_cooldown_seconds: float = 0.2
|
@export var click_cooldown_seconds: float = 0.2
|
||||||
@export var grants_click_while_hovering: bool = false
|
|
||||||
|
|
||||||
## Returns cost of next generator
|
## Returns cost of next generator
|
||||||
func cost_next(owned: int) -> float:
|
func cost_next(owned: int) -> float:
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ shape = SubResource("RectangleShape2D_y5m1q")
|
|||||||
script = ExtResource("1_pl17p")
|
script = ExtResource("1_pl17p")
|
||||||
currency = 1
|
currency = 1
|
||||||
data = ExtResource("3_dc82g")
|
data = ExtResource("3_dc82g")
|
||||||
starts_unlocked = false
|
|
||||||
starts_available = false
|
|
||||||
|
|
||||||
[node name="UI" type="Control" parent="." unique_id=452530906]
|
[node name="UI" type="Control" parent="." unique_id=452530906]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|||||||
Reference in New Issue
Block a user