PokeBot/action/textbox.lua

99 lines
2.1 KiB
Lua
Raw Normal View History

2015-04-06 01:18:46 -07:00
local Textbox = {}
2014-07-12 18:47:39 -07:00
2015-04-06 01:18:46 -07:00
local Input = require "util.input"
local Memory = require "util.memory"
local Menu = require "util.menu"
2014-07-12 18:47:39 -07:00
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ *():;[]ab-?!mf/.,"
-- local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ *():;[]ポモ-?!♂♀/.,"
2014-07-12 18:47:39 -07:00
local nidoName = "A"
local nidoIdx = 1
local function getLetterAt(index)
return alphabet:sub(index, index)
2014-07-12 18:47:39 -07:00
end
local function getIndexForLetter(letter)
return alphabet:find(letter, 1, true)
end
2015-04-06 01:18:46 -07:00
function Textbox.name(letter, randomize)
local inputting = Memory.value("menu", "text_input") == 240
if inputting then
2015-04-06 01:18:46 -07:00
if Memory.value("menu", "text_length") > 0 then
Input.press("Start")
2014-07-12 18:47:39 -07:00
return true
end
local lidx
if letter then
2014-07-12 18:47:39 -07:00
lidx = getIndexForLetter(letter)
else
lidx = nidoIdx
end
2015-04-06 01:18:46 -07:00
local crow = Memory.value("menu", "input_row")
2014-07-12 18:47:39 -07:00
local drow = math.ceil(lidx / 9)
2015-04-06 01:18:46 -07:00
if Menu.balance(crow, drow, true, 6, true) then
local ccol = math.floor(Memory.value("menu", "column") / 2)
2014-07-12 18:47:39 -07:00
local dcol = math.fmod(lidx - 1, 9)
2015-04-06 01:18:46 -07:00
if Menu.sidle(ccol, dcol, 9, true) then
Input.press("A")
2014-07-12 18:47:39 -07:00
end
end
else
-- TODO cancel when menu isn't up
2015-04-06 01:18:46 -07:00
-- if Memory.value("menu", "current") == 7 then
if Memory.raw(0x10B7) == 3 then
Input.press("A", 2)
elseif randomize then
2015-04-06 01:18:46 -07:00
Input.press("A", math.random(1, 5))
2014-07-12 18:47:39 -07:00
else
2015-04-06 01:18:46 -07:00
Input.cancel()
2014-07-12 18:47:39 -07:00
end
end
end
2015-04-06 01:18:46 -07:00
function Textbox.getName()
if nidoName == "a" then
return ""
end
if nidoName == "b" then
return ""
end
if nidoName == "m" then
return ""
end
if nidoName == "f" then
return ""
end
2014-07-12 18:47:39 -07:00
return nidoName
end
2015-04-13 01:40:19 -07:00
function Textbox.getNamePlaintext()
return nidoName
end
function Textbox.setName(name)
if type(name) == "string" then
nidoName = name
nidoIdx = getIndexForLetter(name)
2015-04-13 11:21:27 -07:00
elseif name >= 0 and name < #alphabet then
nidoIdx = name + 1
nidoName = getLetterAt(name)
end
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
function Textbox.isActive()
return Memory.value("game", "textbox") == 1
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
function Textbox.handle()
if not Textbox.isActive() then
2014-07-12 18:47:39 -07:00
return true
end
2015-04-06 01:18:46 -07:00
Input.cancel()
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
return Textbox