WorkStation: create WorkStation class, register test node & crafts, add work station UI
This commit is contained in:
4
mods/CORE/WorkStation/init.lua
Normal file
4
mods/CORE/WorkStation/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__work_station')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('WorkStation')
|
||||||
2
mods/CORE/WorkStation/mod.conf
Normal file
2
mods/CORE/WorkStation/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__work_station
|
||||||
|
depends = smc__core__craft_system, smc__core__node, smc__ui__work_station
|
||||||
112
mods/CORE/WorkStation/src/WorkStation.lua
Normal file
112
mods/CORE/WorkStation/src/WorkStation.lua
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
|
---@type CraftSystem.ImmersiveCraftHandler
|
||||||
|
local ImmersiveCraftHandler = Mod.getInfo('smc__core__craft_system').require('CraftSystem.ImmersiveCraftHandler')
|
||||||
|
|
||||||
|
---@type WorkStationUI
|
||||||
|
local WorkStationUI = Mod.getInfo('smc__ui__work_station').require('WorkStationUI')
|
||||||
|
|
||||||
|
---@type Node
|
||||||
|
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||||
|
|
||||||
|
local WorkStationNode = Node:getExtended({
|
||||||
|
settings = {
|
||||||
|
name = 'work_station',
|
||||||
|
drawtype = 'normal',
|
||||||
|
paramtype = 'light',
|
||||||
|
groups = {work_station = 1}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
---@class WorkStation
|
||||||
|
---@field name string
|
||||||
|
---@field group CraftSystem.CraftGroup
|
||||||
|
---@field nodeDef Node.NodeDefinition
|
||||||
|
local WorkStation = {}
|
||||||
|
|
||||||
|
---Definition table for the `CraftSystem.WorkStation`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class WorkStationDef
|
||||||
|
---@field group CraftSystem.CraftGroup
|
||||||
|
---@field nodeDef Node.NodeDefinition
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def WorkStationDef
|
||||||
|
function WorkStation:new(name, def)
|
||||||
|
local nodeDef = def.nodeDef
|
||||||
|
if nodeDef.callbacks == nil then
|
||||||
|
nodeDef.callbacks = {}
|
||||||
|
end
|
||||||
|
local settings = nodeDef.settings
|
||||||
|
local callbacks = nodeDef.callbacks
|
||||||
|
|
||||||
|
callbacks.on_construct = function(pos)
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
|
--meta:set_string('work_station_name', name)
|
||||||
|
--meta:set_string('craft_group', def.group)
|
||||||
|
end
|
||||||
|
|
||||||
|
callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
Logger.warningLog('Punch')
|
||||||
|
local crafts = ImmersiveCraftHandler:getCraftsByTriggerItem(itemstack:get_name())
|
||||||
|
|
||||||
|
if crafts == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self:showSelectionCraftForm(clicker, crafts)
|
||||||
|
end
|
||||||
|
|
||||||
|
local instance = getInstance(self, {
|
||||||
|
name = name,
|
||||||
|
group = def.group,
|
||||||
|
nodeDef = nodeDef
|
||||||
|
})
|
||||||
|
print('NODEDEF: ',dump(nodeDef.callbacks))
|
||||||
|
|
||||||
|
WorkStationNode:new(nodeDef)
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param player Player
|
||||||
|
---@param crafts CraftSystem.ImmersiveCraft[]
|
||||||
|
function WorkStation:showSelectionCraftForm(player, crafts)
|
||||||
|
local outputs = {}
|
||||||
|
|
||||||
|
for i, craft in ipairs(crafts) do
|
||||||
|
outputs[i] = craft.output
|
||||||
|
end
|
||||||
|
|
||||||
|
core.show_formspec(player:get_player_name(), 'work_station:selection_craft', WorkStationUI:selectionCraftForm(outputs))
|
||||||
|
end
|
||||||
|
|
||||||
|
WorkStation:new('test_station', {
|
||||||
|
group = 'test',
|
||||||
|
nodeDef = {
|
||||||
|
settings = {
|
||||||
|
name = 'test_station',
|
||||||
|
tiles = {'test_station.png'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ImmersiveCraftHandler:addCraft('bricks', {
|
||||||
|
triggerItem = 'rocks:sylite',
|
||||||
|
output = 'rocks:sylite_bricks',
|
||||||
|
startStageName = 'ab',
|
||||||
|
group = 'test',
|
||||||
|
stages = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
ImmersiveCraftHandler:addCraft('block', {
|
||||||
|
triggerItem = 'rocks:sylite',
|
||||||
|
output = 'rocks:sylite_block',
|
||||||
|
startStageName = 'ab',
|
||||||
|
group = 'test',
|
||||||
|
stages = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
return WorkStation
|
||||||
BIN
mods/CORE/WorkStation/textures/test_station.png
Normal file
BIN
mods/CORE/WorkStation/textures/test_station.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
4
mods/UI/WorkStationUI/init.lua
Normal file
4
mods/UI/WorkStationUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__ui__work_station')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('WorkStationUI')
|
||||||
2
mods/UI/WorkStationUI/mod.conf
Normal file
2
mods/UI/WorkStationUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__ui__work_station
|
||||||
|
depends = smc__core__formspec
|
||||||
40
mods/UI/WorkStationUI/src/WorkStationUI.lua
Normal file
40
mods/UI/WorkStationUI/src/WorkStationUI.lua
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type Formspec
|
||||||
|
local Formspec = require('Formspec')
|
||||||
|
|
||||||
|
---@class WorkStationUI
|
||||||
|
local WorkStationUI = {}
|
||||||
|
|
||||||
|
---@param items string[]
|
||||||
|
---@return string
|
||||||
|
function WorkStationUI:selectionCraftForm(items)
|
||||||
|
local listForm = Formspec:new({
|
||||||
|
size = {x=10, y=8},
|
||||||
|
})
|
||||||
|
|
||||||
|
local listFormItems = Formspec:new()
|
||||||
|
table.sort(items)
|
||||||
|
local w, h = 0, 0
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
for _, name in ipairs(items) do
|
||||||
|
listFormItems:itemImageButton(w, h, 2, 2, name, name..'::item_button')
|
||||||
|
|
||||||
|
w = w + 2
|
||||||
|
|
||||||
|
if w > 9 then
|
||||||
|
w = 0
|
||||||
|
h = h + 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
listForm:
|
||||||
|
scrollContainer(listFormItems, 0.5, 0.5, 8, 6, 'work_station:list_items', 'vertical'):
|
||||||
|
scrollbar(8, 0.5, 0.25, 7, 'vertical', 'work_station:list_items')
|
||||||
|
|
||||||
|
return listForm:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
return WorkStationUI
|
||||||
Reference in New Issue
Block a user