Skip to content

Commit 6005afd

Browse files
authored
Merge pull request #2 from SGG-Modding/new_default
New Default - Managed boilerplate edition
2 parents aac4e4c + b22248d commit 6005afd

6 files changed

Lines changed: 105 additions & 58 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added dedicated `ready` and `reload` files so `main.lua` can be ignored for simple mods.
13+
- Added a stub `defs.lua` as a reminder to document the plugin if relevant.
14+
15+
### Changed
16+
17+
- Default template is more up-to-date.
18+
1019
## [0.5.1] - 2024-05-15
1120

1221
### Fixed

src/src/def.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---@meta AuthorName-ModName
2+
local public = {}
3+
4+
-- document whatever you made publicly available to other plugins here
5+
-- use luaCATS annotations and give descriptions where appropriate
6+
-- e.g.
7+
-- ---@param a integer helpful description
8+
-- ---@param b string helpful description
9+
-- ---@return table c helpful description
10+
-- function public.do_stuff(a, b)
11+
12+
return public

src/src/main.lua

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,58 @@
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
38

49
---@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
614

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
1319

1420
---@module 'SGG_Modding-Hades2GameDef-Globals'
15-
local game = rom.game
21+
game = rom.game
1622

1723
---@module 'SGG_Modding-SJSON'
18-
local sjson = rom.mods['SGG_Modding-SJSON']
19-
24+
sjson = mods['SGG_Modding-SJSON']
2025
---@module 'SGG_Modding-ModUtil'
21-
local modutil = rom.mods['SGG_Modding-ModUtil']
26+
modutil = mods['SGG_Modding-ModUtil']
2227

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']
3332

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
3837

39-
local function on_ready_final()
38+
local function on_ready()
4039
-- 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
4741

48-
game.OnControlPressed({'Gift', function(...)
49-
return private.trigger_Gift(...)
50-
end})
42+
import 'ready.lua'
5143
end
5244

53-
local function on_reload_setup()
45+
local function on_reload()
5446
-- what to do when we are ready, but also again on every reload.
5547
-- only do things that are safe to run over and over.
5648

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'
7450
end
7551

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()
7754

55+
-- this runs only when modutil and the game's lua is ready
7856
modutil.on_ready_final(function()
79-
loader.load('game is ready', on_ready_final)
57+
loader.load(on_ready, on_reload)
8058
end)

src/src/ready.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---@meta _
2+
-- globals we define are private to our plugin!
3+
---@diagnostic disable: lowercase-global
4+
5+
-- here is where your mod sets up all the things it will do.
6+
-- this file will not be reloaded if it changes during gameplay
7+
-- so you will most likely want to have it reference
8+
-- values and functions later defined in `reload.lua`.
9+
10+
local file = rom.path.combine(rom.paths.Content, 'Game/Text/en/ShellText.en.sjson')
11+
12+
sjson.hook(file, function(data)
13+
return sjson_ShellText(data)
14+
end)
15+
16+
modutil.mod.Path.Wrap("SetupMap", function(base)
17+
return wrap_SetupMap(base)
18+
end)
19+
20+
game.OnControlPressed({'Gift', function()
21+
return trigger_Gift()
22+
end})

src/src/reload.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---@meta _
2+
-- globals we define are private to our plugin!
3+
---@diagnostic disable: lowercase-global
4+
5+
-- this file will be reloaded if it changes during gameplay,
6+
-- so only assign to values or define things here.
7+
8+
function sjson_ShellText(data)
9+
for _,v in ipairs(data.Texts) do
10+
if v.Id == 'MainMenuScreen_PlayGame' then
11+
v.DisplayName = 'Test ' .. _PLUGIN.guid
12+
break
13+
end
14+
end
15+
end
16+
17+
function wrap_SetupMap(base)
18+
print('Map is loading, here we might load some packages.')
19+
-- game.LoadPackages({Name = package_name_string})
20+
return base()
21+
end
22+
23+
function trigger_Gift()
24+
modutil.mod.Hades.PrintOverhead(config.message)
25+
end

src/thunderstore.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ websiteUrl = "https://github.com/AuthorName/ModName"
1111
containsNsfwContent = false
1212

1313
[package.dependencies]
14+
Hell2Modding-Hell2Modding = "1.0.26"
1415
SGG_Modding-ENVY = "1.0.0"
15-
SGG_Modding-Chalk = "1.0.0"
16+
SGG_Modding-Chalk = "2.0.2"
1617
SGG_Modding-ReLoad = "1.0.1"
1718
SGG_Modding-SJSON = "1.0.0"
1819
SGG_Modding-ModUtil = "3.1.0"

0 commit comments

Comments
 (0)