Skip to content

Commit 4b36304

Browse files
committed
feat: add settings.lua for configuring Balatro
1 parent f9c6f04 commit 4b36304

File tree

2 files changed

+184
-16
lines changed

2 files changed

+184
-16
lines changed

balatrobot.lua

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
---Global configuration for the BalatroBot mod
2-
---@type BalatrobotConfig
3-
BALATRO_BOT_CONFIG = {
4-
port = "12346",
5-
dt = 4.0 / 60.0, -- value >= 4.0 make mod instable
6-
max_fps = 60,
7-
vsync_enabled = false,
8-
9-
-- -- Default values for the original game
10-
-- port = "12346",
11-
-- dt = 1.0 / 60.0,
12-
-- vsync_enabled = true,
13-
-- max_fps = nil,
14-
}
15-
161
-- Load minimal required files
172
assert(SMODS.load_file("src/lua/utils.lua"))()
183
assert(SMODS.load_file("src/lua/api.lua"))()
194
assert(SMODS.load_file("src/lua/log.lua"))()
5+
assert(SMODS.load_file("src/lua/settings.lua"))()
206

217
-- Initialize API
228
API.init()
239

2410
-- Initialize Logger
2511
LOG.init()
2612

27-
G.SETTINGS.skip_splash = "Yes"
13+
-- Apply all configuration and Love2D patches
14+
SETTINGS.setup()
2815

2916
sendInfoMessage("BalatroBot loaded - version " .. SMODS.current_mod.version, "BALATROBOT")

src/lua/settings.lua

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
-- Environment Variables
2+
local headless = os.getenv("BALATROBOT_HEADLESS") == "1"
3+
local fast = os.getenv("BALATROBOT_FAST") == "1"
4+
local port = os.getenv("BALATROBOT_PORT")
5+
6+
SETTINGS = {}
7+
8+
-- BalatroBot Configuration
9+
local config = {
10+
dt = fast and (4.0 / 60.0) or (1.0 / 60.0),
11+
headless = headless,
12+
fast = fast,
13+
}
14+
15+
-- Apply Love2D patches for performance
16+
local function apply_love_patches()
17+
local original_update = love.update
18+
---@diagnostic disable-next-line: duplicate-set-field
19+
love.update = function(_)
20+
original_update(config.dt)
21+
end
22+
end
23+
24+
-- Configure Balatro G globals for speed
25+
local function configure_balatro_speed()
26+
-- Skip intro and splash screens
27+
G.SETTINGS.skip_splash = "Yes"
28+
29+
if config.fast then
30+
-- Disable VSync completely
31+
love.window.setVSync(0)
32+
33+
-- Fast mode settings
34+
G.FPS_CAP = nil -- Unlimited FPS
35+
G.SETTINGS.GAMESPEED = 10 -- 10x game speed
36+
G.ANIMATION_FPS = 60 -- 6x faster animations
37+
38+
-- Disable visual effects
39+
G.SETTINGS.reduced_motion = true
40+
G.SETTINGS.screenshake = false
41+
G.VIBRATION = 0
42+
G.SETTINGS.GRAPHICS.shadows = "Off"
43+
G.SETTINGS.GRAPHICS.bloom = 0
44+
G.SETTINGS.GRAPHICS.crt = 0
45+
G.SETTINGS.GRAPHICS.texture_scaling = 1 -- Fastest (nearest neighbor)
46+
G.SETTINGS.rumble = false
47+
G.F_RUMBLE = nil
48+
49+
-- Disable audio
50+
G.SETTINGS.SOUND.volume = 0
51+
G.SETTINGS.SOUND.music_volume = 0
52+
G.SETTINGS.SOUND.game_sounds_volume = 0
53+
G.F_MUTE = true
54+
55+
-- Performance optimizations
56+
G.F_ENABLE_PERF_OVERLAY = false
57+
G.SETTINGS.WINDOW.vsync = 0
58+
G.F_SOUND_THREAD = false
59+
G.F_VERBOSE = false
60+
61+
sendInfoMessage("BalatroBot: Running in fast mode")
62+
else
63+
-- Normal mode settings (defaults)
64+
-- Enable VSync
65+
love.window.setVSync(1)
66+
67+
-- Performance settings
68+
G.FPS_CAP = 60
69+
G.SETTINGS.GAMESPEED = 1
70+
G.ANIMATION_FPS = 10
71+
G.VIBRATION = 0
72+
73+
-- Feature flags - restore defaults from globals.lua
74+
G.F_ENABLE_PERF_OVERLAY = false
75+
G.F_MUTE = false
76+
G.F_SOUND_THREAD = true
77+
G.F_VERBOSE = true
78+
G.F_RUMBLE = nil
79+
80+
-- Audio settings - restore normal levels
81+
G.SETTINGS.SOUND = G.SETTINGS.SOUND or {}
82+
G.SETTINGS.SOUND.volume = 50
83+
G.SETTINGS.SOUND.music_volume = 100
84+
G.SETTINGS.SOUND.game_sounds_volume = 100
85+
86+
-- Graphics settings - restore normal quality
87+
G.SETTINGS.GRAPHICS = G.SETTINGS.GRAPHICS or {}
88+
G.SETTINGS.GRAPHICS.shadows = "On"
89+
G.SETTINGS.GRAPHICS.bloom = 1
90+
G.SETTINGS.GRAPHICS.crt = 70
91+
G.SETTINGS.GRAPHICS.texture_scaling = 2
92+
93+
-- Window settings - restore normal display
94+
G.SETTINGS.WINDOW = G.SETTINGS.WINDOW or {}
95+
G.SETTINGS.WINDOW.vsync = 1
96+
97+
-- Visual effects - restore normal motion
98+
G.SETTINGS.reduced_motion = false
99+
G.SETTINGS.screenshake = true
100+
G.SETTINGS.rumble = G.F_RUMBLE
101+
102+
-- Skip intro but allow normal game flow
103+
G.SETTINGS.skip_splash = "Yes"
104+
105+
sendInfoMessage("BalatroBot: Running in normal mode")
106+
end
107+
end
108+
109+
-- Configure headless mode optimizations
110+
local function configure_headless()
111+
if not config.headless then
112+
return
113+
end
114+
115+
-- Hide the window instead of closing it
116+
if love.window and love.window.isOpen() then
117+
-- Try to minimize the window
118+
if love.window.minimize then
119+
love.window.minimize()
120+
sendInfoMessage("BalatroBot: Minimized SMODS loading window")
121+
end
122+
-- Set window to smallest possible size and move it off-screen
123+
love.window.setMode(1, 1)
124+
love.window.setPosition(-1000, -1000)
125+
sendInfoMessage("BalatroBot: Hidden SMODS loading window")
126+
end
127+
128+
-- Disable all rendering operations
129+
---@diagnostic disable-next-line: duplicate-set-field
130+
love.graphics.isActive = function()
131+
return false
132+
end
133+
134+
-- Disable drawing operations
135+
---@diagnostic disable-next-line: duplicate-set-field
136+
love.draw = function()
137+
-- Do nothing in headless mode
138+
end
139+
140+
-- Disable graphics present/swap buffers
141+
---@diagnostic disable-next-line: duplicate-set-field
142+
love.graphics.present = function()
143+
-- Do nothing in headless mode
144+
end
145+
146+
-- Disable window creation/updates for future calls
147+
if love.window then
148+
---@diagnostic disable-next-line: duplicate-set-field
149+
love.window.setMode = function()
150+
-- Return false to indicate window creation failed (headless)
151+
return false
152+
end
153+
154+
---@diagnostic disable-next-line: duplicate-set-field
155+
love.window.isOpen = function()
156+
return false
157+
end
158+
159+
---@diagnostic disable-next-line: duplicate-set-field
160+
love.graphics.isCreated = function()
161+
return false
162+
end
163+
end
164+
165+
-- Log headless mode activation
166+
sendInfoMessage("BalatroBot: Headless mode enabled - graphics rendering disabled")
167+
end
168+
169+
-- Main setup function
170+
SETTINGS.setup = function()
171+
G.BALATROBOT_PORT = port or "12346"
172+
173+
-- Apply Love2D performance patches
174+
apply_love_patches()
175+
176+
-- Configure Balatro speed settings
177+
configure_balatro_speed()
178+
179+
-- Apply headless optimizations if needed
180+
configure_headless()
181+
end

0 commit comments

Comments
 (0)