Skip to content

Commit e3dcbd5

Browse files
committed
feat: remove botlogger and simplify lua code
1 parent 11a7971 commit e3dcbd5

File tree

5 files changed

+902
-1172
lines changed

5 files changed

+902
-1172
lines changed

balatrobot.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@ assert(SMODS.load_file("src/lua/hook.lua"))()
2929
assert(SMODS.load_file("src/lua/utils.lua"))()
3030
assert(SMODS.load_file("src/lua/bot.lua"))()
3131
assert(SMODS.load_file("src/lua/middleware.lua"))()
32-
assert(SMODS.load_file("src/lua/botlogger.lua"))()
3332
assert(SMODS.load_file("src/lua/api.lua"))()
3433

3534
-- Init middleware
3635
Middleware.hookbalatro()
3736
sendDebugMessage("Middleware loaded", "BALATROBOT")
3837

39-
-- Init logger
40-
Botlogger.path = "balatrobot.log"
41-
Botlogger.init()
42-
sendDebugMessage("Logger loaded", "BALATROBOT")
43-
44-
-- Init API
38+
-- Init API (includes queue initialization)
4539
BalatrobotAPI.init()
4640
sendDebugMessage("API loaded", "BALATROBOT")
4741

src/lua/api.lua

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ BalatrobotAPI.socket = nil
99
BalatrobotAPI.waitingFor = nil
1010
BalatrobotAPI.waitingForAction = true
1111

12+
-- Action queues for Python bot commands
13+
BalatrobotAPI.q_skip_or_select_blind = nil
14+
BalatrobotAPI.q_select_cards_from_hand = nil
15+
BalatrobotAPI.q_select_shop_action = nil
16+
BalatrobotAPI.q_select_booster_action = nil
17+
BalatrobotAPI.q_sell_jokers = nil
18+
BalatrobotAPI.q_rearrange_jokers = nil
19+
BalatrobotAPI.q_use_or_sell_consumables = nil
20+
BalatrobotAPI.q_rearrange_consumables = nil
21+
BalatrobotAPI.q_rearrange_hand = nil
22+
BalatrobotAPI.q_start_run = nil
23+
1224
function BalatrobotAPI.notifyapiclient()
13-
-- TODO Generate gamestate json object
25+
-- Generate gamestate json object
1426
local _gamestate = Utils.getGamestate()
1527
_gamestate.waitingFor = BalatrobotAPI.waitingFor
1628
sendDebugMessage("WaitingFor " .. tostring(BalatrobotAPI.waitingFor))
@@ -35,7 +47,7 @@ end
3547

3648
function BalatrobotAPI.queueaction(action)
3749
local _params = Bot.ACTIONPARAMS[action[1]]
38-
List.pushleft(Botlogger["q_" .. _params.func], { 0, action })
50+
List.pushleft(BalatrobotAPI["q_" .. _params.func], { 0, action })
3951
end
4052

4153
function BalatrobotAPI.update(dt)
@@ -76,6 +88,18 @@ function BalatrobotAPI.update(dt)
7688
end
7789

7890
function BalatrobotAPI.init()
91+
-- Initialize action queues for Python bot commands
92+
BalatrobotAPI.q_skip_or_select_blind = List.new()
93+
BalatrobotAPI.q_select_cards_from_hand = List.new()
94+
BalatrobotAPI.q_select_shop_action = List.new()
95+
BalatrobotAPI.q_select_booster_action = List.new()
96+
BalatrobotAPI.q_sell_jokers = List.new()
97+
BalatrobotAPI.q_rearrange_jokers = List.new()
98+
BalatrobotAPI.q_use_or_sell_consumables = List.new()
99+
BalatrobotAPI.q_rearrange_consumables = List.new()
100+
BalatrobotAPI.q_rearrange_hand = List.new()
101+
BalatrobotAPI.q_start_run = List.new()
102+
79103
love.update = Hook.addcallback(love.update, BalatrobotAPI.update)
80104

81105
-- Tell the game engine that every frame is 8/60 seconds long
@@ -128,48 +152,47 @@ function BalatrobotAPI.init()
128152
end
129153
end
130154

131-
if Bot.SETTINGS.api == true then
132-
Middleware.c_play_hand = Hook.addbreakpoint(Middleware.c_play_hand, function()
133-
BalatrobotAPI.waitingFor = "select_cards_from_hand"
134-
BalatrobotAPI.waitingForAction = true
135-
end)
136-
Middleware.c_select_blind = Hook.addbreakpoint(Middleware.c_select_blind, function()
137-
BalatrobotAPI.waitingFor = "skip_or_select_blind"
138-
BalatrobotAPI.waitingForAction = true
139-
end)
140-
Middleware.c_choose_booster_cards = Hook.addbreakpoint(Middleware.c_choose_booster_cards, function()
141-
BalatrobotAPI.waitingFor = "select_booster_action"
142-
BalatrobotAPI.waitingForAction = true
143-
end)
144-
Middleware.c_shop = Hook.addbreakpoint(Middleware.c_shop, function()
145-
BalatrobotAPI.waitingFor = "select_shop_action"
146-
BalatrobotAPI.waitingForAction = true
147-
end)
148-
Middleware.c_rearrange_hand = Hook.addbreakpoint(Middleware.c_rearrange_hand, function()
149-
BalatrobotAPI.waitingFor = "rearrange_hand"
150-
BalatrobotAPI.waitingForAction = true
151-
end)
152-
Middleware.c_rearrange_consumables = Hook.addbreakpoint(Middleware.c_rearrange_consumables, function()
153-
BalatrobotAPI.waitingFor = "rearrange_consumables"
154-
BalatrobotAPI.waitingForAction = true
155-
end)
156-
Middleware.c_use_or_sell_consumables = Hook.addbreakpoint(Middleware.c_use_or_sell_consumables, function()
157-
BalatrobotAPI.waitingFor = "use_or_sell_consumables"
158-
BalatrobotAPI.waitingForAction = true
159-
end)
160-
Middleware.c_rearrange_jokers = Hook.addbreakpoint(Middleware.c_rearrange_jokers, function()
161-
BalatrobotAPI.waitingFor = "rearrange_jokers"
162-
BalatrobotAPI.waitingForAction = true
163-
end)
164-
Middleware.c_sell_jokers = Hook.addbreakpoint(Middleware.c_sell_jokers, function()
165-
BalatrobotAPI.waitingFor = "sell_jokers"
166-
BalatrobotAPI.waitingForAction = true
167-
end)
168-
Middleware.c_start_run = Hook.addbreakpoint(Middleware.c_start_run, function()
169-
BalatrobotAPI.waitingFor = "start_run"
170-
BalatrobotAPI.waitingForAction = true
171-
end)
172-
end
155+
-- Set up waiting states for Python bot
156+
Middleware.c_play_hand = Hook.addbreakpoint(Middleware.c_play_hand, function()
157+
BalatrobotAPI.waitingFor = "select_cards_from_hand"
158+
BalatrobotAPI.waitingForAction = true
159+
end)
160+
Middleware.c_select_blind = Hook.addbreakpoint(Middleware.c_select_blind, function()
161+
BalatrobotAPI.waitingFor = "skip_or_select_blind"
162+
BalatrobotAPI.waitingForAction = true
163+
end)
164+
Middleware.c_choose_booster_cards = Hook.addbreakpoint(Middleware.c_choose_booster_cards, function()
165+
BalatrobotAPI.waitingFor = "select_booster_action"
166+
BalatrobotAPI.waitingForAction = true
167+
end)
168+
Middleware.c_shop = Hook.addbreakpoint(Middleware.c_shop, function()
169+
BalatrobotAPI.waitingFor = "select_shop_action"
170+
BalatrobotAPI.waitingForAction = true
171+
end)
172+
Middleware.c_rearrange_hand = Hook.addbreakpoint(Middleware.c_rearrange_hand, function()
173+
BalatrobotAPI.waitingFor = "rearrange_hand"
174+
BalatrobotAPI.waitingForAction = true
175+
end)
176+
Middleware.c_rearrange_consumables = Hook.addbreakpoint(Middleware.c_rearrange_consumables, function()
177+
BalatrobotAPI.waitingFor = "rearrange_consumables"
178+
BalatrobotAPI.waitingForAction = true
179+
end)
180+
Middleware.c_use_or_sell_consumables = Hook.addbreakpoint(Middleware.c_use_or_sell_consumables, function()
181+
BalatrobotAPI.waitingFor = "use_or_sell_consumables"
182+
BalatrobotAPI.waitingForAction = true
183+
end)
184+
Middleware.c_rearrange_jokers = Hook.addbreakpoint(Middleware.c_rearrange_jokers, function()
185+
BalatrobotAPI.waitingFor = "rearrange_jokers"
186+
BalatrobotAPI.waitingForAction = true
187+
end)
188+
Middleware.c_sell_jokers = Hook.addbreakpoint(Middleware.c_sell_jokers, function()
189+
BalatrobotAPI.waitingFor = "sell_jokers"
190+
BalatrobotAPI.waitingForAction = true
191+
end)
192+
Middleware.c_start_run = Hook.addbreakpoint(Middleware.c_start_run, function()
193+
BalatrobotAPI.waitingFor = "start_run"
194+
BalatrobotAPI.waitingForAction = true
195+
end)
173196
end
174197

175198
return BalatrobotAPI

0 commit comments

Comments
 (0)