Button Count
-Made it so that the registerload / registersave functions are only used if registerload exists. I'll presume there is no emulator that supports one and not the other. This will allow VBA to use this script, although it'll be missing one of the better features until it supports this function. -Made the number of controllers tracked configurable. VBA was counting everything twice when this was set to 2. It will still default to 2, but it'll be easier for people to modify this for VBA now.
This commit is contained in:
parent
94960278e5
commit
72f17fb40c
|
@ -1,137 +0,0 @@
|
|||
--Written by Brandon Evans
|
||||
|
||||
--You can change the position of the text here.
|
||||
local x = 0
|
||||
local y = 8
|
||||
|
||||
local holds = 0
|
||||
local players = {}
|
||||
local presses = 0
|
||||
local states = {}
|
||||
|
||||
function table.copy(t)
|
||||
local t2 = {}
|
||||
for k, v in pairs(t) do
|
||||
t2[k] = v
|
||||
end
|
||||
return t2
|
||||
end
|
||||
|
||||
function load(slot)
|
||||
if not states[slot] then
|
||||
return
|
||||
end
|
||||
--Load the data if there is any available for this slot.
|
||||
holds = states[slot].holds
|
||||
players = table.copy(states[slot].players)
|
||||
presses = states[slot].presses
|
||||
end
|
||||
|
||||
function parse()
|
||||
--If there is an open, read-only FM2 file, parse it for the initial data.
|
||||
if not movie.active() then
|
||||
return false
|
||||
end
|
||||
local fh = io.open(movie.name())
|
||||
if not fh or movie.mode() == 'record' or movie.name():match(
|
||||
'.%.(%w+)$'
|
||||
) ~= 'fm2' then
|
||||
return false
|
||||
end
|
||||
local frame = -1
|
||||
local last = {}
|
||||
local match = {
|
||||
'right', 'left', 'down', 'up', 'start', 'select', 'B', 'A'
|
||||
}
|
||||
--Parse up until two frames before the current one.
|
||||
while frame ~= emu.framecount() - 2 do
|
||||
line = fh:read()
|
||||
if not line then
|
||||
break
|
||||
end
|
||||
--This is only a frame if it starts with a vertical bar.
|
||||
if string.sub(line, 0, 1) == '|' then
|
||||
frame = frame + 1
|
||||
players = {}
|
||||
local player = -1
|
||||
--Split up the sections by a vertical bar.
|
||||
for section in string.gmatch(line, '[^|]+') do
|
||||
player = player + 1
|
||||
--Only deal with actual players.
|
||||
if player ~= 0 then
|
||||
local button = 0
|
||||
--Run through all the buttons.
|
||||
for text in string.gmatch(section, '.') do
|
||||
button = button + 1
|
||||
--Check if this button is pressed.
|
||||
if text ~= ' ' and text ~= '.' then
|
||||
holds = holds + 1
|
||||
--If the button was not previously pressed,
|
||||
--increment.
|
||||
if table.maxn(last) < player or not last[player][
|
||||
match[button]
|
||||
] then
|
||||
presses = presses + 1
|
||||
end
|
||||
if table.maxn(players) < player then
|
||||
table.insert(players, {})
|
||||
end
|
||||
--Mark this button as pressed.
|
||||
players[player][match[button]] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--Save the players to compare with the next frame in the file.
|
||||
last = players
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function save(slot)
|
||||
while table.maxn(states) < slot do
|
||||
table.insert(states, {})
|
||||
end
|
||||
--Mark the current data as the data for this slot.
|
||||
states[slot].holds = holds
|
||||
states[slot].players = table.copy(players)
|
||||
states[slot].presses = presses
|
||||
end
|
||||
|
||||
if parse() then
|
||||
gui.text(x, y + 16, 'Movie parsed for data')
|
||||
else
|
||||
gui.text(x, y + 16, 'No movie parsed for data')
|
||||
end
|
||||
savestate.registerload(load)
|
||||
savestate.registersave(save)
|
||||
|
||||
while true do
|
||||
--If this is the first frame, reset the data.
|
||||
if emu.framecount() == 0 then
|
||||
holds = 0
|
||||
players = {}
|
||||
presses = 0
|
||||
end
|
||||
--Check players one and two.
|
||||
for player = 1, 2 do
|
||||
local buttons = joypad.getdown(player)
|
||||
--Run through all of the pressed buttons.
|
||||
for i, v in pairs(buttons) do
|
||||
holds = holds + 1
|
||||
--If in the previous frame the button was not pressed, increment.
|
||||
if table.maxn(players) >= player and not players[player][i] then
|
||||
presses = presses + 1
|
||||
end
|
||||
end
|
||||
if table.maxn(players) < player then
|
||||
table.insert(players, true)
|
||||
end
|
||||
--Mark these buttons as pressed.
|
||||
players[player] = buttons
|
||||
end
|
||||
gui.text(x, y, 'Holds: ' .. holds)
|
||||
gui.text(x, y + 8, 'Presses: ' .. presses)
|
||||
emu.frameadvance()
|
||||
end
|
|
@ -1,5 +1,7 @@
|
|||
--Written by Brandon Evans
|
||||
|
||||
--You can change the number of controllers tracked here.
|
||||
local controllers = 2
|
||||
--You can change the position of the text here.
|
||||
local x = 0
|
||||
local y = 8
|
||||
|
@ -120,8 +122,10 @@ if parse() then
|
|||
else
|
||||
gui.text(x, y + 16, 'No movie parsed for data')
|
||||
end
|
||||
savestate.registerload(load)
|
||||
savestate.registersave(save)
|
||||
if savestate.registerload then
|
||||
savestate.registerload(load)
|
||||
savestate.registersave(save)
|
||||
end
|
||||
|
||||
while true do
|
||||
--If this is the first frame, reset the data.
|
||||
|
@ -131,7 +135,7 @@ while true do
|
|||
presses = 0
|
||||
end
|
||||
--Check players one and two.
|
||||
for player = 1, 2 do
|
||||
for player = 1, controllers do
|
||||
local buttons = joypad.getdown(player)
|
||||
--Run through all of the pressed buttons.
|
||||
for i, v in pairs(buttons) do
|
||||
|
|
Loading…
Reference in New Issue