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 |
Reference in New Issue
Block a user