mirror of
https://github.com/notwa/mm
synced 2025-02-05 13:23:23 -08:00
allow a single function for simple callbacks
This commit is contained in:
parent
f6d20caa4b
commit
f2839bb69c
3 changed files with 24 additions and 41 deletions
|
@ -43,17 +43,12 @@ local function save()
|
||||||
serialize(fn, saved)
|
serialize(fn, saved)
|
||||||
end
|
end
|
||||||
|
|
||||||
dummy = Callbacks()
|
|
||||||
|
|
||||||
function Setter(t)
|
function Setter(t)
|
||||||
local cb = Callbacks()
|
return function()
|
||||||
function cb:on()
|
for func, value in pairs(t) do
|
||||||
for addr, value in pairs(t) do
|
func(value)
|
||||||
addr(value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cb.hold = cb.on
|
|
||||||
return cb
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local passives = {}
|
local passives = {}
|
||||||
|
@ -101,18 +96,7 @@ function any_item:tick_on()
|
||||||
addrs.buttons_enabled(0)
|
addrs.buttons_enabled(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
local everything = Callbacks()
|
local function soft_reset()
|
||||||
function everything:on()
|
|
||||||
dofile("oneshot.lua")
|
|
||||||
end
|
|
||||||
|
|
||||||
local escape_cutscene = Callbacks()
|
|
||||||
function escape_cutscene:on()
|
|
||||||
addrs.cutscene_status_2(3)
|
|
||||||
end
|
|
||||||
|
|
||||||
local soft_reset = Callbacks()
|
|
||||||
function soft_reset:on()
|
|
||||||
if oot then
|
if oot then
|
||||||
-- FIXME: Link voids out on title screen.
|
-- FIXME: Link voids out on title screen.
|
||||||
-- need to load title screen save?
|
-- need to load title screen save?
|
||||||
|
@ -128,8 +112,7 @@ function soft_reset:on()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_pos = Callbacks()
|
local function save_pos()
|
||||||
function save_pos:on()
|
|
||||||
local la = addrs.link_actor
|
local la = addrs.link_actor
|
||||||
saved.pos = {}
|
saved.pos = {}
|
||||||
local pos = saved.pos
|
local pos = saved.pos
|
||||||
|
@ -141,8 +124,7 @@ function save_pos:on()
|
||||||
pos.isg = la.sword_active()
|
pos.isg = la.sword_active()
|
||||||
save()
|
save()
|
||||||
end
|
end
|
||||||
local load_pos = Callbacks()
|
local function load_pos()
|
||||||
function load_pos:on()
|
|
||||||
local la = addrs.link_actor
|
local la = addrs.link_actor
|
||||||
local pos = saved.pos
|
local pos = saved.pos
|
||||||
if pos == nil then return end
|
if pos == nil then return end
|
||||||
|
@ -157,27 +139,23 @@ function load_pos:on()
|
||||||
la.sword_active(pos.isg)
|
la.sword_active(pos.isg)
|
||||||
end
|
end
|
||||||
|
|
||||||
reload_scene = Callbacks()
|
local function reload_scene()
|
||||||
function reload_scene:on()
|
|
||||||
local ev = addrs.exit_value()
|
local ev = addrs.exit_value()
|
||||||
addrs.warp_begin(0x14)
|
addrs.warp_begin(0x14)
|
||||||
addrs.warp_destination(ev)
|
addrs.warp_destination(ev)
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_scene = Callbacks()
|
local function save_scene()
|
||||||
function save_scene:on()
|
|
||||||
saved.scene = addrs.exit_value()
|
saved.scene = addrs.exit_value()
|
||||||
save()
|
save()
|
||||||
end
|
end
|
||||||
local load_scene = Callbacks()
|
local function load_scene()
|
||||||
function load_scene:on()
|
|
||||||
if saved.scene == nil then return end
|
if saved.scene == nil then return end
|
||||||
addrs.warp_begin(0x14)
|
addrs.warp_begin(0x14)
|
||||||
addrs.warp_destination(saved.scene)
|
addrs.warp_destination(saved.scene)
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_scene_pos = Callbacks()
|
local function save_scene_pos()
|
||||||
function save_scene_pos:on()
|
|
||||||
saved.scenepos = {}
|
saved.scenepos = {}
|
||||||
local sp = saved.scenepos
|
local sp = saved.scenepos
|
||||||
sp.scene = addrs.exit_value()
|
sp.scene = addrs.exit_value()
|
||||||
|
@ -189,8 +167,7 @@ function save_scene_pos:on()
|
||||||
--sp.room = la.room_number()
|
--sp.room = la.room_number()
|
||||||
save()
|
save()
|
||||||
end
|
end
|
||||||
local load_scene_pos = Callbacks()
|
local function load_scene_pos()
|
||||||
function load_scene_pos:on()
|
|
||||||
local sp = saved.scenepos
|
local sp = saved.scenepos
|
||||||
if sp == nil then return end
|
if sp == nil then return end
|
||||||
addrs.warp_begin(0x14)
|
addrs.warp_begin(0x14)
|
||||||
|
@ -207,8 +184,7 @@ function load_scene_pos:on()
|
||||||
--voidout_room_number(sp.room)
|
--voidout_room_number(sp.room)
|
||||||
end
|
end
|
||||||
|
|
||||||
local kill_fades = Callbacks()
|
local function kill_fades()
|
||||||
function kill_fades:on()
|
|
||||||
local et = addrs.entrance_table
|
local et = addrs.entrance_table
|
||||||
if et == nil then return end
|
if et == nil then return end
|
||||||
local et_size = 1244
|
local et_size = 1244
|
||||||
|
@ -275,10 +251,10 @@ local main_menu = Menu{
|
||||||
Toggle("Infinite Items", infinite_items),
|
Toggle("Infinite Items", infinite_items),
|
||||||
Toggle("Use Any Item", any_item),
|
Toggle("Use Any Item", any_item),
|
||||||
Text(""),
|
Text(""),
|
||||||
Oneshot("100% Items", everything),
|
Oneshot("100% Items", Setter{[dofile]="oneshot.lua"}),
|
||||||
LinkTo("Set Progress...", progress_menu),
|
LinkTo("Set Progress...", progress_menu),
|
||||||
Text(""),
|
Text(""),
|
||||||
Oneshot("Escape Cutscene", escape_cutscene),
|
Oneshot("Escape Cutscene", Setter{[addrs.cutscene_status_2]=3}),
|
||||||
Text(""),
|
Text(""),
|
||||||
LinkTo("Play as...", playas_menu),
|
LinkTo("Play as...", playas_menu),
|
||||||
Oneshot("Kill Link", Setter{[addrs.hearts]=0}),
|
Oneshot("Kill Link", Setter{[addrs.hearts]=0}),
|
||||||
|
|
|
@ -33,6 +33,8 @@ end
|
||||||
function Callbacks:release()
|
function Callbacks:release()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local dummy = Callbacks()
|
||||||
|
|
||||||
function MenuItem:init()
|
function MenuItem:init()
|
||||||
self.focused = false
|
self.focused = false
|
||||||
end
|
end
|
||||||
|
@ -89,7 +91,13 @@ end
|
||||||
|
|
||||||
function Active:init(text, callbacks)
|
function Active:init(text, callbacks)
|
||||||
Text.init(self, text)
|
Text.init(self, text)
|
||||||
self.callbacks = callbacks or {}
|
if type(callbacks) == 'function' then
|
||||||
|
local f = callbacks
|
||||||
|
callbacks = Callbacks()
|
||||||
|
function callbacks:on() f() end
|
||||||
|
callbacks.hold = callbacks.on
|
||||||
|
end
|
||||||
|
self.callbacks = callbacks or dummy
|
||||||
end
|
end
|
||||||
|
|
||||||
function Toggle:init(text, callbacks)
|
function Toggle:init(text, callbacks)
|
||||||
|
|
|
@ -157,8 +157,7 @@ for si=0x00,0x7F do
|
||||||
if j ~= 0 then break end
|
if j ~= 0 then break end
|
||||||
ename = "[crash?]"
|
ename = "[crash?]"
|
||||||
end
|
end
|
||||||
local callback = Callbacks()
|
local callback = function()
|
||||||
function callback:on()
|
|
||||||
addrs.warp_destination(make_exit_value(si,j,0))
|
addrs.warp_destination(make_exit_value(si,j,0))
|
||||||
addrs.warp_begin(0x14)
|
addrs.warp_begin(0x14)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue