Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
184 lines (167 loc) · 6.02 KB
/
Copy pathmain.lua
File metadata and controls
184 lines (167 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
-- API 7 Showcase: UI/4 tabs & tables, bsx.tween & bsx.audio, recipes, API 7 domains/hooks, and passive events.
local state = {
wind_mult = 1.0,
wind_hook_on = false,
counts = {
fishing_result = 0,
loot_pickup = 0,
pet_summoned = 0,
boss_rush_event = 0,
},
}
local wind_hook = nil
local pulse_tween = nil
local panel = bsx.ui.panel('API 7 Showcase')
local status_lbl, recipe_lbl, dye_lbl, pets_lbl, events_lbl, pulse_lbl
local function clamp_text(s, limit)
local txt = tostring(s or '')
if #txt <= limit then return txt end
return string.sub(txt, 1, limit - 3) .. '...'
end
local function refresh_events_label()
if panel and events_lbl then
panel:set_text(events_lbl, string.format(
'Events: fish=%d loot=%d pet=%d boss=%d',
state.counts.fishing_result,
state.counts.loot_pickup,
state.counts.pet_summoned,
state.counts.boss_rush_event
))
end
end
local function refresh_world_snapshot()
local ok_r, recipes, r_err = pcall(game.recipes.find, '', 3)
local ok_w, wind, w_err = pcall(game.world.wind_scale)
local ok_d, dyes, d_err = pcall(game.appearance.dye_palettes, 8)
local ok_b, ban_days = pcall(game.minigames.ban_duration_days)
local ok_p, pets, p_err = pcall(game.pets.observed)
if panel and status_lbl then
local wtxt = (ok_w and wind ~= nil) and string.format('wind=%.2fx', wind) or ('wind=' .. tostring(w_err))
local btxt = ok_b and ban_days ~= nil and ('ban_days=' .. tostring(ban_days)) or 'ban_days=?'
panel:set_text(status_lbl, clamp_text(wtxt .. ' | ' .. btxt, 118))
end
if panel and recipe_lbl then
if ok_r and type(recipes) == 'table' then
local first = recipes[1] and (tostring(recipes[1].row) .. ':' .. tostring(recipes[1].name or recipes[1].display_name or '-')) or 'none'
panel:set_text(recipe_lbl, clamp_text(string.format('Recipes sampled: %d (first=%s)', #recipes, first), 118))
else
panel:set_text(recipe_lbl, clamp_text('Recipes: ' .. tostring(r_err), 118))
end
end
if panel and dye_lbl then
if ok_d and type(dyes) == 'table' then
panel:set_text(dye_lbl, string.format('Dye palettes: groups=%d textures=%d', #(dyes.color_groups or {}), #(dyes.texture_palettes or {})))
else
panel:set_text(dye_lbl, clamp_text('Dye palettes: ' .. tostring(d_err), 118))
end
end
if panel and pets_lbl then
if ok_p and type(pets) == 'table' then
panel:set_text(pets_lbl, string.format('Observed pets: %d', #pets))
else
panel:set_text(pets_lbl, clamp_text('Observed pets: ' .. tostring(p_err), 118))
end
end
end
local function sync_wind_hook()
if wind_hook then
wind_hook:remove()
wind_hook = nil
end
if state.wind_hook_on then
wind_hook = game.hooks.add('on_wind', { mult = state.wind_mult, add = 0.0, priority = 0 })
end
end
if panel then
panel:colored_text('BSX Lua API 7 & UI/4 Showcase', { r = 0.45, g = 0.85, b = 1.0, a = 1.0 })
panel:tooltip('Exercises UI/4 tables & tabs, bsx.tween, bsx.audio, recipes, wind hooks, and Wave 21 events')
panel:begin_tab_bar('api7_showcase_tabs')
panel:tab('Overview')
status_lbl = panel:text('Waiting for world_ready...')
pulse_lbl = panel:text('Tween pulse: idle')
panel:button('Tween Pulse', function()
if pulse_tween and pulse_tween.cancel then pulse_tween:cancel() end
pulse_tween = bsx.tween.to(0.0, 1.0, 0.35, {
ease = 'out_quad',
on_update = function(v)
if panel and pulse_lbl then
panel:set_text(pulse_lbl, string.format('Tween pulse: %.2f', v))
end
end,
on_done = function()
if panel and pulse_lbl then
panel:set_text(pulse_lbl, 'Tween pulse: complete')
end
end,
})
end)
panel:same_line()
panel:button('Audio Vol Check', function()
local vol = bsx.audio.master_volume()
bsx.ui.toast(string.format('Audio master volume: %.2f', vol), { title = 'API 7 Showcase', level = 'info' })
end)
panel:end_tab()
panel:tab('Recipes & Wind')
recipe_lbl = panel:text('Recipes: waiting')
dye_lbl = panel:text('Dye palettes: waiting')
panel:drag_float('Wind Multiplier', state.wind_mult, 0.05, 0.0, 5.0, function(v)
state.wind_mult = v
if state.wind_hook_on then sync_wind_hook() end
end)
panel:checkbox('Enable on_wind Hook', state.wind_hook_on, function(v)
state.wind_hook_on = (v == true)
sync_wind_hook()
end)
local sample_ok, sample_rows = pcall(game.recipes.find, '', 3)
panel:begin_table('api7_sample_recipes', 3, { 'Row', 'Name', 'Scale' })
if sample_ok and type(sample_rows) == 'table' and #sample_rows > 0 then
for _, row in ipairs(sample_rows) do
panel:table_row()
panel:table_cell(tostring(row.row or '?'))
panel:table_cell(clamp_text(row.name or row.display_name or '-', 32))
panel:table_cell(tostring(row.fixed_material_count or '-'))
end
else
panel:table_row()
panel:table_cell('1')
panel:table_cell('Recipe sample (live when loaded)')
panel:table_cell('0.50x')
end
panel:end_table()
panel:end_tab()
panel:tab('Events & Pets')
pets_lbl = panel:text('Observed pets: waiting')
events_lbl = panel:text('Events: fish=0 loot=0 pet=0 boss=0')
panel:button('Refresh Snapshot', function()
refresh_world_snapshot()
end)
panel:end_tab()
panel:end_tab_bar()
end
for name, _ in pairs(state.counts) do
bsx.on(name, function()
state.counts[name] = state.counts[name] + 1
refresh_events_label()
end)
end
bsx.on('world_ready', function()
refresh_world_snapshot()
refresh_events_label()
local vol = bsx.audio.master_volume()
local ok_w, wind = pcall(game.world.wind_scale)
local ok_r, recipes = pcall(game.recipes.find, '', 3)
bsx.log(string.format('API7_SHOWCASE_READY recipes=%s wind=%s audio_vol=%.2f',
(ok_r and type(recipes) == 'table') and tostring(#recipes) or 'nil',
ok_w and tostring(wind) or 'nil',
vol))
end)
function on_unload()
if wind_hook and wind_hook.remove then
wind_hook:remove()
wind_hook = nil
end
if pulse_tween and pulse_tween.cancel then
pulse_tween:cancel()
pulse_tween = nil
end
end