Refactor: restructure world entities and evolution logic; remove unused files and improve batch processing
This commit is contained in:
@@ -17,6 +17,8 @@ var OwniverseEntities: Dictionary = {}
|
||||
var OwniverseItems: Dictionary = {}
|
||||
var Templates: Dictionary = {}
|
||||
|
||||
var batch_count = 40
|
||||
|
||||
|
||||
func get_localized_item_description(item_id: String, item: String) -> String:
|
||||
if Locales[Locale].has(item_id):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://icbk3la71t7h"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bq7xkdvq4iejn" path="res://world/Background/starry_sky_layer.gd" id="1_st4ay"]
|
||||
[ext_resource type="Script" uid="uid://bq7xkdvq4iejn" path="res://world/background/starry_sky_layer.gd" id="1_st4ay"]
|
||||
|
||||
[node name="StarrySkyLayer" type="Parallax2D"]
|
||||
scroll_offset = Vector2(1080, 1920)
|
||||
|
||||
@@ -25,7 +25,6 @@ var batch_count: int = 40
|
||||
var entity_batches = {}
|
||||
|
||||
|
||||
|
||||
func cycle(year_delta: float) -> void:
|
||||
# all owniverse activity should be called here
|
||||
_auto_production(year_delta)
|
||||
@@ -188,8 +187,7 @@ func save_data() -> void:
|
||||
|
||||
func init_enitities() -> void:
|
||||
for entity_id in Global.OwniverseEntities:
|
||||
var entity = OwniverseEntity.new()
|
||||
entity.init_entity(Global.OwniverseEntities[entity_id])
|
||||
var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id])
|
||||
entities[entity_id] = entity
|
||||
|
||||
current_amount[entity_id] = 0
|
||||
@@ -215,8 +213,4 @@ func init_enitities() -> void:
|
||||
entity_event_groups[entity.event_group] = []
|
||||
entity_event_groups[entity.event_group].append(entity_id)
|
||||
|
||||
#if entity.event_group != "":
|
||||
#entity_event_groups.append(entity.id)
|
||||
#print(entity_groups)
|
||||
#print(entity_event_groups)
|
||||
#endregion
|
||||
@@ -0,0 +1,32 @@
|
||||
extends Node
|
||||
|
||||
class_name OwniverseBatch
|
||||
|
||||
var from_year: float
|
||||
var to_year: float
|
||||
|
||||
var amount: float = 0
|
||||
|
||||
|
||||
func process(year: float) -> float:
|
||||
var _amount: float = 0
|
||||
if year < to_year: return 0
|
||||
if year >= to_year:
|
||||
_amount = amount
|
||||
amount = 0
|
||||
return _amount
|
||||
|
||||
_amount = clampf(amount * (year - from_year) / (to_year - from_year), 0, amount)
|
||||
amount -= _amount
|
||||
from_year = year + 1
|
||||
|
||||
return _amount
|
||||
|
||||
|
||||
func add(delta: float) -> void:
|
||||
amount += delta
|
||||
|
||||
|
||||
func _init(year: float, year_delta: float) -> void:
|
||||
from_year = year - year_delta
|
||||
to_year = year + year_delta
|
||||
@@ -0,0 +1 @@
|
||||
uid://cs0mllvnraida
|
||||
@@ -8,7 +8,8 @@ var cost: Dictionary = {}
|
||||
var bind: Dictionary = {}
|
||||
var mass: float
|
||||
var space: int
|
||||
var lifespan: int
|
||||
var lifespan: float
|
||||
var lifespan_cycle: float
|
||||
var auto: float
|
||||
var gamma: float
|
||||
var blast: int
|
||||
@@ -31,7 +32,7 @@ var claim: String
|
||||
var amount: float = 0.0
|
||||
|
||||
|
||||
func init_entity(values: Dictionary) -> void:
|
||||
func _init(values: Dictionary) -> void:
|
||||
id = values.id
|
||||
is_visible = values.is_visible == "1"
|
||||
unlock = _parse_and_string(values.unlock)
|
||||
@@ -39,7 +40,9 @@ func init_entity(values: Dictionary) -> void:
|
||||
bind = _parse_and_string(values.bind)
|
||||
mass = float(values.mass)
|
||||
space = int(values.space)
|
||||
lifespan = int(values.lifespan)
|
||||
lifespan = float(values.lifespan)
|
||||
lifespan_cycle = lifespan / Global.batch_count # need for proper math
|
||||
print(id, " → ", lifespan, " | ", lifespan_cycle)
|
||||
auto = float(values.auto)
|
||||
gamma = float(values.gamma)
|
||||
blast = int(values.blast)
|
||||
@@ -3,11 +3,23 @@ extends Node
|
||||
class_name OwniverseEvolution
|
||||
|
||||
var batch_count: int = 40
|
||||
var entity_batches = {}
|
||||
var batches: Dictionary[String, Array] = {}
|
||||
|
||||
var distribution: Dictionary[String, float] = {}
|
||||
|
||||
|
||||
func evolute():
|
||||
pass
|
||||
|
||||
func add_to_batch(enitity: OwniverseEntity, amount: float, year: float) -> void:
|
||||
var to_year: float = year + enitity.lifespan
|
||||
var _entity_batches: Array[OwniverseBatch] = batches[enitity.id]
|
||||
if _entity_batches.size() == 0 or _entity_batches[-1].to_year <= to_year:
|
||||
_entity_batches.append(OwniverseBatch.new(to_year, enitity.lifespan_cycle))
|
||||
|
||||
_entity_batches[-1].add(amount)
|
||||
|
||||
|
||||
func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
||||
distribution = {}
|
||||
var _total: float = 0
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bv384dpmvjv8o"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d2wrwichuoncd" path="res://world/Background/background.gd" id="1_ifjjt"]
|
||||
[ext_resource type="PackedScene" uid="uid://icbk3la71t7h" path="res://world/Background/starry_sky_layer.tscn" id="2_behgl"]
|
||||
[ext_resource type="Script" uid="uid://d2wrwichuoncd" path="res://world/background/background.gd" id="1_ifjjt"]
|
||||
[ext_resource type="PackedScene" uid="uid://icbk3la71t7h" path="res://world/background/starry_sky_layer.tscn" id="2_behgl"]
|
||||
[ext_resource type="Script" uid="uid://iiva6x8uo0f2" path="res://stage/stage.gd" id="3_k83x5"]
|
||||
[ext_resource type="Texture2D" uid="uid://5f80g4i46ycl" path="res://ui/topmenu/buttons/button.burger.normal.png" id="4_b8tmp"]
|
||||
[ext_resource type="Texture2D" uid="uid://caia36a08wlqs" path="res://ui/topmenu/buttons/button.burger.pressed.png" id="5_en1oy"]
|
||||
|
||||
Reference in New Issue
Block a user