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 OwniverseItems: Dictionary = {}
|
||||||
var Templates: Dictionary = {}
|
var Templates: Dictionary = {}
|
||||||
|
|
||||||
|
var batch_count = 40
|
||||||
|
|
||||||
|
|
||||||
func get_localized_item_description(item_id: String, item: String) -> String:
|
func get_localized_item_description(item_id: String, item: String) -> String:
|
||||||
if Locales[Locale].has(item_id):
|
if Locales[Locale].has(item_id):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[gd_scene format=3 uid="uid://icbk3la71t7h"]
|
[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"]
|
[node name="StarrySkyLayer" type="Parallax2D"]
|
||||||
scroll_offset = Vector2(1080, 1920)
|
scroll_offset = Vector2(1080, 1920)
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ var batch_count: int = 40
|
|||||||
var entity_batches = {}
|
var entity_batches = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func cycle(year_delta: float) -> void:
|
func cycle(year_delta: float) -> void:
|
||||||
# all owniverse activity should be called here
|
# all owniverse activity should be called here
|
||||||
_auto_production(year_delta)
|
_auto_production(year_delta)
|
||||||
@@ -188,8 +187,7 @@ func save_data() -> void:
|
|||||||
|
|
||||||
func init_enitities() -> void:
|
func init_enitities() -> void:
|
||||||
for entity_id in Global.OwniverseEntities:
|
for entity_id in Global.OwniverseEntities:
|
||||||
var entity = OwniverseEntity.new()
|
var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id])
|
||||||
entity.init_entity(Global.OwniverseEntities[entity_id])
|
|
||||||
entities[entity_id] = entity
|
entities[entity_id] = entity
|
||||||
|
|
||||||
current_amount[entity_id] = 0
|
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] = []
|
||||||
entity_event_groups[entity.event_group].append(entity_id)
|
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
|
#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 bind: Dictionary = {}
|
||||||
var mass: float
|
var mass: float
|
||||||
var space: int
|
var space: int
|
||||||
var lifespan: int
|
var lifespan: float
|
||||||
|
var lifespan_cycle: float
|
||||||
var auto: float
|
var auto: float
|
||||||
var gamma: float
|
var gamma: float
|
||||||
var blast: int
|
var blast: int
|
||||||
@@ -31,7 +32,7 @@ var claim: String
|
|||||||
var amount: float = 0.0
|
var amount: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
func init_entity(values: Dictionary) -> void:
|
func _init(values: Dictionary) -> void:
|
||||||
id = values.id
|
id = values.id
|
||||||
is_visible = values.is_visible == "1"
|
is_visible = values.is_visible == "1"
|
||||||
unlock = _parse_and_string(values.unlock)
|
unlock = _parse_and_string(values.unlock)
|
||||||
@@ -39,7 +40,9 @@ func init_entity(values: Dictionary) -> void:
|
|||||||
bind = _parse_and_string(values.bind)
|
bind = _parse_and_string(values.bind)
|
||||||
mass = float(values.mass)
|
mass = float(values.mass)
|
||||||
space = int(values.space)
|
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)
|
auto = float(values.auto)
|
||||||
gamma = float(values.gamma)
|
gamma = float(values.gamma)
|
||||||
blast = int(values.blast)
|
blast = int(values.blast)
|
||||||
@@ -3,11 +3,23 @@ extends Node
|
|||||||
class_name OwniverseEvolution
|
class_name OwniverseEvolution
|
||||||
|
|
||||||
var batch_count: int = 40
|
var batch_count: int = 40
|
||||||
var entity_batches = {}
|
var batches: Dictionary[String, Array] = {}
|
||||||
|
|
||||||
var distribution: Dictionary[String, float] = {}
|
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:
|
func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
||||||
distribution = {}
|
distribution = {}
|
||||||
var _total: float = 0
|
var _total: float = 0
|
||||||
@@ -18,7 +30,7 @@ func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
|||||||
distribution[id] = _value
|
distribution[id] = _value
|
||||||
|
|
||||||
if _total == 0: return
|
if _total == 0: return
|
||||||
|
|
||||||
for id in distribution:
|
for id in distribution:
|
||||||
distribution[id] /= _total
|
distribution[id] /= _total
|
||||||
|
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
[gd_scene format=3 uid="uid://bv384dpmvjv8o"]
|
[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="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="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="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://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"]
|
[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