Skip to content

Commit

Permalink
World State Dictionary (WIP) + some fixes
Browse files Browse the repository at this point in the history
World State Dictionary:
- CogitoPlayerState now saves an additional dictionary called world_dictionary. This is meant for global world state variables.
- After some experiments and talking to @OvercastInteractive , this seems like the easiest implementation of saving some world state properties and variables that can be user defined.
- This works at runtime but doesn't seem to save/load properly yet.
- See the doc for how this is supposed to work.

Example to test are the laboratory ceiling fans:
- The rotator tool script can check for a world dict value.
- The dict value is set in the lobby via a switch thats using the world_property_setter script.

Other:
- Fixed cogito attribute clamping (thanks @OvercastInteractive )
- Fixed save state file name issues
- PauseMenu: Cleaned up save file timestap display when no save file exists yet
  • Loading branch information
Phazorknight committed Nov 26, 2024
1 parent b80023e commit 215cee5
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![COGITO_banner](docs/Cogito_capsule_202402_jpg.jpg)
# COGITO
[![GodotEngine](https://img.shields.io/badge/Godot_4.3_stable-blue?logo=godotengine&logoColor=white)](https://godotengine.org/) [![COGITO](https://img.shields.io/badge/beta_202411-35A1D7?label=COGITO&labelColor=0E887A)](https://github.com/Phazorknight/Cogito)
beta 202411.02
beta 202411.03

## What is it?
COGITO is a first Person Immersive Sim Template Project for Godot Engine 4.
Expand Down
2 changes: 1 addition & 1 deletion addons/cogito/CogitoObjects/cogito_door.gd
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func set_state():

object_state_updated.emit(interaction_text)
lock_state_updated.emit(lock_interaction_text)
print(lock_interaction_text)


func set_to_open_position():
if door_type == DoorType.SLIDING:
Expand Down
2 changes: 1 addition & 1 deletion addons/cogito/CogitoObjects/cogito_keypad.gd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func append_to_entered_code(_code_digit:String):
if entered_code.length() == passcode.length():
check_entered_code()
else:
print("Maximum code length reached")
CogitoGlobals.debug_log(true, "cogito_keypad.gd", "Maximum code length reached")


func update_code_display():
Expand Down
2 changes: 2 additions & 0 deletions addons/cogito/CogitoObjects/cogito_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ var visibility_attribute : CogitoAttribute
### CURRENCIES
var player_currencies: Dictionary

var world_dictionary: Dictionary

## STAIR HANDLING STUFF
const WALL_MARGIN : float = 0.001
const STEP_DOWN_MARGIN : float = 0.01
Expand Down
2 changes: 2 additions & 0 deletions addons/cogito/Components/Attributes/cogito_attribute.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ var value_current : float:
var prev_value = value_current
value_current = value
if prev_value < value_current:
value_current = clamp(value_current, 0, value_max)
attribute_changed.emit(attribute_name,value_current,value_max,true)
elif prev_value > value_current:
value_current = clamp(value_current, 0, value_max)
attribute_changed.emit(attribute_name,value_current,value_max,false)

if value_current <= 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func _ready():
if parent_object.has_signal("body_entered"):
parent_object.body_entered.connect(_on_body_entered) #Connecting to body entered signal
else:
print(parent_object.name, ": CarriableComponent needs to be child to a RigidBody3D to work.")
CogitoGlobals.debug_log(true,"CarryableComponent.gd", parent_object.name + ": CarriableComponent needs to be child to a RigidBody3D to work.")


func interact(_player_interaction_component:PlayerInteractionComponent):
Expand Down
20 changes: 12 additions & 8 deletions addons/cogito/Components/Properties/cogito_properties.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ enum MaterialProperties{
@export var audio_burning : AudioStream
@export var audio_extinguishing : AudioStream

@export_group("Debuging")
## If turned on, this object will print log messages (only if the global is_logging is turned on as well!)
@export var is_logging : bool = true

var reaction_collider : Node3D = null
var spawned_effects : Array[Node] # Used to store and clear out spawned effects
var is_on_fire : bool = false
Expand Down Expand Up @@ -92,7 +96,7 @@ func _ready():
func start_reaction_threshold_timer(passed_collider: Node3D):
# Quick check to see if the collider has any CogitoProperties.
if( !passed_collider.cogito_properties):
print("Collider ", passed_collider.name, " has no properties.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", "Collider " + passed_collider.name + " has no properties.")
return

# Saving passed collider to make sure we're reaction to the right thing.
Expand All @@ -111,7 +115,7 @@ func check_for_reaction_timer_interrupt(passed_collider: Node3D):

# Quick check to see if the collider has any CogitoProperties.
if( !passed_collider.cogito_properties):
print("Collider ", passed_collider.name, " has no properties.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", "Collider " + passed_collider.name + " has no properties.")
return

remove_systemic_body(passed_collider)
Expand All @@ -130,7 +134,7 @@ func check_for_reaction_timer_interrupt(passed_collider: Node3D):

func check_for_systemic_reactions():
if !reaction_collider:
print("Reaction collider was null.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd","Reaction collider was null.")
return
if !reaction_collider.cogito_properties:
# Case where the object has no properties defined.
Expand Down Expand Up @@ -212,7 +216,7 @@ func set_on_fire():
audio_stream_player_3d.stream = audio_burning
audio_stream_player_3d.play()
else:
print(get_parent().name, " is not FLAMMABLE.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", get_parent().name + " is not FLAMMABLE.")


func start_burn_damage_timer():
Expand Down Expand Up @@ -242,7 +246,7 @@ func extinguish():

func clear_spawned_effects():
for node in spawned_effects:
print("CogitoProperties: Clearing out spawned effect ", node)
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", "Clearing out spawned effect " + node.name)
node.queue_free()
spawned_effects.clear()

Expand All @@ -251,12 +255,12 @@ func make_electric():
if elemental_properties & ElementalProperties.CONDUCTIVE:
is_electric = true
spawn_elemental_vfx(spawn_on_electrified)
print(get_parent().name, " has become electric.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", get_parent().name + " has become electric.")
has_become_electric.emit()

recheck_systemic_reactions()
else:
print(get_parent().name, " is not CONDUCTIVE.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", get_parent().name + " is not CONDUCTIVE.")


func loose_electricity():
Expand Down Expand Up @@ -290,7 +294,7 @@ func remove_systemic_body(body: Node3D):

func recheck_systemic_reactions():
if reaction_bodies.size() < 1:
print(get_parent().name, " systemic properties: Can't recheck reactions as there's no reaction bodies stored.")
CogitoGlobals.debug_log(is_logging, "cogito_properties.gd", get_parent().name + " systemic properties: Can't recheck reactions as there's no reaction bodies stored.")
return

for reaction_body in reaction_bodies:
Expand Down
27 changes: 22 additions & 5 deletions addons/cogito/DemoScenes/COGITO_3_Lobby.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=366 format=4 uid="uid://e31n36p8i6an"]
[gd_scene load_steps=367 format=4 uid="uid://e31n36p8i6an"]

[ext_resource type="Script" path="res://addons/cogito/SceneManagement/cogito_scene.gd" id="1_dracg"]
[ext_resource type="Texture2D" uid="uid://sdcljx8f5dhj" path="res://addons/cogito/Assets/hdris/kloofendal_48d_partly_cloudy_puresky_2k.hdr" id="2_a8imk"]
Expand Down Expand Up @@ -102,6 +102,7 @@
[ext_resource type="PackedScene" uid="uid://bn04jtk86pe0w" path="res://addons/cogito/DemoScenes/DemoPrefabs/cogito_sittable.tscn" id="93_cmkbc"]
[ext_resource type="PackedScene" uid="uid://tkwv6b5arrw2" path="res://addons/cogito/PackedScenes/Pickups/pickup_coins.tscn" id="93_phwoo"]
[ext_resource type="PackedScene" uid="uid://dpuhybufkdmcf" path="res://addons/cogito/DemoScenes/DemoPrefabs/bear_trap.tscn" id="96_vec6d"]
[ext_resource type="Script" path="res://addons/cogito/SceneManagement/world_property_setter.gd" id="103_1du1g"]

[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_wjbty"]
panorama = ExtResource("2_a8imk")
Expand Down Expand Up @@ -132,7 +133,7 @@ volumetric_fog_temporal_reprojection_amount = 0.85
density = 0.04
albedo = Color(0.694118, 0.694118, 0.694118, 1)

[sub_resource type="Resource" id="Resource_ykh2n"]
[sub_resource type="Resource" id="Resource_7sgqj"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -2426,7 +2427,7 @@ shadow_mesh = SubResource("ArrayMesh_3ecdw")
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_upcaa"]
data = PackedVector3Array(0.6928, 0.0903, -1.6, 0, 0.0903, -1.2, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, 0.0903, -0.88, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 1.3856, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -1.2, 0.6128, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.6128, 0.0903, -0.72, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.72, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 0, 0.0903, -1.2, 0, 0.0903, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 1.3856, 0.0903, -0.4, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -1.2, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -1.2, 0.6928, 0.1935, 0, 0, 0.1935, -0.4, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -1.2, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, -1.6, 0.6928, 0.0903, -1.6, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -0.4, 1.3856, 0.0903, -0.4, 0.6928, 0.0903, 0, 0.6928, 0.0903, 0, 0.6928, 0.1935, 0, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.0903, 0, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.1935, -0.4, 0.6928, 0.1935, 0, 0, 0.1935, -1.2, 0, 0.1935, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.8, 0, 0.1935, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -1.2, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.6928, 0.0903, -1.6, 0.6928, 0.1935, -1.6, 0, 0.1935, -1.2, 0.7728, 0.0903, -0.72, 0.7728, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.88, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.6128, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.8128, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.68, 0.6128, -0.4, -0.72, 0.7728, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.72, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.6128, -0.4, -0.88, 0.6128, -0.4, -0.72, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.4, -0.92, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.7728, -0.4, -0.88, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.88, 0.4928, -0.44, -1, 0.4928, -0.44, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -1, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.4928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.5, -1, 0.8928, -0.5, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -1, 0.8928, -0.5, -1, 0.4928, -0.44, -0.6, 0.4928, -0.44, -1, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.4928, -0.44, -0.6, 0.5728, -0.44, -0.68, 0.8128, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.68, 0.8128, -0.44, -0.92, 0.8928, -0.44, -0.6, 0.5728, -0.44, -0.92, 0.5728, -0.44, -0.68, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -1, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8128, -0.44, -0.92, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.92, 0.9128, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.9128, -0.54, -0.58, 0.9128, -0.54, -1.02, 0.4928, -0.5, -1, 0.4728, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.8928, -0.5, -1, 0.4928, -0.5, -1, 0.9128, -0.54, -1.02, 0.9128, -0.54, -0.58, 0.8928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.8928, -0.5, -1, 0.9128, -0.54, -1.02, 0.8928, -0.5, -0.6, 0.9128, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4728, -0.54, -0.58, 0.4728, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4928, -0.5, -1, 0.4928, -0.5, -0.6, 0.5728, -0.4, -0.92, 0.5728, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.4, -0.92, 0.5728, -0.4, -0.92)

[sub_resource type="Resource" id="Resource_i5e2s"]
[sub_resource type="Resource" id="Resource_ni2hk"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -3168,7 +3169,7 @@ material = SubResource("FogMaterial_4avjx")

[node name="Player" parent="." instance=ExtResource("3_mgle8")]
transform = Transform3D(-1, 0, 7.45058e-07, 0, 1, 0, -7.45058e-07, 0, -1, 3.03073, 0.905039, -17.9321)
inventory_data = SubResource("Resource_ykh2n")
inventory_data = SubResource("Resource_7sgqj")
step_height_camera_lerp = 1.5

[node name="QUESTS" type="Node3D" parent="."]
Expand Down Expand Up @@ -6992,7 +6993,7 @@ shape = SubResource("ConcavePolygonShape3D_upcaa")

[node name="kitchenFridgeContainer2" parent="BREAK_ROOM" instance=ExtResource("57_fdyfl")]
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 3.65301, -4.84288e-08, 6.17191)
inventory_data = SubResource("Resource_i5e2s")
inventory_data = SubResource("Resource_ni2hk")

[node name="kitchenMicrowave2" parent="BREAK_ROOM" instance=ExtResource("61_1x4um")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.98491, 0.84, 6.39503)
Expand Down Expand Up @@ -7849,6 +7850,21 @@ transform = Transform3D(0.225393, 0, -0.974268, 0, 1, 0, 0.974268, 0, 0.225393,
[node name="Coins2" parent="." instance=ExtResource("93_phwoo")]
transform = Transform3D(-0.821508, 0, -0.570197, 0, 1, 0, 0.570197, 0, -0.821508, -1.33015, 0.86935, -11.3396)

[node name="LabPowerSwitch" parent="." instance=ExtResource("66_4pwwj")]
transform = Transform3D(-1, 8.74228e-08, -3.82137e-15, 0, -4.37114e-08, -1, -8.74228e-08, -1, 4.37114e-08, -4.43584, 3.70623, 9.74427)
is_on = true
interaction_text_when_on = "Lab power off"
interaction_text_when_off = "Lab power on"

[node name="Set_LabPower" type="Node" parent="LabPowerSwitch"]
script = ExtResource("103_1du1g")
properties_to_set_ON = {
"lab_power": true
}
properties_to_set_OFF = {
"lab_power": false
}

[connection signal="body_entered" from="QUESTS/Archive_QuestStarter" to="QUESTS/Archive_QuestStarter" method="_on_body_entered"]
[connection signal="body_entered" from="QUESTS/Laptop_QuestStarter" to="QUESTS/Laptop_QuestStarter" method="_on_body_entered"]
[connection signal="body_entered" from="QUESTS/Archive_QuestEnder" to="QUESTS/Archive_QuestEnder" method="_on_body_entered"]
Expand All @@ -7857,6 +7873,7 @@ transform = Transform3D(-0.821508, 0, -0.570197, 0, 1, 0, 0.570197, 0, -0.821508
[connection signal="pressed" from="ARCHIVE/CameraButton" to="ARCHIVE/SecurityCamera" method="turn_off"]
[connection signal="body_entered" from="CUBICLE_AREA/WaterFeature/WetZone" to="CUBICLE_AREA/WaterFeature/WetZone" method="_on_body_entered"]
[connection signal="body_entered" from="CUBICLE_AREA/WaterFeature2/WetZone2" to="CUBICLE_AREA/WaterFeature2/WetZone2" method="_on_body_entered"]
[connection signal="switched" from="LabPowerSwitch" to="LabPowerSwitch/Set_LabPower" method="on_bool_signal"]

[editable path="UPPER_OFFICE_CEO/WindowedDoor"]
[editable path="ARCHIVE/ArchiveDoor"]
Expand Down
4 changes: 2 additions & 2 deletions addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ volumetric_fog_ambient_inject = 0.1
volumetric_fog_sky_affect = 0.1
volumetric_fog_temporal_reprojection_amount = 0.85

[sub_resource type="Resource" id="Resource_f050j"]
[sub_resource type="Resource" id="Resource_ymw1b"]
resource_local_to_scene = true
script = ExtResource("4_hlewe")
grid = true
Expand Down Expand Up @@ -899,7 +899,7 @@ environment = SubResource("Environment_obnk3")
[node name="Player" parent="." instance=ExtResource("2_7qwrr")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.13854, 0.8, -5.43073)
inventory_data = SubResource("Resource_f050j")
inventory_data = SubResource("Resource_ymw1b")
[node name="CONNECTOR_TO_LOBBY" type="Node3D" parent="."]
Expand Down
Loading

0 comments on commit 215cee5

Please sign in to comment.