industrialtest/guide.lua

109 lines
4.3 KiB
Lua

-- IndustrialTest
-- Copyright (C) 2025 mrkubax10
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local S=minetest.get_translator("industrialtest")
local pages={
introduction={
title=S("Introduction"),
icon=industrialtest.elementKeys.paper,
content=[[
<big>Introduction</big>
<left>
IndustrialTest implements finite power functionality which can be used to perform various tasks using generators and consumers. Such features are not a new thing in Luanti, as there are older mods which do that already. This mod, however, proves to be more flexible.
</left>
]]
},
electricalNetwork={
title=S("Electrical network"),
icon="industrialtest:insulated_copper_cable",
content=[[
<big>Electrical network</big>
<left>
In order to attach electricity consumers to power sources (like generators, batteries, further just called generators) electrical network is used. Consumers can get connected either directly to generators or through various cables. Each generator can output certain voltage (this is actually amperage, however since this mod doesn't simulate electricity accurately, it's called voltage), the same situation is for consumers as they can only handle up to certain voltage.
Figure 1 shows voltage levels present in this mod.
If voltage is too high for cable it will melt without dropping anything while consumer will explode also without dropping anything and possibly destroying terrain around. Power capacity is measured in EU (Energy Units) and the voltage is EU/update.
</left>
<mono>
--------------------------------------------
| Voltage level | EU/update | Cable |
--------------------------------------------
| LV | 600 | Tin |
| MV | 2400 | Copper |
| HV | 10200 | Gold |
| EV | 40800 | Iron |
| IV | 163800 | Glass Fibre |
|----------------------------|--------------
Figure 1. Voltage levels and respective cables
</mono>
]]
}
}
local function getGuideFormspec(playerName,pageName)
local formspec={
"formspec_version[4]",
"size[15,10.8]",
"label[0.1,0.2;"..S("IndustrialTest Guide").."]",
--"scrollbaroptions[]",
"scrollbar[3.6,0.4;0.5,10.3;vertical;scrollbarList;0]",
"scroll_container[0.1,0.4;4,10.3;scrollbarList;vertical]"
}
-- Contents sidebar
local PAGE_BUTTON_HEIGHT=0.7
local index=0
for name,page in pairs(pages) do
table.insert(formspec,string.format("container[0,%f]",index*PAGE_BUTTON_HEIGHT))
table.insert(formspec,string.format("item_image[0,0;%f,%f;%s]",PAGE_BUTTON_HEIGHT,PAGE_BUTTON_HEIGHT,page.icon))
table.insert(formspec,string.format("button[%f,0;%f,%f;%s;%s]",PAGE_BUTTON_HEIGHT+0.05,3.45-PAGE_BUTTON_HEIGHT,PAGE_BUTTON_HEIGHT,name,page.title))
table.insert(formspec,"container_end[]")
index=index+1
end
table.insert(formspec,"scroll_container_end[]")
if pageName and pages[pageName] then
table.insert(formspec,string.format("hypertext[4.2,0.4;10.7,10.3;content;%s]",pages[pageName].content))
end
return table.concat(formspec,"")
end
local function showGuide(playerName,page)
minetest.show_formspec(playerName,"industrialtest:guide",getGuideFormspec(playerName,page))
return true
end
local function handleGuideFields(player,formname,fields)
if formname~="industrialtest:guide" then
return
end
for name,_ in pairs(pages) do
if fields[name] then
minetest.close_formspec(player:get_player_name(),formname)
showGuide(player:get_player_name(),name)
break
end
end
end
minetest.register_on_player_receive_fields(handleGuideFields)
minetest.register_chatcommand("industrialtest_guide",{
description=S("Shows graphical guide for content and features provided by IndustrialTest"),
func=showGuide
})