WorkStation: rename WorkStation -> ImmersiveWorkStation, rework code, support new node tab stuff
This commit is contained in:
4
mods/CORE/ImmersiveWorkStation/init.lua
Normal file
4
mods/CORE/ImmersiveWorkStation/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__immersive_work_station')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('ImmersiveWorkStation')
|
||||
2
mods/CORE/ImmersiveWorkStation/mod.conf
Normal file
2
mods/CORE/ImmersiveWorkStation/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__core__immersive_work_station
|
||||
depends = smc__core__craft_system, smc__core__node, smc__ui__work_station
|
||||
218
mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua
Normal file
218
mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua
Normal file
@@ -0,0 +1,218 @@
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
local CraftSystem = Smc.requireCraftSystem()
|
||||
|
||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
-- Default settings that a work station node should have.
|
||||
local ImmersiveWorkStationNode = Node:getExtended({
|
||||
settings = {
|
||||
name = '',
|
||||
drawtype = 'normal',
|
||||
paramtype = 'light',
|
||||
groups = { immersive_station = 1, dig_immediate = 2 }
|
||||
}
|
||||
})
|
||||
|
||||
---A work station (node) that enables player interaction
|
||||
---with the immersive crafting mechanics.
|
||||
---@class ImmersiveWorkStation
|
||||
---@field name string
|
||||
---@field craftType CraftSystem.ImmersiveCraftType
|
||||
---@field handler CraftSystem.ImmersiveCraftHandler
|
||||
---@field tab PlayerInventoryUI.getTabFunc
|
||||
local ImmersiveWorkStation = {}
|
||||
|
||||
---Definition table for the `ImmersiveWorkStation`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class ImmersiveWorkStationDef
|
||||
---@field craftType CraftSystem.ImmersiveCraftType
|
||||
---@field tab PlayerInventoryUI.getTabFunc
|
||||
|
||||
---@param name string
|
||||
---@param def ImmersiveWorkStationDef
|
||||
---@param nodeDef Node.NodeDefinition
|
||||
function ImmersiveWorkStation:new(name, def, nodeDef)
|
||||
local handler = CraftSystem:getImmersiveCraftHandler(def.craftType)
|
||||
|
||||
---@type ImmersiveWorkStation
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.craftType = def.craftType
|
||||
instance.handler = handler
|
||||
instance.tab = def.tab
|
||||
|
||||
if nodeDef.callbacks == nil then
|
||||
---@type Node.Callbacks
|
||||
nodeDef.callbacks = {}
|
||||
end
|
||||
local settings = nodeDef.settings
|
||||
local callbacks = nodeDef.callbacks
|
||||
|
||||
-- Callback when the work station block is installed in the world
|
||||
-- Ensures initialization of necessary parameters
|
||||
callbacks.on_construct = function(pos)
|
||||
instance:init(pos)
|
||||
end
|
||||
|
||||
-- Callback for interaction with a work station (start of crafting)
|
||||
callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
instance:showForm(pos, clicker)
|
||||
end
|
||||
|
||||
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
|
||||
instance:abortCraft(pos)
|
||||
end
|
||||
|
||||
callbacks.on_dig = function(pos, node, digger)
|
||||
---@type ImmersiveWorkStation.MetaData
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
local craftName = meta:get_string('craft_name')
|
||||
if craftName == '' then
|
||||
return core.node_dig(pos, node, digger)
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Registering a node for Luanti.
|
||||
ImmersiveWorkStationNode:new(nodeDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
function ImmersiveWorkStation:showForm(pos, player)
|
||||
local playerName = player:get_player_name()
|
||||
---@type ImmersiveWorkStation.MetaData
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
local craftName = meta:get_string('craft_name')
|
||||
if craftName ~= '' then
|
||||
core.chat_send_player(playerName, 'The workbench is occupied by another craft.')
|
||||
return
|
||||
end
|
||||
|
||||
PlayerInventoryUI:addActiveNodeForm(pos, playerName)
|
||||
PlayerInventoryUI:setContex(playerName, 'left_tab_name', 'node_tab')
|
||||
PlayerInventoryUI:setContex(playerName, 'node_tab_pos', pos)
|
||||
PlayerInventoryUI:setContex(playerName, 'node_tab', self.tab)
|
||||
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end
|
||||
|
||||
---@param pos MapPosition
|
||||
function ImmersiveWorkStation:init(pos)
|
||||
---@type ImmersiveWorkStation.MetaData
|
||||
local meta = core.get_meta(pos)
|
||||
end
|
||||
|
||||
---@param pos MapPosition
|
||||
function ImmersiveWorkStation:abortCraft(pos)
|
||||
---@type ImmersiveWorkStation.MetaData
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
local craftName = meta:get_string('craft_name')
|
||||
if craftName == '' then
|
||||
return
|
||||
end
|
||||
|
||||
local craft = self.handler:getCraftByName(craftName)
|
||||
craft:abortCraft(pos)
|
||||
end
|
||||
|
||||
-- --- DEBUG ---
|
||||
|
||||
local handler = CraftSystem:getImmersiveCraftHandler('workbench')
|
||||
|
||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
||||
local baseGetCraftTab = require('PlayerInventoryUI.baseGetCraftTab')
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param tabType PlayerInventoryUI.TabType
|
||||
---@return Formspec
|
||||
local function tab(self, playerName, tabType)
|
||||
return baseGetCraftTab(self, playerName, tabType, 'node_tab', handler)
|
||||
end
|
||||
|
||||
ImmersiveWorkStation:new('test_station', {
|
||||
craftType = 'workbench',
|
||||
tab = tab,
|
||||
},
|
||||
{
|
||||
settings = {
|
||||
name = 'test_station',
|
||||
tiles = {'test_station.png'}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
handler:registerCraft('bricks', {
|
||||
output = 'rocks:sylite_bricks',
|
||||
recipe = {'rocks:sylite'},
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'rocks:sylite',
|
||||
type = 'tapping',
|
||||
clicksNeed = 3,
|
||||
nextStage = 'tapping_2',
|
||||
},
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping_2',
|
||||
targetItem = 'rocks:sylite_block',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
nextStage = 'tapping_3',
|
||||
},
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping_3',
|
||||
targetItem = 'rocks:sylite_bricks',
|
||||
type = 'tapping',
|
||||
clicksNeed = 1,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
handler:registerCraft('block', {
|
||||
output = 'rocks:sylite_block',
|
||||
recipe = {'rocks:sylite'},
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'rocks:sylite',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
handler:registerCraft('marentine_planks', {
|
||||
output = 'wood:marentine_planks',
|
||||
recipe = {'rocks:sylite'},
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'wood:marentine_log',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
}
|
||||
},
|
||||
})
|
||||
--]]
|
||||
return ImmersiveWorkStation
|
||||
@@ -0,0 +1,9 @@
|
||||
---@alias ImmersiveWorkStation.MetaData.StringKey 'player_name'|'craft_name'|'stage_name'|'stage_data'
|
||||
---@alias ImmersiveWorkStation.MetaData.FloatKey 'craft_amount'
|
||||
|
||||
---**Only for EmmyLua.**
|
||||
---@class ImmersiveWorkStation.MetaData : NodeMetaRef
|
||||
---@field get_string fun(self, key:ImmersiveWorkStation.MetaData.StringKey):string
|
||||
---@field set_string fun(self, key:ImmersiveWorkStation.MetaData.StringKey, value:string)
|
||||
---@field get_float fun(self, key:ImmersiveWorkStation.MetaData.FloatKey):number
|
||||
---@field set_float fun(self, key:ImmersiveWorkStation.MetaData.FloatKey, value:number)
|
||||
BIN
mods/CORE/ImmersiveWorkStation/textures/test_station.png
Normal file
BIN
mods/CORE/ImmersiveWorkStation/textures/test_station.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Reference in New Issue
Block a user