Compare commits
29 Commits
tahrion_te
...
1d43ae1255
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d43ae1255 | |||
| 9426ac01dd | |||
| 21232bd1f7 | |||
| 0c02c0045d | |||
| 205cbc10c2 | |||
| 660c96ab5c | |||
| ec8499ff76 | |||
| 430ac78ea1 | |||
| f7140fb3cc | |||
| 6153b053f6 | |||
| bc03aa4ba6 | |||
| 04f90a7b2d | |||
| 66380fb873 | |||
| 169dd64bce | |||
| 613b7ead83 | |||
| 94dc3fa819 | |||
| 6c77b5a38c | |||
| c41ee05b55 | |||
| 87c6e5f3f3 | |||
| e435b21b43 | |||
| 0baa7af759 | |||
| 83304bbfc1 | |||
| 7dbd2f3be8 | |||
| b41448da7b | |||
| 865f46b734 | |||
| 3dd28858f5 | |||
| 9119582ddd | |||
| a12091fc93 | |||
| cfadf47951 |
@@ -1,5 +1,5 @@
|
|||||||
name: Сообщение об ошибке
|
name: PR-template
|
||||||
about: Сообщить о недоработке игры, которую необходимо исправить.
|
about: PR-template
|
||||||
labels:
|
labels:
|
||||||
- pr/wait review
|
- pr/wait review
|
||||||
- review/need a maintainer
|
- review/need a maintainer
|
||||||
@@ -23,12 +23,12 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: Требования
|
label: Требования
|
||||||
options:
|
options:
|
||||||
- label: Я запускал игру и убедился в том, что она работает.
|
|
||||||
required: true
|
|
||||||
- label: Я ознакомлен с соглашением по разработке и мои изменения следуют принятым стандартам.
|
- label: Я ознакомлен с соглашением по разработке и мои изменения следуют принятым стандартам.
|
||||||
required: true
|
required: true
|
||||||
|
- label: Я запускал игру и убедился в том, что она работает.
|
||||||
|
required: false
|
||||||
- label: Я указал в описании запроса метки (label) с префиксом `Edit:` в соответствии с теми изменениями, которые сделал.
|
- label: Я указал в описании запроса метки (label) с префиксом `Edit:` в соответствии с теми изменениями, которые сделал.
|
||||||
required: true
|
required: false
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
value: |
|
value: |
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__craft_system
|
name = smc__core__craft_system
|
||||||
depends = smc__system__system_loader
|
depends = smc__system__system_loader, smc__core__creature
|
||||||
|
|||||||
@@ -1,117 +1,30 @@
|
|||||||
local HASH_SPLITTER = '&'
|
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@alias CraftSystem.shapelessCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ShapelessCraft[]>>
|
---@type CraftSystem.PrimitiveCraftHandler
|
||||||
---@alias CraftSystem.processualCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ProcessualCraft[]>>
|
local PrimitiveCraftHandler = require('CraftSystem.PrimitiveCraftHandler')
|
||||||
|
---@type CraftSystem.ImmersiveCraftHandler
|
||||||
|
local ImmersiveCraftHandler= require('CraftSystem.ImmersiveCraftHandler')
|
||||||
|
---@type CraftSystem.ImmersiveCraftNode
|
||||||
|
local ImmersiveCraftNode= require('CraftSystem.ImmersiveCraftNode')
|
||||||
|
|
||||||
|
---@alias CraftSystem.CraftGroup string
|
||||||
|
---@alias CraftSystem.CraftRecipe string[]
|
||||||
|
---@alias CraftSystem.CraftType 'primitive'|'immersive'
|
||||||
|
|
||||||
---@class CraftSystem
|
---@class CraftSystem
|
||||||
---@field shapelessCraftsList CraftSystem.shapelessCraftsList
|
local CraftSystem = {}
|
||||||
---@field processualCraftsList CraftSystem.processualCraftsList
|
|
||||||
local CraftSystem = {
|
|
||||||
shapelessCraftsList = {},
|
|
||||||
processualCraftsList = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
---@alias CraftSystem.Craft.Type
|
---@param craftName string
|
||||||
---|'shapeless'
|
---@param def CraftSystem.PrimitiveCraftDef
|
||||||
---|'processual'
|
function CraftSystem.registerPrimitiveCraft(craftName, def)
|
||||||
---@alias CraftSystem.Craft.Group string
|
PrimitiveCraftHandler:addCraft(craftName, def)
|
||||||
---@alias CraftSystem.Craft.Recipe string[]
|
|
||||||
|
|
||||||
---@alias shapelessCraftFunc fun(self:CraftSystem.ShapelessCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?):boolean
|
|
||||||
---@alias processualCraftFunc fun(self:CraftSystem.ProcessualCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?, processTime:number):boolean
|
|
||||||
|
|
||||||
---@class CraftSystem.BaseCraft
|
|
||||||
---@field type CraftSystem.Craft.Type
|
|
||||||
---@field group CraftSystem.Craft.Group
|
|
||||||
---@field output string
|
|
||||||
---@field recipe CraftSystem.Craft.Recipe
|
|
||||||
---@field return table? TODO: доделать тут тип
|
|
||||||
---@field craftFunc (fun(self, ...):boolean)?
|
|
||||||
|
|
||||||
---@class CraftSystem.ShapelessCraft : CraftSystem.BaseCraft
|
|
||||||
---@field craftFunc shapelessCraftFunc?
|
|
||||||
|
|
||||||
---@class CraftSystem.ProcessualCraft : CraftSystem.BaseCraft
|
|
||||||
---@field processTime number
|
|
||||||
---@field craftFunc processualCraftFunc?
|
|
||||||
|
|
||||||
---@param type CraftSystem.Craft.Type
|
|
||||||
---@return CraftSystem.shapelessCraftsList|CraftSystem.processualCraftsList
|
|
||||||
local function getCraftList(type)
|
|
||||||
local craftList
|
|
||||||
|
|
||||||
if type == 'shapeless' then
|
|
||||||
craftList = CraftSystem.shapelessCraftsList
|
|
||||||
elseif type == 'processual' then
|
|
||||||
craftList = CraftSystem.processualCraftsList
|
|
||||||
else
|
|
||||||
error(string.format('Craft type `%s` does not exist.', type))
|
|
||||||
end
|
|
||||||
|
|
||||||
return craftList
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param type CraftSystem.Craft.Type
|
---@param craftName string
|
||||||
---@param group CraftSystem.Craft.Group
|
---@param def CraftSystem.ImmersiveCraftDef
|
||||||
---@return table<string, table>
|
function CraftSystem.registerImmersiveCraft(craftName, def)
|
||||||
local function getCraftGroup(type, group)
|
ImmersiveCraftHandler:addCraft(craftName, def)
|
||||||
local craftList = getCraftList(type)
|
|
||||||
|
|
||||||
---@type table<string, table>?
|
|
||||||
local craftGroup = craftList[group]
|
|
||||||
|
|
||||||
assert(craftGroup ~= nil, string.format('Craft group `%s` does not exist.', type))
|
|
||||||
|
|
||||||
return craftGroup
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param type CraftSystem.Craft.Type
|
|
||||||
---@param group CraftSystem.Craft.Group
|
|
||||||
function CraftSystem.registerCraftGroup(type, group)
|
|
||||||
local craftList = getCraftList(type)
|
|
||||||
|
|
||||||
assert(craftList[group] == nil, string.format('Craft group `%s` is already registered.', type))
|
|
||||||
|
|
||||||
craftList[group] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param recipe CraftSystem.Craft.Recipe
|
|
||||||
---@return string
|
|
||||||
function CraftSystem.getCraftHash(recipe)
|
|
||||||
table.sort(recipe)
|
|
||||||
|
|
||||||
local hash = ''
|
|
||||||
|
|
||||||
for i = 0, #recipe-1 do
|
|
||||||
hash = hash..recipe[i]..HASH_SPLITTER
|
|
||||||
end
|
|
||||||
|
|
||||||
return hash..recipe[#recipe]
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param craftDef CraftSystem.ShapelessCraft|CraftSystem.ProcessualCraft
|
|
||||||
function CraftSystem.registerCraft(craftDef)
|
|
||||||
local craftGroup = getCraftGroup(craftDef.type, craftDef.group)
|
|
||||||
|
|
||||||
local hash = CraftSystem.getCraftHash(craftDef.recipe)
|
|
||||||
|
|
||||||
table.insert(craftGroup[hash], craftDef)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param type CraftSystem.Craft.Type
|
|
||||||
---@param group CraftSystem.Craft.Group
|
|
||||||
---@return CraftSystem.ShapelessCraft[] |
|
|
||||||
--- CraftSystem.processualCraftsList[] |
|
|
||||||
--- nil
|
|
||||||
function CraftSystem.getCraftResults(type, group, recipe)
|
|
||||||
local craftGroup = getCraftGroup(type, group)
|
|
||||||
|
|
||||||
local hash = CraftSystem.getCraftHash(recipe)
|
|
||||||
|
|
||||||
return craftGroup[hash]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return CraftSystem
|
return CraftSystem
|
||||||
13
mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua
Normal file
13
mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---Abstract class for craft.
|
||||||
|
---@class CraftSystem.BaseCraft
|
||||||
|
---@field name string
|
||||||
|
---@field group CraftSystem.CraftGroup
|
||||||
|
local BaseCraft = {}
|
||||||
|
|
||||||
|
---Definition table for the `CraftSystem.BaseCraft`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class CraftSystem.BaseCraftDef
|
||||||
|
---@field group CraftSystem.CraftGroup
|
||||||
|
|
||||||
|
return BaseCraft
|
||||||
47
mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua
Normal file
47
mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---Abstract class for handling crafting.
|
||||||
|
---@class CraftSystem.BaseCraftHandler
|
||||||
|
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
||||||
|
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsList CraftSystem.BaseCraft[]
|
||||||
|
---@field learnedCrafts table<string, table<string, CraftSystem.BaseCraft>>
|
||||||
|
local BaseCraftHandler = {
|
||||||
|
craftsByName = {},
|
||||||
|
craftsByGroup = {},
|
||||||
|
craftsList = {},
|
||||||
|
learnedCrafts = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@return CraftSystem.BaseCraft
|
||||||
|
function BaseCraftHandler:getCraftByName(craftName)
|
||||||
|
local craft = self.craftsByName[craftName]
|
||||||
|
|
||||||
|
assert(craft ~= nil, ('There is no primitive craft named `%s`.'):format(
|
||||||
|
craftName))
|
||||||
|
|
||||||
|
return craft
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftGroup CraftSystem.CraftGroup
|
||||||
|
---@return CraftSystem.BaseCraft[]
|
||||||
|
function BaseCraftHandler:getCraftsByGroup(craftGroup)
|
||||||
|
local crafts = self.craftsByGroup[craftGroup]
|
||||||
|
|
||||||
|
assert(crafts ~= nil, ('There are no primitive crafts with `%s` group'):format(
|
||||||
|
craftGroup))
|
||||||
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param playerName string
|
||||||
|
---@return table<string, CraftSystem.BaseCraft>
|
||||||
|
function BaseCraftHandler:getLearnedCrafts(playerName)
|
||||||
|
local crafts = self.learnedCrafts[playerName]
|
||||||
|
|
||||||
|
assert(crafts ~= nil, ('There is no primitive crafting data for a player named `%s`.'):format(
|
||||||
|
playerName))
|
||||||
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
return BaseCraftHandler
|
||||||
51
mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua
Normal file
51
mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type CraftSystem.BaseCraft
|
||||||
|
local BaseCraft = require('CraftSystem.BaseCraft')
|
||||||
|
---@type CraftSystem.ImmersiveCraftStage
|
||||||
|
local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraft : CraftSystem.BaseCraft
|
||||||
|
---@field startStageName string
|
||||||
|
---@field triggerItem string
|
||||||
|
---@field output string
|
||||||
|
---@field stagesByName table<string, CraftSystem.ImmersiveCraftStage>
|
||||||
|
local ImmersiveCraft = extend(BaseCraft, {})
|
||||||
|
|
||||||
|
---Definition table for the `CraftSystem.ImmersiveCraft`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class CraftSystem.ImmersiveCraftDef : CraftSystem.BaseCraftDef
|
||||||
|
---@field startStageName string
|
||||||
|
---@field triggerItem string
|
||||||
|
---@field output string
|
||||||
|
---@field stages CraftSystem.ImmersiveCraftStageDef[]
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def CraftSystem.ImmersiveCraftDef
|
||||||
|
---@return CraftSystem.ImmersiveCraft
|
||||||
|
function ImmersiveCraft:new(name, def)
|
||||||
|
local stagesByName = {}
|
||||||
|
|
||||||
|
for _, stageDef in ipairs(def.stages) do
|
||||||
|
local stage = ImmersiveCraftStage:new(stageDef)
|
||||||
|
|
||||||
|
stagesByName[stageDef.name] = stage
|
||||||
|
end
|
||||||
|
|
||||||
|
local instance = getInstance(self, {
|
||||||
|
name = name,
|
||||||
|
group = def.group,
|
||||||
|
startStageName = def.startStageName,
|
||||||
|
triggerItem = def.triggerItem,
|
||||||
|
output = def.output,
|
||||||
|
stagesByName = stagesByName,
|
||||||
|
})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return ImmersiveCraft
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
local extend = Class.extend
|
||||||
|
|
||||||
|
local tableInsert = table.insert
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type CraftSystem.BaseCraftHandler
|
||||||
|
local BaseCraftHandler = require('CraftSystem.BaseCraftHandler')
|
||||||
|
---@type CraftSystem.ImmersiveCraft
|
||||||
|
local ImmersiveCraft = require('CraftSystem.ImmersiveCraft')
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftHandler : CraftSystem.BaseCraftHandler
|
||||||
|
---@field craftsByTriggerItem table<string, CraftSystem.ImmersiveCraft[]>
|
||||||
|
---@field getCraftByName fun(self, craftName:string):CraftSystem.ImmersiveCraft
|
||||||
|
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.ImmersiveCraft[]
|
||||||
|
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.ImmersiveCraft>
|
||||||
|
local ImmersiveCraftHandler = extend(BaseCraftHandler, {
|
||||||
|
craftsByTriggerItem = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param def CraftSystem.ImmersiveCraftDef
|
||||||
|
function ImmersiveCraftHandler:addCraft(craftName, def)
|
||||||
|
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
||||||
|
craftName))
|
||||||
|
|
||||||
|
local craft = ImmersiveCraft:new(craftName, def)
|
||||||
|
|
||||||
|
local group = def.group
|
||||||
|
|
||||||
|
if self.craftsByGroup[group] == nil then
|
||||||
|
self.craftsByGroup[group] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local triggerItem = def.triggerItem
|
||||||
|
|
||||||
|
if self.craftsByTriggerItem[triggerItem] == nil then
|
||||||
|
self.craftsByTriggerItem[triggerItem] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
self.craftsByName[craftName] = craft
|
||||||
|
tableInsert(self.craftsByGroup[group], craft)
|
||||||
|
tableInsert(self.craftsByTriggerItem[triggerItem], craft)
|
||||||
|
tableInsert(self.craftsList, craft)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param triggerItem string
|
||||||
|
---@return CraftSystem.ImmersiveCraft[]?
|
||||||
|
function ImmersiveCraftHandler:getCraftsByTriggerItem(triggerItem)
|
||||||
|
local crafts = self.craftsByTriggerItem[triggerItem]
|
||||||
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
return ImmersiveCraftHandler
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
local extend = Class.extend
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type CraftSystem.ImmersiveCraftNode
|
||||||
|
local ImmersiveCraftNode = require('CraftSystem.ImmersiveCraftNode')
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftNode.TapperNode : CraftSystem.ImmersiveCraftNode
|
||||||
|
local TapperNode = extend(ImmersiveCraftNode, {})
|
||||||
|
|
||||||
|
return TapperNode
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
|
---@alias CraftSystem.ImmersiveCraftStage.HandlerFunc fun(self, Player)
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftStage
|
||||||
|
---@field name string
|
||||||
|
---@field startHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field processHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field endHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field returnItems table? TODO: доделать тут тип
|
||||||
|
local ImmersiveCraftStage = {
|
||||||
|
data = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
---Definition table for the `CraftSystem.ImmersiveCraft`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class CraftSystem.ImmersiveCraftStageDef
|
||||||
|
---@field name string
|
||||||
|
---@field startHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field processHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field endHandler CraftSystem.ImmersiveCraftStage.HandlerFunc
|
||||||
|
---@field returnItems table? TODO: доделать тут тип
|
||||||
|
|
||||||
|
---@param def CraftSystem.ImmersiveCraftStageDef
|
||||||
|
---@return CraftSystem.ImmersiveCraftStage
|
||||||
|
function ImmersiveCraftStage:new(def)
|
||||||
|
local instance = getInstance(self, {
|
||||||
|
name = def.name,
|
||||||
|
startHandler = def.startHandler,
|
||||||
|
processHandler = def.processHandler,
|
||||||
|
endHandler = def.endHandler
|
||||||
|
})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return ImmersiveCraftStage
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
|
---@type CraftSystem.ImmersiveCraftStage
|
||||||
|
local ImmersiveCraftStage = Mod.getInfo('smc__core__craft_system').require('ImmersiveCraftStage')
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftStage.Tapping : CraftSystem.ImmersiveCraftStage
|
||||||
|
---@field targetItem string
|
||||||
|
---@field startHandler fun(self:CraftSystem.ImmersiveCraftStage.Tapping, pos:Position, Player:Player)
|
||||||
|
---@field processHandler fun(self:CraftSystem.ImmersiveCraftStage.Tapping, pos:Position, Player:Player)
|
||||||
|
---@field endHabdler fun(self:CraftSystem.ImmersiveCraftStage.Tapping, pos:Position, Player:Player)
|
||||||
|
---@field entity Entity
|
||||||
|
local Tapping = extend(ImmersiveCraftStage, {})
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftStage.TappingDef
|
||||||
|
---@field targetItem string
|
||||||
|
|
||||||
|
---@param def CraftSystem.ImmersiveCraftStage.TappingDef
|
||||||
|
function Tapping:new(def)
|
||||||
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
|
instance.targetItem = def.targetItem
|
||||||
|
|
||||||
|
instance.startHandler = function(self, pos, Player)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.processHandler = function(self, pos, Player)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.endHabdler = function(self, pos, Player)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return Tapping
|
||||||
38
mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua
Normal file
38
mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type CraftSystem.BaseCraft
|
||||||
|
local BaseCraft = require('CraftSystem.BaseCraft')
|
||||||
|
|
||||||
|
---@class CraftSystem.PrimitiveCraft : CraftSystem.BaseCraft
|
||||||
|
---@field output string
|
||||||
|
---@field recipe CraftSystem.CraftRecipe
|
||||||
|
---@field returnItems table? TODO: доделать тут тип
|
||||||
|
local PrimitiveCraft = extend(BaseCraft, {})
|
||||||
|
|
||||||
|
---Definition table for the `CraftSystem.PrimitiveCraft`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class CraftSystem.PrimitiveCraftDef : CraftSystem.BaseCraftDef
|
||||||
|
---@field output string
|
||||||
|
---@field recipe CraftSystem.CraftRecipe
|
||||||
|
---@field returnItems table? TODO: доделать тут тип
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def CraftSystem.PrimitiveCraftDef
|
||||||
|
---@return CraftSystem.PrimitiveCraft
|
||||||
|
function PrimitiveCraft:new(name, def)
|
||||||
|
local instance = getInstance(self, {
|
||||||
|
name = name,
|
||||||
|
group = def.group,
|
||||||
|
output = def.output,
|
||||||
|
recipe = def.recipe,
|
||||||
|
returnItems = def.returnItems or {}
|
||||||
|
})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return PrimitiveCraft
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
local extend = Class.extend
|
||||||
|
|
||||||
|
local tableInsert = table.insert
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type CraftSystem.BaseCraftHandler
|
||||||
|
local BaseCraftHandler = require('CraftSystem.BaseCraftHandler')
|
||||||
|
|
||||||
|
---@type CraftSystem.PrimitiveCraft
|
||||||
|
local PrimitiveCraft = require('CraftSystem.PrimitiveCraft')
|
||||||
|
|
||||||
|
---@class CraftSystem.PrimitiveCraftHandler : CraftSystem.BaseCraftHandler
|
||||||
|
---@field getCraftByName fun(self, craftName:string):CraftSystem.PrimitiveCraft
|
||||||
|
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.PrimitiveCraft[]
|
||||||
|
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.PrimitiveCraft>
|
||||||
|
local PrimitiveCraftHandler = extend(BaseCraftHandler, {})
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param def CraftSystem.PrimitiveCraftDef
|
||||||
|
function PrimitiveCraftHandler:addCraft(craftName, def)
|
||||||
|
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
||||||
|
craftName))
|
||||||
|
|
||||||
|
local craft = PrimitiveCraft:new(craftName, def)
|
||||||
|
|
||||||
|
local group = def.group
|
||||||
|
|
||||||
|
if self.craftsByGroup[group] == nil then
|
||||||
|
self.craftsByGroup[group] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
self.craftsByName[craftName] = craft
|
||||||
|
tableInsert(self.craftsByGroup[group], craft)
|
||||||
|
tableInsert(self.craftsList, craft)
|
||||||
|
end
|
||||||
|
|
||||||
|
return PrimitiveCraftHandler
|
||||||
15
mods/CORE/CraftSystem/src/CraftSystem/immersiveCraftNode.lua
Normal file
15
mods/CORE/CraftSystem/src/CraftSystem/immersiveCraftNode.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---@type Creature
|
||||||
|
local Creature = Mod.getInfo('smc__core__entity').require('Creature')
|
||||||
|
|
||||||
|
---@class CraftSystem.ImmersiveCraftNode : Creature
|
||||||
|
local ImmersiveCraftNode = Creature:getExtended({
|
||||||
|
settings = {
|
||||||
|
_name = 'craft_system:immersive_craft_node',
|
||||||
|
_add_mod_name = false,
|
||||||
|
initial_properties = {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return ImmersiveCraftNode
|
||||||
4
mods/CORE/Creature/init.lua
Normal file
4
mods/CORE/Creature/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__creature')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Creature')
|
||||||
1
mods/CORE/Creature/mod.conf
Normal file
1
mods/CORE/Creature/mod.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name = smc__core__creature
|
||||||
109
mods/CORE/Creature/src/Creature.lua
Normal file
109
mods/CORE/Creature/src/Creature.lua
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
|
local tableCopy, tableMerge = table.copy, table.merge
|
||||||
|
|
||||||
|
---@class Creature
|
||||||
|
---@field entityDef Creature.CreatureDefinition
|
||||||
|
---@field luantiDef EntityDefinition
|
||||||
|
---@field defaultDef Creature.CreatureDefinition
|
||||||
|
local Creature = {
|
||||||
|
defaultDef = {
|
||||||
|
settings = {
|
||||||
|
_name = '',
|
||||||
|
_add_mod_name = true,
|
||||||
|
initial_properties = {},
|
||||||
|
},
|
||||||
|
callbacks = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param entityDef Creature.CreatureDefinition
|
||||||
|
---@return EntityDefinition
|
||||||
|
local function entityDefToLuantiDef(entityDef)
|
||||||
|
entityDef = tableCopy(entityDef)
|
||||||
|
local s = entityDef.settings
|
||||||
|
local c = entityDef.callbacks or {}
|
||||||
|
|
||||||
|
---@type EntityDefinition
|
||||||
|
local luantiDef = tableMerge(s, c)
|
||||||
|
|
||||||
|
return luantiDef
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param entityDef Creature.CreatureDefinition
|
||||||
|
---@return Creature
|
||||||
|
function Creature:new(entityDef)
|
||||||
|
-- Adding default parameters.
|
||||||
|
---@type Creature.CreatureDefinition
|
||||||
|
entityDef = tableMerge(entityDef, self.defaultDef, true)
|
||||||
|
|
||||||
|
-- The callback table may not be specified.
|
||||||
|
if entityDef.callbacks == nil then
|
||||||
|
---@type Creature.Callbacks
|
||||||
|
entityDef.callbacks = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local s = entityDef.settings
|
||||||
|
local c = entityDef.callbacks
|
||||||
|
|
||||||
|
-- Add the short mod name prefix to the entity name.
|
||||||
|
if s._add_mod_name then
|
||||||
|
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
||||||
|
end
|
||||||
|
|
||||||
|
local onActivate = c.on_activate or function() end
|
||||||
|
|
||||||
|
-- We rewrite the entity initialization function so that custom fields
|
||||||
|
-- can be passed to it directly via `core.add_entity(pos, name, [staticdata])`.
|
||||||
|
c.on_activate = function(self, staticdata, dtime)
|
||||||
|
local initCustomFields = {}
|
||||||
|
|
||||||
|
if staticdata and staticdata ~= '' then
|
||||||
|
initCustomFields = core.deserialize(staticdata) or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We reset the fields that should not be overwritten.
|
||||||
|
initCustomFields.name = nil
|
||||||
|
initCustomFields.object = nil
|
||||||
|
|
||||||
|
---@type LuaEntity
|
||||||
|
self = tableMerge(self, initCustomFields)
|
||||||
|
|
||||||
|
-- If an initialization callback was specified for the entity, then we call it.
|
||||||
|
if c.on_activate ~= nil then
|
||||||
|
onActivate(self, staticdata, dtime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type Creature
|
||||||
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
|
local luantiDef = entityDefToLuantiDef(entityDef)
|
||||||
|
|
||||||
|
instance.entityDef = entityDef
|
||||||
|
instance.luantiDef = luantiDef
|
||||||
|
|
||||||
|
core.register_entity(s._name, luantiDef)
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---Allows you to create a child class of an entity by specifying
|
||||||
|
---default parameters that will be added to the entity's parameters
|
||||||
|
---when an instance is received.
|
||||||
|
---@param defaultDef Creature.CreatureDefinition
|
||||||
|
---@return Creature
|
||||||
|
function Creature:getExtended(defaultDef)
|
||||||
|
-- Adding default parameters.
|
||||||
|
---@type Creature.CreatureDefinition
|
||||||
|
defaultDef = tableMerge(self.defaultDef, defaultDef)
|
||||||
|
|
||||||
|
---@type Creature
|
||||||
|
local ChildClass = extend(self, {
|
||||||
|
defaultDef = defaultDef,
|
||||||
|
})
|
||||||
|
|
||||||
|
return ChildClass
|
||||||
|
end
|
||||||
|
|
||||||
|
return Creature
|
||||||
72
mods/CORE/Creature/src/Creature/Callbacks.lua
Normal file
72
mods/CORE/Creature/src/Creature/Callbacks.lua
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
---@class Creature.Callbacks
|
||||||
|
local Callbacks = {}
|
||||||
|
|
||||||
|
---Called when the object is instantiated.
|
||||||
|
--- * `dtime_s` is the time passed since the object was unloaded,
|
||||||
|
---which can be used for updating the entity state.
|
||||||
|
---@type fun(self:LuaEntity, staticdata:string, dtime_s:number)?
|
||||||
|
Callbacks.on_activate = nil
|
||||||
|
|
||||||
|
---Called when the object is about to get removed or unloaded.
|
||||||
|
--- * `removal`: boolean indicating whether the object is about to get removed.
|
||||||
|
--- Calling `object:remove()` on an active object will call this with `removal=true`.
|
||||||
|
--- The mapblock the entity resides in being unloaded will call this with `removal=false`.
|
||||||
|
---
|
||||||
|
---Note that this won't be called if the object hasn't been activated in the first place.
|
||||||
|
---In particular, `core.clear_objects({mode = "full"})` won't call this,
|
||||||
|
---whereas `core.clear_objects({mode = "quick"})` might call this.
|
||||||
|
---@type fun(self:LuaEntity, removal:boolean)?
|
||||||
|
Callbacks.on_deactivate = nil
|
||||||
|
|
||||||
|
---Called on every server tick, after movement and collision processing.
|
||||||
|
--- * `dtime`: elapsed time since last call
|
||||||
|
--- * `s`: table with collision info (only available if `physical=true`)
|
||||||
|
---@type fun(self:LuaEntity, dtime:number, moveresult:table)? -- TODO: дописать более точный тип moveresult
|
||||||
|
Callbacks.on_step = nil
|
||||||
|
|
||||||
|
---Called when somebody punches the object.
|
||||||
|
---Note that you probably want to handle most punches using the automatic armor group system.
|
||||||
|
--- * `puncher`: an `ObjectRef `(can be `nil`)
|
||||||
|
--- * `time_from_last_punch`: Meant for disallowing spamming of clicks (can be `nil`).
|
||||||
|
--- * `tool_capabilities`: capability table of used item
|
||||||
|
--- * `dir`: unit vector of direction of punch. Always defined. Points from the puncher to the punched.
|
||||||
|
--- * `damage``: damage that will be done to entity.
|
||||||
|
---
|
||||||
|
---Can return `true` to prevent the default damage mechanism.
|
||||||
|
---@type (fun(self:LuaEntity, puncher:ObjectRef|Player|nil, time_from_last_punch:number|nil, tool_capabilities:table|nil, dir:vector, damage:number):boolean)? -- TODO: дописать более точный тип для tool_capabilities
|
||||||
|
Callbacks.on_punch = nil
|
||||||
|
|
||||||
|
---Called when the object dies.
|
||||||
|
--- * `killer`: an `ObjectRef` (can be `nil`)
|
||||||
|
---@type fun(self:LuaEntity, killer:ObjectRef|Player|nil)?
|
||||||
|
Callbacks.on_death = nil
|
||||||
|
|
||||||
|
---Called when `clicker` pressed the 'place/use' key while
|
||||||
|
---pointing to the object (not necessarily an actual rightclick)
|
||||||
|
--- * `clicker`: an `ObjectRef` (may or may not be a player)
|
||||||
|
---@type fun(self:LuaEntity, clicker:ObjectRef|Player)?
|
||||||
|
Callbacks.on_rightclick = nil
|
||||||
|
|
||||||
|
---Called after another object is attached to this object.
|
||||||
|
--- * `child`: an `ObjectRef` of the child
|
||||||
|
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||||
|
Callbacks.on_attach_child = nil
|
||||||
|
|
||||||
|
---Called after another object has detached from this object.
|
||||||
|
--- * `child`: an `ObjectRef` of the child
|
||||||
|
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||||
|
Callbacks.on_detach_child = nil
|
||||||
|
|
||||||
|
---Called after detaching from another object.
|
||||||
|
--- * `parent`: an ObjectRef from where it got detached
|
||||||
|
---
|
||||||
|
---**Note**: this is also called before removal from the world.
|
||||||
|
---@type fun(self:LuaEntity, parent)?
|
||||||
|
Callbacks.on_detach = nil
|
||||||
|
|
||||||
|
---Should return a string that will be passed to `on_activate` when the object
|
||||||
|
---is instantiated the next time.
|
||||||
|
---@type (fun(self:LuaEntity):string)?
|
||||||
|
Callbacks.get_staticdata = nil
|
||||||
|
|
||||||
|
return Callbacks
|
||||||
6
mods/CORE/Creature/src/Creature/CreatureDefinition.lua
Normal file
6
mods/CORE/Creature/src/Creature/CreatureDefinition.lua
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---@class Creature.CreatureDefinition
|
||||||
|
---@field settings Creature.Settings
|
||||||
|
---@field callbacks Creature.Callbacks?
|
||||||
|
local CreatureDefinition = {}
|
||||||
|
|
||||||
|
return CreatureDefinition
|
||||||
14
mods/CORE/Creature/src/Creature/Settings.lua
Normal file
14
mods/CORE/Creature/src/Creature/Settings.lua
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---@class Creature.Settings
|
||||||
|
local Settings = {}
|
||||||
|
|
||||||
|
---Registration name for the entity. Must be unique.
|
||||||
|
---@type string
|
||||||
|
Settings._name = nil
|
||||||
|
|
||||||
|
---Whether to add the mod name to the settings._name. Default: `true`
|
||||||
|
Settings._add_mod_name = nil
|
||||||
|
|
||||||
|
---@type ObjectProperties
|
||||||
|
Settings.initial_properties = nil
|
||||||
|
|
||||||
|
return Settings
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__core__entity
|
|
||||||
9
mods/CORE/Item/locale/item.ru.tr
Normal file
9
mods/CORE/Item/locale/item.ru.tr
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# textdomain: item
|
||||||
|
|
||||||
|
Rarity=Редкость
|
||||||
|
common=простой
|
||||||
|
uncommon=необычный
|
||||||
|
distinguished=выдающийся
|
||||||
|
eminent=исключительный
|
||||||
|
prime=Превосходный
|
||||||
|
unique=Уникальный
|
||||||
@@ -1,33 +1,84 @@
|
|||||||
local getInstance = Class.getInstance
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
|
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__item')
|
local modInfo = Mod.getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||||
|
|
||||||
|
---Determines whether common rarity will be shown in item descriptions or not.
|
||||||
|
local SHOW_COMMON_RARITY = true
|
||||||
|
|
||||||
|
---Colors corresponding to the rarity color in the item description.
|
||||||
|
---@type table<Item.Rarity, ColorString>
|
||||||
|
local RARITY_COLORS = {
|
||||||
|
['common'] = '#C0C0C0',
|
||||||
|
['uncommon'] = '#7cd2e2',
|
||||||
|
['distinguished'] = '#7ce2da',
|
||||||
|
['eminent'] = '#44d1a9',
|
||||||
|
['prime'] = '#9CF0B1',
|
||||||
|
['unique'] = '#f4c95a'
|
||||||
|
}
|
||||||
|
|
||||||
|
---Whether to show the numeric index in the rarity description.
|
||||||
|
local SHOW_RARITY_INDEX = true
|
||||||
|
|
||||||
|
---@type table<Item.Rarity, integer>
|
||||||
|
local RARITY_INDEX = {
|
||||||
|
['common'] = 1,
|
||||||
|
['uncommon'] = 2,
|
||||||
|
['distinguished'] = 3,
|
||||||
|
['eminent'] = 4,
|
||||||
|
['prime'] = 5,
|
||||||
|
['unique'] = 0
|
||||||
|
}
|
||||||
|
|
||||||
---@class Item
|
---@class Item
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef table
|
---@field luantiDef ItemDefinition
|
||||||
---@field getVisual fun(): string
|
---@field getVisual fun(): string
|
||||||
---@field defaultDef Item.ItemDefinition
|
---@field defaultDef Item.ItemDefinition
|
||||||
local Item = {
|
local Item = {
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
title = '',
|
_title = '',
|
||||||
description = '',
|
_description = '',
|
||||||
titleColor = '#FFFFFF',
|
_title_color = '#FFFFFF',
|
||||||
descriptionColor = '#C0C0C0',
|
_description_color = '#C0C0C0',
|
||||||
addModName = true,
|
_rarity = 'common',
|
||||||
|
_add_mod_name = true,
|
||||||
},
|
},
|
||||||
callbacks = {}
|
callbacks = {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---Adds an item's rarity tag to the description.
|
||||||
|
---@param rarity Item.Rarity
|
||||||
|
---@param desc string
|
||||||
|
---@return string
|
||||||
|
local function addRarityToDesc(rarity, desc)
|
||||||
|
if not SHOW_COMMON_RARITY and rarity == 'common' then
|
||||||
|
return desc
|
||||||
|
end
|
||||||
|
|
||||||
|
local S = core.get_translator('item')
|
||||||
|
local color = RARITY_COLORS[rarity]
|
||||||
|
|
||||||
|
local rarityString = S('Rarity')..': '..S(rarity)
|
||||||
|
|
||||||
|
if SHOW_RARITY_INDEX then
|
||||||
|
rarityString = rarityString..' ['..RARITY_INDEX[rarity]..']'
|
||||||
|
end
|
||||||
|
|
||||||
|
return desc..'\n'..colorize(color, rarityString)
|
||||||
|
end
|
||||||
|
|
||||||
---The alias `table.merge` for EmmyLua
|
---The alias `table.merge` for EmmyLua
|
||||||
---@type fun(...):(NodeDefinition|ItemDefinition)
|
---@type fun(...):(NodeDefinition|ItemDefinition)
|
||||||
local defMerge = function(...)
|
local defMerge = function(...)
|
||||||
return table.merge(...)
|
return tableMerge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
@@ -36,16 +87,12 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
local modName = Mod.getInfo().shortName
|
local modName = Mod.getInfo().shortName
|
||||||
local S = core.get_translator(modName)
|
local S = core.get_translator(modName)
|
||||||
|
|
||||||
itemDef = table.copy(itemDef)
|
itemDef = tableCopy(itemDef)
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
local c = itemDef.callbacks
|
local c = itemDef.callbacks
|
||||||
|
|
||||||
if s.addModName then
|
local title = s._title
|
||||||
s.name = modName .. ':' .. s.name
|
local description = s._description
|
||||||
end
|
|
||||||
|
|
||||||
local title = s.title
|
|
||||||
local description = s.description
|
|
||||||
|
|
||||||
if title == nil or title == '' then
|
if title == nil or title == '' then
|
||||||
title = string.match(s.name, '%S:(%S+)')..'-title'
|
title = string.match(s.name, '%S:(%S+)')..'-title'
|
||||||
@@ -55,59 +102,73 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.titleColor ~= nil and s.descriptionColor ~= nil then
|
if s._title_color ~= nil and s._description_color ~= nil then
|
||||||
description = core.colorize(s.titleColor ,S(title))..'\n'..
|
description = colorize(s._title_color ,S(title))..'\n'..
|
||||||
core.colorize(s.descriptionColor, S(description))
|
colorize(s._description_color, S(description))
|
||||||
else
|
else
|
||||||
error('Item description color parameters cannot be empty.')
|
error('Item description color parameters cannot be empty.')
|
||||||
end
|
end
|
||||||
|
|
||||||
s.title, s.description = nil, description
|
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||||
|
|
||||||
|
description = addRarityToDesc(s._rarity, description)
|
||||||
|
|
||||||
|
s.description = description..core.get_background_escape_sequence('#110F13')
|
||||||
|
|
||||||
local luantiDef = defMerge(s, c)
|
local luantiDef = defMerge(s, c)
|
||||||
|
|
||||||
return luantiDef
|
return luantiDef
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef NodeDefinition|ItemDefinition
|
---@param luantiDef NodeDefinition
|
||||||
local function register3dItem(luantiDef)
|
local function register3dItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_node(':'..name, luantiDef)
|
core.register_node(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef ItemDefinition
|
---@param luantiDef ItemDefinition
|
||||||
local function registerFlatItem(luantiDef)
|
local function registerFlatItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_craftitem(':'..name, luantiDef)
|
core.register_craftitem(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---The alias `table.merge` for EmmyLua
|
---The alias `table.merge` for EmmyLua
|
||||||
---@type fun(...):(Item.ItemDefinition)
|
---@type fun(...):(Item.ItemDefinition)
|
||||||
local defMerge = function(...)
|
local defMerge = function(...)
|
||||||
return table.merge(...)
|
return tableMerge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:new(itemDef)
|
function Item:new(itemDef)
|
||||||
---Adding default parameters
|
assert(itemDef.settings.description == nil,
|
||||||
|
'The item description was specified using `description`, not `_description`. '..
|
||||||
|
'Please note that the `description` field should not be used when registering an item. '..
|
||||||
|
'Use `_title` and `_description` instead.')
|
||||||
|
|
||||||
|
-- Adding default parameters
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||||
|
local s = itemDef.settings
|
||||||
|
|
||||||
|
if s._add_mod_name then
|
||||||
|
s.name = Mod.getInfo().shortName .. ':' .. s.name
|
||||||
|
end
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||||
local visual = itemDef.settings.visual
|
local visual = itemDef.settings._visual
|
||||||
|
|
||||||
if visual == nil then
|
if visual == nil then
|
||||||
visual = 'item_2d'
|
visual = 'item_2d'
|
||||||
end
|
end
|
||||||
|
|
||||||
itemDef.settings.visual = nil
|
itemDef.settings._visual = nil
|
||||||
|
|
||||||
if visual == 'item_3d' then
|
if visual == 'item_3d' then
|
||||||
register3dItem(luantiDef)
|
register3dItem(luantiDef)
|
||||||
@@ -132,8 +193,10 @@ end
|
|||||||
---@param defaultDef Item.ItemDefinition
|
---@param defaultDef Item.ItemDefinition
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:getExtended(defaultDef)
|
function Item:getExtended(defaultDef)
|
||||||
|
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local ChildClass = Class.extend(self, {
|
local ChildClass = extend(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -146,6 +209,8 @@ end
|
|||||||
function Item:getFactory(defaultDef)
|
function Item:getFactory(defaultDef)
|
||||||
if defaultDef == nil then
|
if defaultDef == nil then
|
||||||
defaultDef = self.defaultDef
|
defaultDef = self.defaultDef
|
||||||
|
else
|
||||||
|
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
|
|||||||
8
mods/CORE/Item/src/Item/Rarity.lua
Normal file
8
mods/CORE/Item/src/Item/Rarity.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---Rarity of items:
|
||||||
|
--- * `common`
|
||||||
|
--- * `uncommon`
|
||||||
|
--- * `distinguished`
|
||||||
|
--- * `eminent`
|
||||||
|
--- * `prime`
|
||||||
|
--- * `unique`
|
||||||
|
---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique'
|
||||||
@@ -5,38 +5,40 @@ local Settings = {}
|
|||||||
---@type string
|
---@type string
|
||||||
Settings.name = ''
|
Settings.name = ''
|
||||||
|
|
||||||
|
---@type string?
|
||||||
|
Settings.description = nil
|
||||||
|
|
||||||
---Whether to add the mod name to the settings.name. Default: `true`
|
---Whether to add the mod name to the settings.name. Default: `true`
|
||||||
---@type boolean?
|
---@type boolean?
|
||||||
Settings.addModName = nil
|
Settings._add_mod_name = nil
|
||||||
|
|
||||||
---Item description. 1st line of item description.
|
---Item description. 1st line of item description.
|
||||||
---@type string?
|
---@type string?
|
||||||
Settings.title = nil
|
Settings._title = nil
|
||||||
|
|
||||||
---Item description. The rest of item description.
|
---Item description. The rest of item description.
|
||||||
---@type string?
|
---@type string?
|
||||||
Settings.description = nil
|
Settings._description = nil
|
||||||
|
|
||||||
---Item title color in description.
|
---Item title color in description.
|
||||||
---
|
---
|
||||||
---Default: `#FFFFFF`
|
---Default: `#FFFFFF`
|
||||||
---@type ColorString?
|
---@type ColorString?
|
||||||
Settings.titleColor = nil
|
Settings._title_color = nil
|
||||||
|
|
||||||
---Item description color in description.
|
---Item description color in description.
|
||||||
---
|
---
|
||||||
---Default: `#C0C0C0`
|
---Default: `#C0C0C0`
|
||||||
---@type ColorString?
|
---@type ColorString?
|
||||||
Settings.descriptionColor = nil
|
Settings._description_color = nil
|
||||||
|
|
||||||
---@alias Item.Visual
|
|
||||||
---'item_2d'|
|
|
||||||
---'item_3d'
|
|
||||||
|
|
||||||
---Visual node type.
|
---Visual node type.
|
||||||
---@type Item.Visual?
|
---@type Item.Visual?
|
||||||
Settings.visual = nil
|
Settings._visual = nil
|
||||||
|
|
||||||
|
---Formal (lore) rarity of an item. Default `common`.
|
||||||
|
---@type Item.Rarity?
|
||||||
|
Settings._rarity = nil
|
||||||
|
|
||||||
|
|
||||||
---Table of groups-characteristics of Item.
|
---Table of groups-characteristics of Item.
|
||||||
|
|||||||
1
mods/CORE/Item/src/Item/Visual.lua
Normal file
1
mods/CORE/Item/src/Item/Visual.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---@alias Item.Visual 'item_2d'|'item_3d'
|
||||||
@@ -22,7 +22,7 @@ function Node:new(nodeDef)
|
|||||||
---Adding default parameters
|
---Adding default parameters
|
||||||
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
||||||
|
|
||||||
nodeDef.settings.visual = 'item_3d'
|
nodeDef.settings._visual = 'item_3d'
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local instance = Item:new(nodeDef)
|
local instance = Item:new(nodeDef)
|
||||||
@@ -35,6 +35,8 @@ end
|
|||||||
---@param defaultDef Node.NodeDefinition
|
---@param defaultDef Node.NodeDefinition
|
||||||
---@return Node
|
---@return Node
|
||||||
function Node:getExtended(defaultDef)
|
function Node:getExtended(defaultDef)
|
||||||
|
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local ChildClass = Class.extend(self, {
|
local ChildClass = Class.extend(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
@@ -49,6 +51,8 @@ end
|
|||||||
function Node:getFactory(defaultDef)
|
function Node:getFactory(defaultDef)
|
||||||
if defaultDef == nil then
|
if defaultDef == nil then
|
||||||
defaultDef = self.defaultDef
|
defaultDef = self.defaultDef
|
||||||
|
else
|
||||||
|
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
|
|||||||
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 |
@@ -5,7 +5,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node')
|
|||||||
local defaultLiquidDef = {
|
local defaultLiquidDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
addModName = false,
|
_add_mod_name = false,
|
||||||
tiles = {},
|
tiles = {},
|
||||||
waving = 3,
|
waving = 3,
|
||||||
use_texture_alpha = "blend",
|
use_texture_alpha = "blend",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ for i=0, 3 do
|
|||||||
Plant:new({
|
Plant:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = 'plant'..tostring(i),
|
name = 'plant'..tostring(i),
|
||||||
title = 'Plant',
|
_title = 'Plant',
|
||||||
tiles = { ts:t(i,0) },
|
tiles = { ts:t(i,0) },
|
||||||
place_param2 = 3,
|
place_param2 = 3,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node')
|
|||||||
local defaultRockDef = {
|
local defaultRockDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = "",
|
name = "",
|
||||||
description = "A rocks",
|
_description = "A rocks",
|
||||||
tiles = {},
|
tiles = {},
|
||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
@@ -45,9 +45,28 @@ local function registerRocksTypes(postfix, x)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function registerPilarStaff(rock, y)
|
||||||
|
local columnTop = ts:t(9, y)
|
||||||
|
|
||||||
|
rockFactory:registerNodesByShortDef({
|
||||||
|
{rock..'_fluted_column', {columnTop, columnTop, ts:t(6, y)}},
|
||||||
|
{rock..'_ionic_chapiter', {
|
||||||
|
ts:t(3, y),
|
||||||
|
columnTop,
|
||||||
|
ts:t(7, y),
|
||||||
|
ts:t(7, y),
|
||||||
|
ts:t(8, y),
|
||||||
|
ts:t(8, y)}},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
registerPilarStaff('sylite_black', 2)
|
||||||
|
|
||||||
registerRocksTypes('', 0)
|
registerRocksTypes('', 0)
|
||||||
registerRocksTypes('_block', 2)
|
registerRocksTypes('_chipped', 1)
|
||||||
registerRocksTypes('_bricks', 5)
|
registerRocksTypes('_block', 3)
|
||||||
|
registerRocksTypes('_bricks', 4)
|
||||||
|
registerRocksTypes('_bricks_2', 5)
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
rockFactory:registerItems({
|
rockFactory:registerItems({
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 151 KiB |
@@ -8,7 +8,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node')
|
|||||||
local defaultSoilDef = {
|
local defaultSoilDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = "",
|
name = "",
|
||||||
description = "A soil",
|
_description = "A soil",
|
||||||
tiles = {},
|
tiles = {},
|
||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
@@ -47,7 +47,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "clay_soil_baren",
|
name = "clay_soil_baren",
|
||||||
title = "Barren Clay Soil",
|
_title = "Barren Clay Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = clayTiles,
|
tiles = clayTiles,
|
||||||
},
|
},
|
||||||
@@ -56,7 +56,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "clay_soil_poor",
|
name = "clay_soil_poor",
|
||||||
title = "Poor Clay Soil",
|
_title = "Poor Clay Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = clayTiles,
|
tiles = clayTiles,
|
||||||
},
|
},
|
||||||
@@ -65,7 +65,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "clay_soil_moderate",
|
name = "clay_soil_moderate",
|
||||||
title = "Moderate Clay Soil",
|
_title = "Moderate Clay Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = clayTiles,
|
tiles = clayTiles,
|
||||||
},
|
},
|
||||||
@@ -74,7 +74,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "clay_soil_fertile",
|
name = "clay_soil_fertile",
|
||||||
title = "Fertile Clay Soil",
|
_title = "Fertile Clay Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = clayTiles,
|
tiles = clayTiles,
|
||||||
},
|
},
|
||||||
@@ -83,7 +83,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "clay_soil_rich",
|
name = "clay_soil_rich",
|
||||||
title = "Rich Clay Soil",
|
_title = "Rich Clay Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = clayTiles,
|
tiles = clayTiles,
|
||||||
},
|
},
|
||||||
@@ -96,7 +96,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "sandy_soil_baren",
|
name = "sandy_soil_baren",
|
||||||
title = "Barren Sandy Soil",
|
_title = "Barren Sandy Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = sandyTiles,
|
tiles = sandyTiles,
|
||||||
},
|
},
|
||||||
@@ -105,7 +105,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "sandy_soil_poor",
|
name = "sandy_soil_poor",
|
||||||
title = "Poor Sandy Soil",
|
_title = "Poor Sandy Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = sandyTiles,
|
tiles = sandyTiles,
|
||||||
},
|
},
|
||||||
@@ -114,7 +114,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "sandy_soil_moderate",
|
name = "sandy_soil_moderate",
|
||||||
title = "Moderate Sandy Soil",
|
_title = "Moderate Sandy Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = sandyTiles,
|
tiles = sandyTiles,
|
||||||
},
|
},
|
||||||
@@ -123,7 +123,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "sandy_soil_fertile",
|
name = "sandy_soil_fertile",
|
||||||
title = "Fertile Sandy Soil",
|
_title = "Fertile Sandy Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = sandyTiles,
|
tiles = sandyTiles,
|
||||||
},
|
},
|
||||||
@@ -132,7 +132,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "sandy_soil_rich",
|
name = "sandy_soil_rich",
|
||||||
title = "Rich Sandy Soil",
|
_title = "Rich Sandy Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = sandyTiles,
|
tiles = sandyTiles,
|
||||||
},
|
},
|
||||||
@@ -145,7 +145,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "mixed_soil_baren",
|
name = "mixed_soil_baren",
|
||||||
title = "Barren Mixed Soil",
|
_title = "Barren Mixed Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = mixedTiles,
|
tiles = mixedTiles,
|
||||||
},
|
},
|
||||||
@@ -154,7 +154,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "mixed_soil_poor",
|
name = "mixed_soil_poor",
|
||||||
title = "Poor Mixed Soil",
|
_title = "Poor Mixed Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = mixedTiles,
|
tiles = mixedTiles,
|
||||||
},
|
},
|
||||||
@@ -163,7 +163,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "mixed_soil_moderate",
|
name = "mixed_soil_moderate",
|
||||||
title = "Moderate Mixed Soil",
|
_title = "Moderate Mixed Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = mixedTiles,
|
tiles = mixedTiles,
|
||||||
},
|
},
|
||||||
@@ -172,7 +172,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "mixed_soil_fertile",
|
name = "mixed_soil_fertile",
|
||||||
title = "Fertile Mixed Soil",
|
_title = "Fertile Mixed Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = mixedTiles,
|
tiles = mixedTiles,
|
||||||
},
|
},
|
||||||
@@ -181,7 +181,7 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "mixed_soil_rich",
|
name = "mixed_soil_rich",
|
||||||
title = "Rich Mixed Soil",
|
_title = "Rich Mixed Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = mixedTiles,
|
tiles = mixedTiles,
|
||||||
},
|
},
|
||||||
@@ -194,43 +194,47 @@ soilFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "rocky_soil_baren",
|
name = "rocky_soil_baren",
|
||||||
title = "Barren Rocky Soil",
|
_title = "Barren Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'uncommon'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "rocky_soil_poor",
|
name = "rocky_soil_poor",
|
||||||
title = "Poor Rocky Soil",
|
_title = "Poor Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'distinguished'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "rocky_soil_moderate",
|
name = "rocky_soil_moderate",
|
||||||
title = "Moderate Rocky Soil",
|
_title = "Moderate Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'eminent'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "rocky_soil_fertile",
|
name = "rocky_soil_fertile",
|
||||||
title = "Fertile Rocky Soil",
|
_title = "Fertile Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'prime'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "rocky_soil_rich",
|
name = "rocky_soil_rich",
|
||||||
title = "Rich Rocky Soil",
|
_title = "Rich Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
},
|
},
|
||||||
@@ -248,6 +252,7 @@ Node:new({
|
|||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
soil_fertiliry = 100, -- Soil fertility for agriculture
|
soil_fertiliry = 100, -- Soil fertility for agriculture
|
||||||
}
|
},
|
||||||
|
_rarity = 'unique'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -8,7 +8,7 @@ local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
|||||||
local defaultRockDef = {
|
local defaultRockDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = "",
|
name = "",
|
||||||
description = "A log",
|
_description = "A log",
|
||||||
tiles = {},
|
tiles = {},
|
||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
@@ -21,7 +21,7 @@ local defaultRockDef = {
|
|||||||
local defaultPlanksDef = {
|
local defaultPlanksDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = "",
|
name = "",
|
||||||
description = "A planks",
|
_description = "A planks",
|
||||||
tiles = {},
|
tiles = {},
|
||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
@@ -54,7 +54,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "marentine_log",
|
name = "marentine_log",
|
||||||
title = "Marentine Log",
|
_title = "Marentine Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(0, 1),
|
tiles = t(0, 1),
|
||||||
},
|
},
|
||||||
@@ -63,7 +63,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "allwhere_log",
|
name = "allwhere_log",
|
||||||
title = "Allwhere Log",
|
_title = "Allwhere Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(2, 1),
|
tiles = t(2, 1),
|
||||||
},
|
},
|
||||||
@@ -72,7 +72,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "fis_log",
|
name = "fis_log",
|
||||||
title = "Fis Log",
|
_title = "Fis Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(4, 1),
|
tiles = t(4, 1),
|
||||||
},
|
},
|
||||||
@@ -81,7 +81,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "tammoy_log",
|
name = "tammoy_log",
|
||||||
title = "Tammoy Log",
|
_title = "Tammoy Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(6, 1),
|
tiles = t(6, 1),
|
||||||
},
|
},
|
||||||
@@ -90,7 +90,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "dallalia_log",
|
name = "dallalia_log",
|
||||||
title = "Dallalia Log",
|
_title = "Dallalia Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(8, 1),
|
tiles = t(8, 1),
|
||||||
},
|
},
|
||||||
@@ -99,7 +99,7 @@ logFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "zuph_log",
|
name = "zuph_log",
|
||||||
title = "Zuph Log",
|
_title = "Zuph Log",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(10, 1),
|
tiles = t(10, 1),
|
||||||
},
|
},
|
||||||
@@ -111,7 +111,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "marentine_planks",
|
name = "marentine_planks",
|
||||||
title = "Marentine Planks",
|
_title = "Marentine Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(0, 4) },
|
tiles = { logTileSheet:t(0, 4) },
|
||||||
},
|
},
|
||||||
@@ -120,7 +120,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "allwhere_planks",
|
name = "allwhere_planks",
|
||||||
title = "Allwhere Planks",
|
_title = "Allwhere Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(2, 4) },
|
tiles = { logTileSheet:t(2, 4) },
|
||||||
},
|
},
|
||||||
@@ -129,7 +129,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "fis_planks",
|
name = "fis_planks",
|
||||||
title = "Fis Planks",
|
_title = "Fis Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(4, 4) },
|
tiles = { logTileSheet:t(4, 4) },
|
||||||
},
|
},
|
||||||
@@ -138,7 +138,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "tammoy_planks",
|
name = "tammoy_planks",
|
||||||
title = "Tammoy Planks",
|
_title = "Tammoy Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(6, 4) },
|
tiles = { logTileSheet:t(6, 4) },
|
||||||
},
|
},
|
||||||
@@ -147,7 +147,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "dallalia_planks",
|
name = "dallalia_planks",
|
||||||
title = "Dallalia Planks",
|
_title = "Dallalia Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(8, 4) },
|
tiles = { logTileSheet:t(8, 4) },
|
||||||
},
|
},
|
||||||
@@ -156,7 +156,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "zuph_planks",
|
name = "zuph_planks",
|
||||||
title = "Zuph Planks",
|
_title = "Zuph Planks",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = { logTileSheet:t(10, 4) },
|
tiles = { logTileSheet:t(10, 4) },
|
||||||
},
|
},
|
||||||
@@ -183,7 +183,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "case_closed",
|
name = "case_closed",
|
||||||
title = "Case",
|
_title = "Case",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(0,0)
|
tiles = t(0,0)
|
||||||
},
|
},
|
||||||
@@ -192,7 +192,7 @@ planksFactory:registerItems({
|
|||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = "case_open",
|
name = "case_open",
|
||||||
title = "Case",
|
_title = "Case",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = t(1,0);
|
tiles = t(1,0);
|
||||||
drawtype = 'nodebox';
|
drawtype = 'nodebox';
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
local setMetaTable, TableCopy = setmetatable, table.copy_with_metatables
|
local setMetaTable, tableCopy = setmetatable, table.copy_with_metatables
|
||||||
|
|
||||||
---@class Class
|
---@class Class
|
||||||
Class = {}
|
Class = {}
|
||||||
|
|
||||||
---Returns a child class with inherited parameters from the parent class.
|
---Returns a child class with inherited parameters from the parent class.
|
||||||
---@param parent table
|
---@param parent table
|
||||||
---@param child table
|
---@param child table?
|
||||||
function Class.extend(parent ,child)
|
function Class.extend(parent, child)
|
||||||
return setmetatable(child or {}, { __index = TableCopy(parent) })
|
return setMetaTable(child or {}, { __index = tableCopy(parent) })
|
||||||
end
|
end
|
||||||
|
|
||||||
---Intended for class constructors.
|
---Intended for class constructors.
|
||||||
@@ -23,7 +23,7 @@ function Class.getInstance(self, params, metatable)
|
|||||||
metatable = {}
|
metatable = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
metatable.__index = TableCopy(self)
|
metatable.__index = tableCopy(self)
|
||||||
|
|
||||||
local instance = setMetaTable(params, metatable)
|
local instance = setMetaTable(params, metatable)
|
||||||
|
|
||||||
|
|||||||
@@ -156,10 +156,10 @@ local function mergeInPlace(target, source, recursively)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Merges entries from `t2` into a deep copy of `t1`, skipping existing keys.
|
--- Merges entries from `t2` into a deep copy of `t1`, skipping existing keys.
|
||||||
--- @param t1 table<string, any> | any[] Target table to merge into
|
--- @param t1 table Target table to merge into
|
||||||
--- @param t2 table<string, any> | any[] Source table to merge from
|
--- @param t2 table Source table to merge from
|
||||||
--- @param recursively? boolean Enable recursive merging (default: false)
|
--- @param recursively? boolean Enable recursive merging (default: false)
|
||||||
--- @return table<string, any> | any[]
|
--- @return table
|
||||||
function table.merge(t1, t2, recursively)
|
function table.merge(t1, t2, recursively)
|
||||||
ensureArgType(t1, 'table', 1, 'table.merge')
|
ensureArgType(t1, 'table', 1, 'table.merge')
|
||||||
ensureArgType(t2, 'table', 2, 'table.merge')
|
ensureArgType(t2, 'table', 2, 'table.merge')
|
||||||
|
|||||||
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
|
||||||
Submodule util/ide-helper updated: 3eb0f97115...e5a12d31ba
Reference in New Issue
Block a user