mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Added a simple way to replace code in events with other code
This commit is contained in:
@@ -1,4 +1,24 @@
|
|||||||
module Compiler
|
module Compiler
|
||||||
|
SCRIPT_REPLACEMENTS = [
|
||||||
|
['Kernel.', ''],
|
||||||
|
['$PokemonBag.pbQuantity', '$bag.quantity'],
|
||||||
|
['$PokemonBag.pbHasItem?', '$bag.has?'],
|
||||||
|
['$PokemonBag.pbCanStore?', '$bag.can_add?'],
|
||||||
|
['$PokemonBag.pbStoreItem', '$bag.add'],
|
||||||
|
['$PokemonBag.pbStoreAllOrNone', '$bag.add_all'],
|
||||||
|
['$PokemonBag.pbChangeItem', '$bag.replace_item'],
|
||||||
|
['$PokemonBag.pbDeleteItem', '$bag.remove'],
|
||||||
|
['$PokemonBag.pbIsRegistered?', '$bag.registered?'],
|
||||||
|
['$PokemonBag.pbRegisterItem', '$bag.register'],
|
||||||
|
['$PokemonBag.pbUnregisterItem', '$bag.unregister'],
|
||||||
|
['$PokemonBag', '$bag'],
|
||||||
|
['pbQuantity', '$bag.quantity'],
|
||||||
|
['pbHasItem?', '$bag.has?'],
|
||||||
|
['pbCanStore?', '$bag.can_add?'],
|
||||||
|
['pbStoreItem', '$bag.add'],
|
||||||
|
['pbStoreAllOrNone', '$bag.add_all']
|
||||||
|
]
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
@@ -819,22 +839,6 @@ module Compiler
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_script(script,re)
|
|
||||||
tmp = script[0].gsub(re) { yield($~) }
|
|
||||||
if script[0]!=tmp
|
|
||||||
script[0] = tmp
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
def change_scripts(script)
|
|
||||||
changed = false
|
|
||||||
changed |= change_script(script,/\$game_variables\[(\d+)\](?!\s*(?:\=|\!|<|>))/) { |m| "pbGet("+m[1]+")" }
|
|
||||||
changed |= change_script(script,/\$Trainer\.party\[\s*pbGet\((\d+)\)\s*\]/) { |m| "pbGetPokemon("+m[1]+")" }
|
|
||||||
return changed
|
|
||||||
end
|
|
||||||
|
|
||||||
def fix_event_name(event)
|
def fix_event_name(event)
|
||||||
return false if !event
|
return false if !event
|
||||||
case event.name.downcase
|
case event.name.downcase
|
||||||
@@ -850,6 +854,31 @@ module Compiler
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def replace_scripts(script)
|
||||||
|
ret = false
|
||||||
|
SCRIPT_REPLACEMENTS.each { |pair| ret = true if script.gsub!(pair[0], pair[1]) }
|
||||||
|
ret = true if script.gsub!(/\$game_variables\[(\d+)\](?!\s*(?:\=|\!|<|>))/) { |m| "pbGet(" + $~[1] + ")" }
|
||||||
|
ret = true if script.gsub!(/\$Trainer\.party\[\s*pbGet\((\d+)\)\s*\]/) { |m| "pbGetPokemon(" + $~[1] + ")" }
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_event_scripts(event)
|
||||||
|
return false if event_is_empty?(event)
|
||||||
|
ret = false
|
||||||
|
pbEachPage(event) do |page|
|
||||||
|
page.list.each do |cmd|
|
||||||
|
params = cmd.parameters
|
||||||
|
case cmd.code
|
||||||
|
when 355, 655 # Script (first line, continuation line)
|
||||||
|
ret = true if params[0].is_a?(String) && replace_scripts(params[0])
|
||||||
|
when 111 # Conditional Branch
|
||||||
|
ret = true if params[0] == 12 && replace_scripts(params[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
def fix_event_use(event,_mapID,mapData)
|
def fix_event_use(event,_mapID,mapData)
|
||||||
return nil if event_is_empty?(event)
|
return nil if event_is_empty?(event)
|
||||||
changed = false
|
changed = false
|
||||||
@@ -864,19 +893,13 @@ module Compiler
|
|||||||
while i<list.length
|
while i<list.length
|
||||||
params = list[i].parameters
|
params = list[i].parameters
|
||||||
case list[i].code
|
case list[i].code
|
||||||
when 655 # Script (continuation line)
|
# when 655 # Script (continuation line)
|
||||||
x = [params[0]]
|
|
||||||
changed |= change_scripts(x)
|
|
||||||
params[0] = x[0]
|
|
||||||
when 355 # Script (first line)
|
when 355 # Script (first line)
|
||||||
lastScript = i
|
lastScript = i
|
||||||
if !params[0].is_a?(String)
|
if !params[0].is_a?(String)
|
||||||
i += 1
|
i += 1
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
x = [params[0]]
|
|
||||||
changed |= change_scripts(x)
|
|
||||||
params[0] = x[0]
|
|
||||||
# Check if the script is an old way of healing the entire party, and if
|
# Check if the script is an old way of healing the entire party, and if
|
||||||
# so, replace it with a better version that uses event commands
|
# so, replace it with a better version that uses event commands
|
||||||
if params[0][0,1]!="f" && params[0][0,1]!="p" && params[0][0,1]!="K"
|
if params[0][0,1]!="f" && params[0][0,1]!="p" && params[0][0,1]!="K"
|
||||||
@@ -1225,10 +1248,7 @@ module Compiler
|
|||||||
end
|
end
|
||||||
when 111 # Conditional Branch
|
when 111 # Conditional Branch
|
||||||
if list[i].parameters[0]==12 # script
|
if list[i].parameters[0]==12 # script
|
||||||
x = [list[i].parameters[1]]
|
script = list[i].parameters[1]
|
||||||
changed |= change_scripts(x)
|
|
||||||
list[i].parameters[1] = x[0]
|
|
||||||
script = x[0]
|
|
||||||
if script[trainerMoneyRE] # Compares $Trainer.money with a value
|
if script[trainerMoneyRE] # Compares $Trainer.money with a value
|
||||||
# Checking money directly
|
# Checking money directly
|
||||||
operator = $1
|
operator = $1
|
||||||
@@ -1432,6 +1452,7 @@ module Compiler
|
|||||||
changed = true
|
changed = true
|
||||||
end
|
end
|
||||||
changed = true if fix_event_name(map.events[key])
|
changed = true if fix_event_name(map.events[key])
|
||||||
|
changed = true if fix_event_scripts(map.events[key])
|
||||||
newevent = fix_event_use(map.events[key],id,mapData)
|
newevent = fix_event_use(map.events[key],id,mapData)
|
||||||
if newevent
|
if newevent
|
||||||
map.events[key] = newevent
|
map.events[key] = newevent
|
||||||
|
|||||||
Reference in New Issue
Block a user