|
1 | | ----@module 'SGG_Modding-ENVY' |
2 | | -local envy = rom.mods['SGG_Modding-ENVY'] |
| 1 | +---@meta _ |
| 2 | +-- grabbing our dependencies, |
| 3 | +-- these funky (---@) comments are just there |
| 4 | +-- to help VS Code find the definitions of things |
| 5 | + |
| 6 | +---@diagnostic disable-next-line: undefined-global |
| 7 | +local mods = rom.mods |
3 | 8 |
|
4 | 9 | ---@module 'SGG_Modding-ENVY-auto' |
5 | | -envy.auto(); _ENV = private |
| 10 | +mods['SGG_Modding-ENVY'].auto() |
| 11 | +-- ^ this gives us `public` and `import`, among others |
| 12 | +-- and makes all globals we define private to this plugin. |
| 13 | +---@diagnostic disable: lowercase-global |
6 | 14 |
|
7 | | ----@module 'SGG_Modding-ReLoad' |
8 | | -local reload = rom.mods['SGG_Modding-ReLoad'] |
9 | | -local loader = reload.auto_multiple() |
10 | | - |
11 | | ----@module 'SGG_Modding-Chalk' |
12 | | -local chalk = rom.mods["SGG_Modding-Chalk"] |
| 15 | +---@diagnostic disable-next-line: undefined-global |
| 16 | +rom = rom |
| 17 | +---@diagnostic disable-next-line: undefined-global |
| 18 | +_PLUGIN = PLUGIN |
13 | 19 |
|
14 | 20 | ---@module 'SGG_Modding-Hades2GameDef-Globals' |
15 | | -local game = rom.game |
| 21 | +game = rom.game |
16 | 22 |
|
17 | 23 | ---@module 'SGG_Modding-SJSON' |
18 | | -local sjson = rom.mods['SGG_Modding-SJSON'] |
19 | | - |
| 24 | +sjson = mods['SGG_Modding-SJSON'] |
20 | 25 | ---@module 'SGG_Modding-ModUtil' |
21 | | -local modutil = rom.mods['SGG_Modding-ModUtil'] |
| 26 | +modutil = mods['SGG_Modding-ModUtil'] |
22 | 27 |
|
23 | | ----@module 'config' |
24 | | -local config = chalk.auto_lua_toml() |
25 | | -public.config = config |
26 | | - |
27 | | -local function on_ready_setup() |
28 | | - -- what to do when we are ready, but not re-do on reload. |
29 | | - |
30 | | - if not config.enabled then return end |
31 | | - |
32 | | - local file = rom.path.combine(rom.paths.Content, 'Game/Text/en/ShellText.en.sjson') |
| 28 | +---@module 'SGG_Modding-Chalk' |
| 29 | +chalk = mods["SGG_Modding-Chalk"] |
| 30 | +---@module 'SGG_Modding-ReLoad' |
| 31 | +reload = mods['SGG_Modding-ReLoad'] |
33 | 32 |
|
34 | | - sjson.hook(file, function(...) |
35 | | - return private.sjson_ShellText(...) |
36 | | - end) |
37 | | -end |
| 33 | +---@module 'config' |
| 34 | +config = chalk.auto 'config.lua' |
| 35 | +-- ^ this updates our `.cfg` file in the config folder! |
| 36 | +public.config = config -- so other mods can access our config |
38 | 37 |
|
39 | | -local function on_ready_final() |
| 38 | +local function on_ready() |
40 | 39 | -- what to do when we are ready, but not re-do on reload. |
41 | | - |
42 | | - if not config.enabled then return end |
43 | | - |
44 | | - modutil.mod.Path.Wrap("SetupMap", function(base, ...) |
45 | | - return private.wrap_SetupMap(base, ...) |
46 | | - end) |
| 40 | + if config.enabled == false then return end |
47 | 41 |
|
48 | | - game.OnControlPressed({'Gift', function(...) |
49 | | - return private.trigger_Gift(...) |
50 | | - end}) |
| 42 | + import 'ready.lua' |
51 | 43 | end |
52 | 44 |
|
53 | | -local function on_reload_setup() |
| 45 | +local function on_reload() |
54 | 46 | -- what to do when we are ready, but also again on every reload. |
55 | 47 | -- only do things that are safe to run over and over. |
56 | 48 |
|
57 | | - function private.sjson_ShellText(data) |
58 | | - for _,v in ipairs(data.Texts) do |
59 | | - if v.Id == 'MainMenuScreen_PlayGame' then |
60 | | - v.DisplayName = 'Test ' .. _PLUGIN.guid |
61 | | - break |
62 | | - end |
63 | | - end |
64 | | - end |
65 | | - |
66 | | - function private.wrap_SetupMap(base) |
67 | | - print('Map is loading, here we might load some packages.') |
68 | | - return base() |
69 | | - end |
70 | | - |
71 | | - function private.trigger_Gift() |
72 | | - modutil.mod.Hades.PrintOverhead(config.message) |
73 | | - end |
| 49 | + import 'reload.lua' |
74 | 50 | end |
75 | 51 |
|
76 | | -loader.load('plugin is ready', on_ready_setup, on_reload_setup) |
| 52 | +-- this allows us to limit certain functions to not be reloaded. |
| 53 | +local loader = reload.auto_single() |
77 | 54 |
|
| 55 | +-- this runs only when modutil and the game's lua is ready |
78 | 56 | modutil.on_ready_final(function() |
79 | | - loader.load('game is ready', on_ready_final) |
| 57 | + loader.load(on_ready, on_reload) |
80 | 58 | end) |
0 commit comments