Add helper for mineunit CI

This commit is contained in:
Y. Wang 2023-02-11 15:04:00 +01:00
parent b3da5480f7
commit dc80f5f7dc
3 changed files with 62 additions and 13 deletions

View File

@ -6,14 +6,30 @@ Wagon mods can add a description to the `_doc_wagon_longdesc` field of
the wagon prototype; adding `advtrains_doc_integration` as an optional
dependency is _not_ needed.
For (among other things) CI, the following functions are available in
If you use [Mineunit][mineunit], you can copy (or add a symlink to)
this directory into the fixtures directory of your mod and then using
(for exmaple) the code below to generate wagon datasheets.
```
require "mineunit"
mineunit "core"
fixture "advtrains_doc_integration/ci/init"
sourcefile "init"
```
[mineunit]: https://github.com/S-S-X/mineunit
If you do not use Mineunit, the following functions are available in
the `advtrains_doc_integration` table:
* `write_wagon_info_as_latex`, which exports the datasheet of a single
type of wagon as LaTeX, and
* `write_all_wagons_as_latex`, which exports all wagon datasheets as
LaTeX.
The datasheets are exported to the world directory.
It is also possible to export wagon datasheets using the `atdoc_write`
command.
command in Minetest.
The datasheets are exported to the world directory (or, for Mineunit,
the fixtures directory). Note that the result of generating datasheets
from Minetest and from CI may differ for various reasons.

35
ci/init.lua Normal file
View File

@ -0,0 +1,35 @@
-- Mineunit CI
require "mineunit"
mineunit "core"
if not minetest.get_translated_string then
local ESCAPE_CHAR = string.char(0x1b)
function _G.minetest.get_translated_string(_, s)
return s:gsub(ESCAPE_CHAR .. "%(T@[^)]+%)", ""):gsub(ESCAPE_CHAR .. "[TFE]", "")
end
end
if not minetest.safe_file_write then
function _G.minetest.safe_file_write(fn, c)
local f, e = io.open(fn, "wb")
if not f then return error(e) end
f:write(c)
f:close()
end
end
_G.advtrains = {
wagon_prototypes = {},
register_wagon = function(name, prototype, desc, invimg)
advtrains.wagon_prototypes[name] = prototype
minetest.register_craftitem(":"..name, {
description = desc,
inventory_image = invimg,
wield_image = invimg,
stack_max = 1,
})
advtrains_doc_integration.write_wagon_info_as_latex(name)
end
}
fixture("advtrains_doc_integration/init")

View File

@ -198,11 +198,6 @@ local function adjust_wagon_prototype(prototype)
p.max_passengers = pax
p.max_drivers = driver
p.max_seats = pax+driver
if p.set_livery then
if not (multi_component_liveries and p.set_livery == multi_component_liveries.set_livery and p.livery_definition) then
p.livery_definition = nil
end
end
return p
end
@ -308,12 +303,11 @@ if doc then
end
local _register_wagon = advtrains.register_wagon
function advtrains.register_wagon(...)
_register_wagon(...)
local name = ...
function advtrains.register_wagon(name, ...)
if not string.find(name, ":") then
name = "advtrains:" .. name
end
_register_wagon(name, ...)
if doc then
doc_register_wagon(name)
end
@ -389,7 +383,11 @@ function advtrains_doc_integration.write_wagon_info_as_latex(itemname)
for _, i in ipairs(prototype.drops or {}) do
local item = ItemStack(i)
if not item:is_empty() then
table.insert(st, string.format([[& %s: %d\\]], SL(item:get_short_description()), item:get_count()))
local desc = string.format([[\texttt{%s}]], SL(item:get_name()))
if item:is_known() then
desc = SL(item:get_short_description())
end
table.insert(st, string.format([[& %s: %d\\]], desc, item:get_count()))
count = count + 1
end
end