Files
chaussette.sale/game_state.gd
Thomas 9350825614 Des changements de scènes sans bugs
du moins je l'espère!
2025-04-15 11:09:07 +02:00

73 lines
2.1 KiB
GDScript

extends Node
var _game : GameControler
var _is_switiching = false
var _debug = false
var isUsingTouch = false
var hasChosenNotToMakeChoices = false
var hasChosenToMakeChoices = false
var hasCompletedBobDialogue = false
var hasMetBob = false
var hasVisitedBakery = false
var isPlayerDeaf = false
var vec_last_facing_direction = Vector2(0, 0)
var float_thomas_music_position = 0
var current_scene = "outside"
var position_outside = Vector2(-134.3333, -164.0905)
var position_bakery = Vector2(506.361, 843.8615)
func update_position(p: Vector2):
if _is_switiching:
if(_debug):
print("switching scene, not updating position")
return
match current_scene:
"outside":
position_outside = p
"bakery":
position_bakery = p
if(_debug):
print (current_scene, " position ", p)
func get_position_player():
match current_scene:
"outside":
return position_outside
"bakery":
return position_bakery
return Vector2(0, 0)
func save():
var ret = {}
var thisScript: GDScript = get_script()
for propertyInfo in thisScript.get_script_property_list():
var propertyName: String = propertyInfo.name
var propertyValue = get(propertyName)
ret[propertyName] = JSON.stringify(propertyValue)
# don't save protected fields
if propertyName.begins_with("_") :
continue
return ret
func load_save(data:Dictionary):
var thisScript: GDScript = get_script()
for propertyInfo in thisScript.get_script_property_list():
var propertyName: String = propertyInfo.name
# don't load protected fields
if propertyName.begins_with("_") :
continue
if data.get(propertyName) == null:
continue
if propertyName.begins_with("is") or propertyName.begins_with("has"):
set(propertyName, data.get(propertyName) == "true")
elif propertyName.begins_with("position_") or propertyName.begins_with("vec"):
var strplps = (data.get(propertyName) as String).replace("\"(", "").replace(")\"", "")
var parts = strplps.split(", ")
set(propertyName, Vector2(float(parts[0]), float(parts[1])))
elif propertyName.begins_with("float_"):
set(propertyName, float(data.get(propertyName)))
else:
set(propertyName, data.get(propertyName).lstrip("\"").rstrip("\""))