89 lines
2.4 KiB
GDScript3
89 lines
2.4 KiB
GDScript3
|
class_name SaveData extends CharacterStoryState
|
||
|
|
||
|
enum GameMode {FREERUN, HUB, MISSION}
|
||
|
|
||
|
@export var ctime: int
|
||
|
@export var character_story_states: Array[CharacterStoryState]
|
||
|
@export var characters_unlocked: Array[StringName]
|
||
|
@export var character_stories_completed: Array[StringName]
|
||
|
@export var maps_unlocked: Array[MapUnlockMark]
|
||
|
@export var maps_completed: Array[MapCompletionMark]
|
||
|
@export var misc: Dictionary
|
||
|
|
||
|
func get_map_unlock_mark(
|
||
|
character: StringName,
|
||
|
level: StringName,
|
||
|
mission: StringName,
|
||
|
update: bool
|
||
|
) -> MapUnlockMark:
|
||
|
for mark in maps_unlocked:
|
||
|
if (
|
||
|
mark.character == character and
|
||
|
mark.map.level == level and
|
||
|
mark.map.mission == mission
|
||
|
):
|
||
|
return mark
|
||
|
if update:
|
||
|
var mark := MapUnlockMark.new()
|
||
|
mark.character = character
|
||
|
mark.map = MapID.new()
|
||
|
mark.map.level = level
|
||
|
mark.map.mission = mission
|
||
|
maps_unlocked.push_back(mark)
|
||
|
return mark
|
||
|
else:
|
||
|
return null
|
||
|
|
||
|
func get_map_completion_mark(
|
||
|
character: StringName,
|
||
|
level: StringName,
|
||
|
mission: StringName,
|
||
|
update: bool
|
||
|
) -> MapCompletionMark:
|
||
|
for mark in maps_completed:
|
||
|
if (
|
||
|
mark.character == character and
|
||
|
mark.map.level == level and
|
||
|
mark.map.mission == mission
|
||
|
):
|
||
|
return mark
|
||
|
if update:
|
||
|
var mark := MapCompletionMark.new()
|
||
|
mark.character = character
|
||
|
mark.map = MapID.new()
|
||
|
mark.map.level = level
|
||
|
mark.map.mission = mission
|
||
|
mark.best_time = NAN
|
||
|
maps_completed.push_back(mark)
|
||
|
return mark
|
||
|
else:
|
||
|
return null
|
||
|
|
||
|
func find_character_story_state(character: StringName) -> CharacterStoryState:
|
||
|
for state in character_story_states:
|
||
|
if state.checkpoint.character == character:
|
||
|
return state
|
||
|
return null
|
||
|
|
||
|
func switch_character_story_state(character: StringName) -> void:
|
||
|
if not (checkpoint and character == checkpoint.character):
|
||
|
if checkpoint and saved_hub_world_location:
|
||
|
for state in character_story_states:
|
||
|
assert(not (state is SaveData))
|
||
|
if state.checkpoint.character == checkpoint.character:
|
||
|
state.checkpoint = checkpoint.duplicate(true)
|
||
|
state.saved_hub_world_location = (
|
||
|
saved_hub_world_location.duplicate(true)
|
||
|
)
|
||
|
if character.is_empty():
|
||
|
checkpoint = null
|
||
|
saved_hub_world_location = null
|
||
|
else:
|
||
|
for state in character_story_states:
|
||
|
assert(not (state is SaveData))
|
||
|
if state.checkpoint.character == character:
|
||
|
checkpoint = state.checkpoint.duplicate(true)
|
||
|
saved_hub_world_location = (
|
||
|
state.saved_hub_world_location.duplicate(true)
|
||
|
)
|