diff --git a/mods/CORE/WorkStation/init.lua b/mods/CORE/WorkStation/init.lua new file mode 100644 index 0000000..ca9c573 --- /dev/null +++ b/mods/CORE/WorkStation/init.lua @@ -0,0 +1,4 @@ +local modInfo = Mod.getInfo('smc__core__work_station') +local require = modInfo.require + +return require('WorkStation') diff --git a/mods/CORE/WorkStation/mod.conf b/mods/CORE/WorkStation/mod.conf new file mode 100644 index 0000000..0c8fb65 --- /dev/null +++ b/mods/CORE/WorkStation/mod.conf @@ -0,0 +1,2 @@ +name = smc__core__work_station +depends = smc__core__craft_system, smc__core__node, smc__ui__work_station diff --git a/mods/CORE/WorkStation/src/WorkStation.lua b/mods/CORE/WorkStation/src/WorkStation.lua new file mode 100644 index 0000000..408c61d --- /dev/null +++ b/mods/CORE/WorkStation/src/WorkStation.lua @@ -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 diff --git a/mods/CORE/WorkStation/textures/test_station.png b/mods/CORE/WorkStation/textures/test_station.png new file mode 100644 index 0000000..b0d7f0a Binary files /dev/null and b/mods/CORE/WorkStation/textures/test_station.png differ diff --git a/mods/UI/WorkStationUI/init.lua b/mods/UI/WorkStationUI/init.lua new file mode 100644 index 0000000..de174c3 --- /dev/null +++ b/mods/UI/WorkStationUI/init.lua @@ -0,0 +1,4 @@ +local modInfo = Mod.getInfo('smc__ui__work_station') +local require = modInfo.require + +return require('WorkStationUI') diff --git a/mods/UI/WorkStationUI/mod.conf b/mods/UI/WorkStationUI/mod.conf new file mode 100644 index 0000000..d64e453 --- /dev/null +++ b/mods/UI/WorkStationUI/mod.conf @@ -0,0 +1,2 @@ +name = smc__ui__work_station +depends = smc__core__formspec diff --git a/mods/UI/WorkStationUI/src/WorkStationUI.lua b/mods/UI/WorkStationUI/src/WorkStationUI.lua new file mode 100644 index 0000000..6b359d7 --- /dev/null +++ b/mods/UI/WorkStationUI/src/WorkStationUI.lua @@ -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 \ No newline at end of file