Cleanup
This commit is contained in:
@@ -19,27 +19,16 @@ const HUGE_COST_EXPONENT: int = 1000000
|
||||
|
||||
## Currency target updated by this generator.
|
||||
@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
|
||||
## Enables per-cycle automatic production when true.
|
||||
@export var is_automatic: bool = true
|
||||
## If true, `_on_pressed` buys one generator instead of granting click currency.
|
||||
@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.
|
||||
@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.
|
||||
var _mouse_entered: bool = false
|
||||
@@ -96,6 +85,8 @@ func _ready() -> void:
|
||||
_generator_id = _resolve_generator_id()
|
||||
_ensure_registered()
|
||||
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.
|
||||
func _process(delta: float) -> void:
|
||||
@@ -204,7 +195,7 @@ func _on_pressed() -> void:
|
||||
if not is_available_to_player():
|
||||
return
|
||||
|
||||
if data != null and press_buys_generator:
|
||||
if press_buys_generator:
|
||||
buy(1)
|
||||
return
|
||||
|
||||
@@ -227,28 +218,28 @@ func _try_handle_mouse_click() -> void:
|
||||
|
||||
## Grants one click/hover reward if cooldown has elapsed.
|
||||
func _try_grant_click_currency() -> void:
|
||||
if data == null:
|
||||
return
|
||||
if _remaining_click_cooldown_seconds > 0.0:
|
||||
return
|
||||
|
||||
_add_currency(_get_click_value())
|
||||
_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:
|
||||
if data != null:
|
||||
return BigNumber.new(data.click_mantissa, data.click_exponent)
|
||||
return BigNumber.new(click_mantissa, click_exponent)
|
||||
if data == null:
|
||||
return BigNumber.from_float(0.0)
|
||||
return BigNumber.new(data.click_mantissa, data.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:
|
||||
if data != null:
|
||||
return maxf(data.click_cooldown_seconds, 0.0)
|
||||
return maxf(click_cooldown_seconds, 0.0)
|
||||
if data == null:
|
||||
return 0.0
|
||||
return maxf(data.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:
|
||||
if data != null:
|
||||
return data.grants_click_while_hovering
|
||||
return grants_click_while_hovering
|
||||
|
||||
## 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())
|
||||
_is_registered = true
|
||||
|
||||
## Default unlocked state used at registration time.
|
||||
## Default unlocked state loaded from generator data.
|
||||
func _default_unlocked_state() -> bool:
|
||||
if data != null:
|
||||
return data.starts_unlocked
|
||||
return starts_unlocked
|
||||
if data == null:
|
||||
return false
|
||||
return data.starts_unlocked
|
||||
|
||||
## Default available state used at registration time.
|
||||
## Default available state loaded from generator data.
|
||||
func _default_available_state() -> bool:
|
||||
if data != null:
|
||||
return data.starts_available
|
||||
return starts_available
|
||||
if data == null:
|
||||
return false
|
||||
return data.starts_available
|
||||
|
||||
## Area2D callback: pointer entered generator interaction region.
|
||||
func _on_area_2d_mouse_entered() -> void:
|
||||
|
||||
@@ -27,7 +27,6 @@ extends Resource
|
||||
@export var click_mantissa: float = 1.0
|
||||
@export var click_exponent: int = 0
|
||||
@export var click_cooldown_seconds: float = 0.2
|
||||
@export var grants_click_while_hovering: bool = false
|
||||
|
||||
## Returns cost of next generator
|
||||
func cost_next(owned: int) -> float:
|
||||
|
||||
Reference in New Issue
Block a user