2026-03-30 00:48:20 +03:00
|
|
|
extends Node
|
|
|
|
|
class_name Owniverse
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
signal unlock_item(item_id: String)
|
|
|
|
|
|
2026-03-30 00:48:20 +03:00
|
|
|
var g_datetime: float = 0
|
|
|
|
|
var g_speed: int = 1
|
2026-04-05 20:15:07 +03:00
|
|
|
var g_speed_in_years = 1
|
2026-04-08 00:23:22 +03:00
|
|
|
|
2026-05-05 23:49:12 +03:00
|
|
|
var entities: Dictionary[String, OwniverseEntity] = {}
|
|
|
|
|
|
|
|
|
|
var items_to_update: Dictionary[String, float] = {}
|
|
|
|
|
|
|
|
|
|
var cumulative_amount: Dictionary[String, float] = {}
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
var auto_production: Array = []
|
|
|
|
|
var locked_entities: Array = []
|
|
|
|
|
|
2026-05-05 23:49:12 +03:00
|
|
|
#region Production
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
func cycle(delta: float) -> void:
|
|
|
|
|
_check_locked_items()
|
|
|
|
|
|
|
|
|
|
|
2026-05-05 23:49:12 +03:00
|
|
|
func produce(item_id: String, amount: int) -> void:
|
2026-05-31 10:57:44 +03:00
|
|
|
#if item_id == "S" or item_id == 'H':
|
|
|
|
|
#entities[item_id].amount += 1
|
|
|
|
|
entities[item_id].amount += amount
|
2026-05-26 23:21:44 +03:00
|
|
|
var entity: OwniverseEntity = entities[item_id]
|
|
|
|
|
_process_enitity(entity, amount)
|
2026-05-05 23:49:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
func automated_production(_delta: float) -> void:
|
|
|
|
|
for entity_id in auto_production:
|
|
|
|
|
var entity = entities[entity_id]
|
|
|
|
|
var amount_to_produce = int(entity.amount * entity.product_per_year_amount * _delta)
|
2026-05-05 23:49:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# add to all lists
|
2026-05-26 23:21:44 +03:00
|
|
|
func _process_enitity(entity: OwniverseEntity, amount: int) -> void:
|
|
|
|
|
_count_cumulative(entity, amount)
|
|
|
|
|
|
|
|
|
|
items_to_update[entity.id] = entity.amount
|
2026-05-05 23:49:12 +03:00
|
|
|
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
func _count_cumulative(entity: OwniverseEntity, amount: int) -> void:
|
|
|
|
|
cumulative_amount[entity.id] += amount
|
|
|
|
|
if entity.group_as != "":
|
|
|
|
|
cumulative_amount[entity.group_as] += amount
|
2026-05-05 23:49:12 +03:00
|
|
|
|
|
|
|
|
|
2026-05-26 23:21:44 +03:00
|
|
|
func _check_locked_items() -> void:
|
|
|
|
|
for entity:OwniverseEntity in locked_entities:
|
|
|
|
|
for elem in entity.unlock:
|
|
|
|
|
if cumulative_amount[elem] < entity.unlock[elem]:
|
|
|
|
|
continue
|
2026-05-31 10:57:44 +03:00
|
|
|
#print(entity.id, " ", elem, ":", entity.unlock[elem])
|
2026-05-26 23:21:44 +03:00
|
|
|
unlock_item.emit(entity.id)
|
|
|
|
|
locked_entities.erase(entity)
|
2026-05-31 10:57:44 +03:00
|
|
|
return # SIC!
|
2026-05-26 23:21:44 +03:00
|
|
|
|
2026-05-05 23:49:12 +03:00
|
|
|
#endregion
|
|
|
|
|
|
2026-04-08 00:23:22 +03:00
|
|
|
|
|
|
|
|
func init_enitities() -> void:
|
|
|
|
|
for entity_id in Global.OwniverseEntities:
|
|
|
|
|
var entity = OwniverseEntity.new()
|
|
|
|
|
entity.init_entity(Global.OwniverseEntities[entity_id])
|
2026-05-05 23:49:12 +03:00
|
|
|
entities[entity_id] = entity
|
2026-05-26 23:21:44 +03:00
|
|
|
|
|
|
|
|
cumulative_amount[entity_id] = 0
|
|
|
|
|
cumulative_amount[entity.group_as] = 0
|
|
|
|
|
|
|
|
|
|
if entity.unlock != {}:
|
|
|
|
|
locked_entities.append(entity)
|
|
|
|
|
|
|
|
|
|
if entity.product_per_year_type != "":
|
|
|
|
|
auto_production.append(entity)
|
2026-05-05 23:49:12 +03:00
|
|
|
|
2026-04-08 00:23:22 +03:00
|
|
|
|
2026-03-30 00:48:20 +03:00
|
|
|
func add_time_delta(delta) -> float:
|
2026-05-26 23:21:44 +03:00
|
|
|
var year_delta: float = delta * g_speed_in_years
|
2026-04-05 20:15:07 +03:00
|
|
|
|
|
|
|
|
# all ownivewrse activity should be called here
|
|
|
|
|
|
|
|
|
|
g_datetime += year_delta
|
2026-03-30 00:48:20 +03:00
|
|
|
return g_datetime
|
|
|
|
|
|
2026-05-05 23:49:12 +03:00
|
|
|
|
2026-04-05 20:15:07 +03:00
|
|
|
func change_speed(delta: int) -> int:
|
|
|
|
|
g_speed = clamp(g_speed + delta, 1, Global.SPEED_LIMIT)
|
2026-05-26 23:21:44 +03:00
|
|
|
g_speed_in_years = pow(10, g_speed - 1)
|
2026-04-05 20:15:07 +03:00
|
|
|
return g_speed
|