Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format Lua files #3819

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ jobs:
- name: format C++ files
run: make astyle

- name: format markdown and typescript files
- name: format Markdown and TypeScript files
run: deno fmt

- name: json formatting
- name: format Lua files
run: deno task dprint fmt

- name: format JSON
run: make style-all-json-parallel RELEASE=1

- uses: autofix-ci/action@bee19d72e71787c12ca0f29de72f2833e437e4c9
Expand Down
39 changes: 21 additions & 18 deletions data/mods/saveload_lua_test/main.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
gdebug.log_info("SLT: main")

local mod = game.mod_runtime[ game.current_mod ]
local storage = game.mod_storage[ game.current_mod ]
local mod = game.mod_runtime[game.current_mod]
local storage = game.mod_storage[game.current_mod]

--[[
If we keep all our data simple and in mod.storage,
we won't even have to register save/load hooks,
it'll be saved/loaded automatically.
]]--
]]
--
mod.storage = storage

--[[
Expand All @@ -19,33 +20,35 @@ storage.num = 12.3
-- Usertype
storage.tri = Tripoint.new(3, 4, 5)
-- String
storage.tri_as_str = tostring( Tripoint.new(3, 4, 5) )
storage.tri_as_str = tostring(Tripoint.new(3, 4, 5))

--[[
If we want to build complex state out of loaded data
we may create a hook that would read loaded data from mod_storage
and create our complex state in the mod_runtime.
]]--
]]
--
mod.on_game_load_hook = function()
gdebug.log_info("SLT: on_load")
if storage.num then
gdebug.log_info( "Data found! num = ", storage.num )
end
if storage.tri then
gdebug.log_info( "Data found! tri = ", storage.tri )
end
gdebug.log_info("SLT: on_load")

if storage.num then
gdebug.log_info("Data found! num = ", storage.num)
end
if storage.tri then
gdebug.log_info("Data found! tri = ", storage.tri)
end
end

--[[
If we have complex enough state (e.g. recursive tables, or with custom metatables)
we may create a hook that would write a simplified version into mod_storage,
so the hardcoded JSON serializer would be able to handle it.
]]--
]]
--
mod.on_game_save_hook = function()
gdebug.log_info("SLT: on_save")
gdebug.log_info("SLT: on_save")

if storage.num then
gdebug.log_info("Saving NUM value = ", storage.num)
end
if storage.num then
gdebug.log_info("Saving NUM value = ", storage.num)
end
end
10 changes: 5 additions & 5 deletions data/mods/saveload_lua_test/preload.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
gdebug.log_info("SLT: preload")

local mod = game.mod_runtime[ game.current_mod ]
local mod = game.mod_runtime[game.current_mod]

game.hooks.on_game_load[ #game.hooks.on_game_load + 1 ] = function( ... )
return mod.on_game_load_hook( ... )
game.hooks.on_game_load[#game.hooks.on_game_load + 1] = function(...)
return mod.on_game_load_hook(...)
end

game.hooks.on_game_save[ #game.hooks.on_game_save + 1 ] = function( ... )
return mod.on_game_save_hook( ... )
game.hooks.on_game_save[#game.hooks.on_game_save + 1] = function(...)
return mod.on_game_save_hook(...)
end
Loading
Loading