Release 0.0.1.8.8.7
This commit is contained in:
1 parent
3c8a17aa78
commit
c7beab414c
16283 files changed
+768761
-2
No files matched your search
@@ -0,0 +1,46 @@
|
||||
# mkxp-z compatibility fix for scripts that pass non-boolean values to visible=
|
||||
# Place this file in ModScripts/ as: ModScripts/99998_mkxp_visible_bool_fix.rb
|
||||
|
||||
module MKXPZVisibleBoolFix
|
||||
module_function
|
||||
|
||||
def normalize_visible_value(value)
|
||||
case value
|
||||
when true, false
|
||||
value
|
||||
when nil
|
||||
false
|
||||
when Numeric
|
||||
value != 0
|
||||
when String
|
||||
v = value.strip.downcase
|
||||
return false if v.empty? || v == '0' || v == 'false' || v == 'nil' || v == 'off' || v == 'no'
|
||||
true
|
||||
else
|
||||
!!value
|
||||
end
|
||||
end
|
||||
|
||||
def patch_visible_writer(klass)
|
||||
return unless klass.instance_methods.include?(:visible=)
|
||||
return if klass.instance_methods.include?(:mkxpz_visible_without_boolfix=)
|
||||
|
||||
klass.class_eval do
|
||||
alias_method :mkxpz_visible_without_boolfix=, :visible=
|
||||
|
||||
define_method(:visible=) do |value|
|
||||
send(:mkxpz_visible_without_boolfix=, MKXPZVisibleBoolFix.normalize_visible_value(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[Sprite, Plane, Window, Viewport].each do |klass|
|
||||
begin
|
||||
MKXPZVisibleBoolFix.patch_visible_writer(klass)
|
||||
rescue StandardError => e
|
||||
p "[mkxp-z boolfix] failed to patch #{klass}: #{e.class}: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
||||
p '[mkxp-z boolfix] visible= compatibility patch loaded'
|
||||
Reference in new issue
Block a user