extends Node signal productions_update(p: Array[Production]) @warning_ignore("unused_signal") signal production_log(producer: Currency, p: Production) @export var currencies: Array[Production] @export var members: Array func get_currency(c: Currency) -> Production: sync_currency.call_deferred() for p in currencies: if c == p.currency: return p var p := Production.new() p.currency = c p.amount = 0 currencies.append(p) return p func sync_currency(): var did_remove := true while did_remove: did_remove = false for i in range(len(currencies)): var p: Production = currencies[i] if p.amount == 0: currencies.remove_at(i) did_remove = true break productions_update.emit(currencies) func get_currency_amount(currency: Currency) -> int: var c := get_currency(currency) return c.amount func can_consume(production: Production) -> bool: return get_currency_amount(production.currency) >= production.amount func produce(production: Production): sync_currency.call_deferred() var c := get_currency(production.currency) c.amount += production.amount func simulate(): productions_update.emit.call_deferred(currencies) for c in currencies: for p in c.currency.production: var pp := Production.new() pp.currency = p.currency pp.amount = c.amount * p.amount produce(pp) func _ready() -> void: simulate()