Skip to content

Commit

Permalink
Per-save options, moved mod options to submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
SylviBlossom committed Jun 26, 2023
1 parent 43c4a55 commit be61f33
Show file tree
Hide file tree
Showing 3 changed files with 392 additions and 231 deletions.
25 changes: 25 additions & 0 deletions Data/Scripts/002_Save data/002_SaveData_Value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(id, &block)
@id = id
@loaded = false
@load_in_bootup = false
@optional = false
instance_eval(&block)
raise "No save_value defined for save value #{id.inspect}" if @save_proc.nil?
##Sylvi Items
Expand Down Expand Up @@ -69,6 +70,14 @@ def load_new_game_value
self.load(@new_game_value_proc.call)
end

#Sylvi
def get_new_game_value
unless self.has_new_game_proc?
raise "Save value #{@id} has no new_game_value defined"
end
return @new_game_value_proc.call
end

# @return [Boolean] whether the value should be loaded during bootup
def load_in_bootup?
return @load_in_bootup
Expand Down Expand Up @@ -173,6 +182,16 @@ def from_vanilla(&block)
@from_vanilla_proc = block
end

#Sylvi
def optional
@optional = true
end

#Sylvi
def optional?
return @optional
end

# @!endgroup
end

Expand Down Expand Up @@ -296,6 +315,12 @@ def self.compile_save_hash

#Sylvi Items
def self.resolve_modded_data(save_data)
# Load optional values
@values.each do |value|
next if save_data.has_key?(value.id) || !value.optional?
save_data[value.id] = value.get_new_game_value
end
# Sync vanilla and modded values
@values.each do |value|
next unless value.modded?
if save_data.has_key?(value.id)
Expand Down
24 changes: 21 additions & 3 deletions Data/Scripts/002_Save data/004_Game_SaveValues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
load_in_bootup
ensure_class :PokemonSystem
save_value { $PokemonSystem }
load_value { |value| $PokemonSystem = value }
new_game_value { PokemonSystem.new }
load_value { |value|
$PokemonSystem = PokemonSystem.new if !$PokemonSystem
$PokemonSystem.load_bootup_data(value)
}
new_game_value { $PokemonSystem ? $PokemonSystem : PokemonSystem.new }
from_old_format { |old_format| old_format[3] }
end

Expand Down Expand Up @@ -135,7 +138,22 @@
end


#Sylvi Items
# Kuray Save Data
#===============================================================================

SaveData.register(:kuray_pokemon_system_file) do
optional
ensure_class :PokemonSystem
save_value { $PokemonSystem }
load_value { |value|
$PokemonSystem = PokemonSystem.new if !$PokemonSystem
$PokemonSystem.load_file_data(value)
}
new_game_value { PokemonSystem.new }
end


# Vanilla-Modded Compatibility
#===============================================================================

SaveData.register(:kuray_player) do
Expand Down
Loading

0 comments on commit be61f33

Please sign in to comment.