97 lines
2.1 KiB
Ruby
97 lines
2.1 KiB
Ruby
# encoding: UTF-8
|
|||
|
|
#
|
||
|
|
# Minimal safe hair-color reapply after loading a save.
|
||
|
|
#
|
||
|
|
# Notes:
|
||
|
|
# - do not override Game_Player#refresh_chs
|
||
|
|
# - do not touch runtime visual signatures
|
||
|
|
# - do not clear caches every Scene_Map start
|
||
|
|
# - only re-run the normal game path: apply_color_palette after load
|
||
|
|
#
|
||
|
|
module HairColorLoadFix
|
||
|
|
DELAY_FRAMES = 2
|
||
|
|
|
||
|
|
module_function
|
||
|
|
|
||
|
|
def schedule(frames = DELAY_FRAMES)
|
||
|
|
@pending = true
|
||
|
|
@frames = frames.to_i
|
||
|
|
@frames = 0 if @frames < 0
|
||
|
|
rescue
|
||
|
|
@pending = true
|
||
|
|
@frames = DELAY_FRAMES
|
||
|
|
end
|
||
|
|
|
||
|
|
def pending?
|
||
|
|
!!@pending
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def ready?
|
||
|
|
return false unless $game_player
|
||
|
|
actor = ($game_player.actor rescue nil)
|
||
|
|
return false if actor.nil?
|
||
|
|
return false unless $game_player.respond_to?(:apply_color_palette)
|
||
|
|
true
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def tick
|
||
|
|
return false unless @pending
|
||
|
|
return false unless ready?
|
||
|
|
|
||
|
|
@frames ||= 0
|
||
|
|
if @frames > 0
|
||
|
|
@frames -= 1
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
begin
|
||
|
|
$game_player.apply_color_palette
|
||
|
|
@pending = false
|
||
|
|
return true
|
||
|
|
rescue
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
class Scene_Load < Scene_File
|
||
|
|
unless method_defined?(:hair_color_load_fix_safe_on_load_success)
|
||
|
|
alias hair_color_load_fix_safe_on_load_success on_load_success
|
||
|
|
end
|
||
|
|
|
||
|
|
def on_load_success(*args, &block)
|
||
|
|
result = hair_color_load_fix_safe_on_load_success(*args, &block)
|
||
|
|
HairColorLoadFix.schedule
|
||
|
|
result
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if defined?(Scene_CustomModeLoad)
|
||
|
|
class Scene_CustomModeLoad
|
||
|
|
unless method_defined?(:hair_color_load_fix_safe_custom_on_load_success)
|
||
|
|
alias hair_color_load_fix_safe_custom_on_load_success on_load_success
|
||
|
|
end
|
||
|
|
|
||
|
|
def on_load_success(*args, &block)
|
||
|
|
result = hair_color_load_fix_safe_custom_on_load_success(*args, &block)
|
||
|
|
HairColorLoadFix.schedule
|
||
|
|
result
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
class Scene_Map < Scene_Base
|
||
|
|
unless method_defined?(:hair_color_load_fix_safe_update)
|
||
|
|
alias hair_color_load_fix_safe_update update
|
||
|
|
end
|
||
|
|
|
||
|
|
def update(*args, &block)
|
||
|
|
result = hair_color_load_fix_safe_update(*args, &block)
|
||
|
|
HairColorLoadFix.tick
|
||
|
|
result
|
||
|
|
end
|
||
|
|
end
|