Revamp goals as resources
This commit is contained in:
43
core/goals/goal_data.gd
Normal file
43
core/goals/goal_data.gd
Normal file
@@ -0,0 +1,43 @@
|
||||
class_name GoalData
|
||||
extends Resource
|
||||
|
||||
@export var id: StringName = &""
|
||||
@export var requirements: Array[GoalRequirementData] = []
|
||||
|
||||
func has_id() -> bool:
|
||||
return not String(id).strip_edges().is_empty()
|
||||
|
||||
func get_valid_requirements() -> Array[Resource]:
|
||||
var result: Array[Resource] = []
|
||||
for requirement_resource in requirements:
|
||||
if requirement_resource == null:
|
||||
continue
|
||||
if not bool(requirement_resource.call("is_valid")):
|
||||
continue
|
||||
|
||||
result.append(requirement_resource)
|
||||
|
||||
return result
|
||||
|
||||
func is_valid() -> bool:
|
||||
if not has_id():
|
||||
return false
|
||||
|
||||
return not get_valid_requirements().is_empty()
|
||||
|
||||
func is_met() -> bool:
|
||||
var valid_requirements: Array[Resource] = get_valid_requirements()
|
||||
if valid_requirements.is_empty():
|
||||
return false
|
||||
|
||||
for requirement_resource in valid_requirements:
|
||||
if not bool(requirement_resource.call("is_met")):
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func get_first_requirement_summary() -> String:
|
||||
var valid_requirements: Array[Resource] = get_valid_requirements()
|
||||
if valid_requirements.is_empty():
|
||||
return ""
|
||||
return String(valid_requirements[0].call("get_summary_text"))
|
||||
1
core/goals/goal_data.gd.uid
Normal file
1
core/goals/goal_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dx4kmh33rrkpy
|
||||
42
core/goals/goal_requirement_data.gd
Normal file
42
core/goals/goal_requirement_data.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
class_name GoalRequirementData
|
||||
extends Resource
|
||||
|
||||
@export var currency: Resource
|
||||
@export var amount_mantissa: float = 0.0
|
||||
@export var amount_exponent: int = 0
|
||||
|
||||
func get_currency_id() -> StringName:
|
||||
if currency == null:
|
||||
return &""
|
||||
|
||||
return GameState.get_currency_id(currency)
|
||||
|
||||
func get_amount() -> BigNumber:
|
||||
return BigNumber.new(amount_mantissa, amount_exponent)
|
||||
|
||||
func has_valid_currency() -> bool:
|
||||
var currency_id: StringName = get_currency_id()
|
||||
if currency_id == &"":
|
||||
return false
|
||||
|
||||
return GameState.is_known_currency_id(currency_id)
|
||||
|
||||
func has_valid_amount() -> bool:
|
||||
return get_amount().mantissa >= 0.0
|
||||
|
||||
func is_valid() -> bool:
|
||||
return has_valid_currency() and has_valid_amount()
|
||||
|
||||
func is_met() -> bool:
|
||||
if not is_valid():
|
||||
return false
|
||||
|
||||
var total_amount: BigNumber = GameState.get_total_currency_acquired_by_id(get_currency_id())
|
||||
return not total_amount.is_less_than(get_amount())
|
||||
|
||||
func get_summary_text() -> String:
|
||||
if not is_valid():
|
||||
return ""
|
||||
|
||||
var currency_name: String = GameState.get_currency_name(get_currency_id())
|
||||
return "%s %s" % [get_amount().to_string_suffix(2), currency_name]
|
||||
1
core/goals/goal_requirement_data.gd.uid
Normal file
1
core/goals/goal_requirement_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://r4js5eajolio
|
||||
Reference in New Issue
Block a user