Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion game/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ config_version=5

[application]

config/name="Langjam Game"
config/name="Gamma cooked"
run/main_scene="uid://ce1jmpre2oxkg"
config/features=PackedStringArray("4.5", "GL Compatibility")
config/icon="res://icon.svg"

Expand Down
87 changes: 87 additions & 0 deletions game/rule_entity_parent.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
extends Node

var initializing = true

# Set a property on an entity
func set_entity_property(obj: Object, property_name: StringName, value: Variant):
obj.set(property_name, value)
obj.set_meta(property_name, value)

func set_entity_property_deferred(obj: Object, property_name: StringName, value: Variant):
obj.set_deferred(property_name, value)
obj.call_deferred("set_meta", property_name, value)

func get_entity_property(obj: Object, property_name: StringName) -> Variant:
var v = obj.get(property_name)
if v != null:
return v
if property_name in obj.get_meta_list():
return obj.get_meta(property_name)
return null

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass
#for c in get_children():
#var e = SimEntity.new(c)
#entities.push_back(e)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass

var sad_texture: Texture2D = load("res://textures/sad1.svg")

# Perform a deferred update using a recording object.
# fn must:
# * Be pure
# * Only use state it captured when it was created (not new global state)
# * Be commutative and associated with all other updates on the property.
# If these conditions are met, the order of updates should not be observable, so the order of
# rule execution should not be observable.
func deferred_update(record: Dictionary, obj: Object, property_name: StringName, fn):
var key = [obj, property_name]
var v = record.get(key)
if v == null:
v = get_entity_property(obj, property_name)
v = fn.call(v)
record[key] = v

func _physics_process(_delta: float) -> void:
var recorded: Dictionary = {}
for a in get_children():
if initializing:
deferred_update(recorded, a, StringName("friend"), func(_v): return "None")
for b in get_children():
if a == b:
continue
#if get_entity_property(b, StringName("moving")):
var a_offset: Vector2 = get_entity_property(a, StringName("position"))
var b_offset: Vector2 = get_entity_property(b, StringName("position"))
if a_offset.distance_to(b_offset) < 20:
deferred_update(recorded, a, StringName("friend"), func(_v): return b.name)
if a_offset.distance_to(b_offset) < 100:
var vel = (a_offset - b_offset) / 100
deferred_update(recorded, a, StringName("position"), func (v): return v - vel)

if get_entity_property(a, StringName("emotional")):
for b in get_children():
if a == b:
continue
var a_offset: Vector2 = get_entity_property(a, StringName("position"))
var b_offset = get_entity_property(b, StringName("position"))
if a_offset.distance_to(b_offset) < 10:
deferred_update(recorded, a, StringName("texture"), func (_v): return sad_texture)

if get_entity_property(a, StringName("moving")):
var offset = get_entity_property(a, StringName("position"))
if offset != null:
deferred_update(recorded, a, StringName("position"), func (v):
v.x += 1
return v
)

for k in recorded.keys():
set_entity_property(k[0], k[1], recorded[k])

initializing = false
1 change: 1 addition & 0 deletions game/rule_entity_parent.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b4s1n6b74hrj0
21 changes: 17 additions & 4 deletions game/test_scene.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
[gd_scene load_steps=2 format=3 uid="uid://ce1jmpre2oxkg"]
[gd_scene load_steps=4 format=3 uid="uid://ce1jmpre2oxkg"]

[ext_resource type="Texture2D" uid="uid://cy64oitmrt583" path="res://icon.svg" id="1_uhqqe"]
[ext_resource type="Script" uid="uid://b4s1n6b74hrj0" path="res://rule_entity_parent.gd" id="1_uhqqe"]
[ext_resource type="Texture2D" uid="uid://ecg3llvsdms" path="res://textures/wink.svg" id="2_ia1lp"]
[ext_resource type="Texture2D" uid="uid://cy64oitmrt583" path="res://icon.svg" id="3_sasra"]

[node name="Node2D" type="Node2D"]
script = ExtResource("1_uhqqe")

[node name="Line2D" type="Line2D" parent="."]
position = Vector2(-5, 36)
points = PackedVector2Array(0, 0, 30, 50)

[node name="Sprite2D2" type="Sprite2D" parent="."]
position = Vector2(801, 177)
texture = ExtResource("3_sasra")

[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(414, 299)
texture = ExtResource("1_uhqqe")
position = Vector2(399, 173)
texture = ExtResource("2_ia1lp")
metadata/moving = true
metadata/emotional = true
40 changes: 40 additions & 0 deletions game/textures/happy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions game/textures/happy.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://502oh1bix4id"
path="res://.godot/imported/happy.svg-fd33a7aeedbdafea8797b06b9dd0664e.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://textures/happy.svg"
dest_files=["res://.godot/imported/happy.svg-fd33a7aeedbdafea8797b06b9dd0664e.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
58 changes: 58 additions & 0 deletions game/textures/sad1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions game/textures/sad1.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://c6njtxqwr03s2"
path="res://.godot/imported/sad1.svg-ff4ee8724c479ec02c56521325058822.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://textures/sad1.svg"
dest_files=["res://.godot/imported/sad1.svg-ff4ee8724c479ec02c56521325058822.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
58 changes: 58 additions & 0 deletions game/textures/sad2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading