Compare commits
26 Commits
26a73117a9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c3defaaa15 | |||
| 7ccaea2ed0 | |||
| c96bb2c0bc | |||
| 9fa3a0aff7 | |||
| e540107876 | |||
| 1e91290b02 | |||
| 2243ed7532 | |||
| 20ebf5ad75 | |||
| 1fe3200692 | |||
| 24932b5d2e | |||
| af0b7c8beb | |||
| ba8dad4798 | |||
| c2e16834d8 | |||
| 2d3bdf4d02 | |||
| 841d269494 | |||
| ced1397c76 | |||
| 56a9388676 | |||
| 5d3e7b3620 | |||
| f995397f28 | |||
| 9566e0edde | |||
| 316d2cac3b | |||
| 3da8c3a27c | |||
| 266d44eca8 | |||
| d82cd28407 | |||
| 02f7ca2894 | |||
| 7ef96bd434 |
@@ -46,5 +46,6 @@
|
|||||||
"unbalanced": "Any"
|
"unbalanced": "Any"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"completion.callSnippet": "Both"
|
"completion.callSnippet": "Both",
|
||||||
|
"completion.workspaceWord":false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__base_processing_station')
|
local modInfo = Mod:getInfo('smc__core__base_processing_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('BaseProcessingStation')
|
return require('BaseProcessingStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__base_ui')
|
local modInfo = Mod:getInfo('smc__core__base_ui')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('BaseUI')
|
return require('BaseUI')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__controls')
|
local modInfo = Mod:getInfo('smc__core__controls')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Controls')
|
return require('Controls')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('CraftSystem')
|
return require('CraftSystem')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local tableJoin = table.join
|
local tableJoin = table.join
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.PrimitiveCraftHandler
|
---@type CraftSystem.PrimitiveCraftHandler
|
||||||
@@ -205,9 +205,19 @@ end
|
|||||||
---@return boolean check true if craft can be produced
|
---@return boolean check true if craft can be produced
|
||||||
---@return ItemStack[] materialStacks list of itemStacks for crafting
|
---@return ItemStack[] materialStacks list of itemStacks for crafting
|
||||||
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
|
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
|
||||||
|
local OutputStack = ItemStack(craft.output)
|
||||||
|
|
||||||
|
if count <= 0 then
|
||||||
|
Logger.warningLog('`CraftSystem:checkPossiblePlayerInventoryCrafting()`: param `count` <= 0. '..
|
||||||
|
'Was force-reset to `1`. '..
|
||||||
|
'Info: value: `%s`, player: `%s`, craft: `%s`',
|
||||||
|
count, player:get_player_name(), craft.name
|
||||||
|
)
|
||||||
|
count = 1
|
||||||
|
end
|
||||||
|
|
||||||
local inventory = player:get_inventory()
|
local inventory = player:get_inventory()
|
||||||
|
|
||||||
local OutputStack = ItemStack(craft.output)
|
|
||||||
OutputStack:set_count(OutputStack:get_count() * count)
|
OutputStack:set_count(OutputStack:get_count() * count)
|
||||||
|
|
||||||
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)
|
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local assert, pairs, ipairs = assert, pairs, ipairs
|
|||||||
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
||||||
local stringMatch, stringLower = string.match, string_utf8.lower
|
local stringMatch, stringLower = string.match, string_utf8.lower
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler.PlayerCraftsCache
|
---@type CraftSystem.BaseCraftHandler.PlayerCraftsCache
|
||||||
local PlayerCraftsCache = require('CraftSystem.BaseCraftHandler.PlayerCraftsCache')
|
local PlayerCraftsCache = require('CraftSystem.BaseCraftHandler.PlayerCraftsCache')
|
||||||
@@ -239,14 +239,7 @@ local function getMathedCrafts(crafts, pattern)
|
|||||||
local matchedCrafts = {}
|
local matchedCrafts = {}
|
||||||
|
|
||||||
for _, craft in ipairs(crafts) do
|
for _, craft in ipairs(crafts) do
|
||||||
local outputItem = ItemStack(craft.output)
|
if Smc.matchItemDescription(ItemStack(craft.output):get_name(), pattern) then
|
||||||
local itemSettings = Smc.getItemDefinition(outputItem).settings
|
|
||||||
local ruName = stringLower(core.get_translated_string('ru', itemSettings._title))
|
|
||||||
local enName = stringLower(core.get_translated_string('en', itemSettings._title))
|
|
||||||
|
|
||||||
if stringMatch(outputItem:get_name(), pattern) or
|
|
||||||
stringMatch(ruName, pattern) or
|
|
||||||
stringMatch(enName, pattern) then
|
|
||||||
tableInsert(matchedCrafts, craft)
|
tableInsert(matchedCrafts, craft)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local v = vector.new
|
|||||||
local assert, ipairs, tostring = assert, ipairs, tostring
|
local assert, ipairs, tostring = assert, ipairs, tostring
|
||||||
local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop
|
local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
@@ -83,6 +83,15 @@ end
|
|||||||
---@param amount integer
|
---@param amount integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function ImmersiveCraft:startCraft(pos, player, amount)
|
function ImmersiveCraft:startCraft(pos, player, amount)
|
||||||
|
if amount <= 0 then
|
||||||
|
Logger.warningLog('`ImmersiveCraft:startCraft()`: param `amount` <= 0. '..
|
||||||
|
'Was force-reset to `1`. '..
|
||||||
|
'Info: value: `%s`, player: `%s`, craft: `%s`',
|
||||||
|
amount, player:get_player_name(), self.name
|
||||||
|
)
|
||||||
|
amount = 1
|
||||||
|
end
|
||||||
|
|
||||||
local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
|
local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
|
||||||
assert(workStation ~= nil)
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
@@ -124,7 +133,7 @@ function ImmersiveCraft:endCraft(pos, player)
|
|||||||
local playerName = meta:get_string('player_name')
|
local playerName = meta:get_string('player_name')
|
||||||
assert(playerName ~= '')
|
assert(playerName ~= '')
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount > 0)
|
||||||
|
|
||||||
-- Drop the result of crafting.
|
-- Drop the result of crafting.
|
||||||
local dropPos = v(pos) + v(0, 0.9,0)
|
local dropPos = v(pos) + v(0, 0.9,0)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local assert = assert
|
|||||||
|
|
||||||
local tableInsert, tableMerge = table.insert, table.merge
|
local tableInsert, tableMerge = table.insert, table.merge
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@type Creature
|
---@type Creature
|
||||||
local Creature = Mod.getInfo('smc__core__creature').require('Creature')
|
local Creature = Mod:getInfo('smc__core__creature').require('Creature')
|
||||||
|
|
||||||
---The entity the player interacts with during immersive crafting.
|
---The entity the player interacts with during immersive crafting.
|
||||||
---@class CraftSystem.ImmersiveCraftNode : Creature
|
---@class CraftSystem.ImmersiveCraftNode : Creature
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local assert = assert
|
|||||||
local extend = Class.extend
|
local extend = Class.extend
|
||||||
local coreItemDrop = core.item_drop
|
local coreItemDrop = core.item_drop
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ function TappingStage:new(def)
|
|||||||
assert(stageData ~= nil)
|
assert(stageData ~= nil)
|
||||||
|
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount > 0)
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
||||||
local stageData = stageData
|
local stageData = stageData
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local getInstance, extend = Class.getInstance, Class.extend
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraft
|
---@type CraftSystem.BaseCraft
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local extend = Class.extend
|
|||||||
|
|
||||||
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local getInstance, extend = Class.getInstance, Class.extend
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraft
|
---@type CraftSystem.BaseCraft
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local HASH_SEPARATOR = ','
|
|||||||
|
|
||||||
local tableInsert, tableCopy, tableSort, tableConcat, tableIsEmpty = table.insert, table.copy, table.sort, table.concat, table.is_empty
|
local tableInsert, tableCopy, tableSort, tableConcat, tableIsEmpty = table.insert, table.copy, table.sort, table.concat, table.is_empty
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__creature')
|
local modInfo = Mod:getInfo('smc__core__creature')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Creature')
|
return require('Creature')
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function Creature:new(entityDef)
|
|||||||
|
|
||||||
-- Add the short mod name prefix to the entity name.
|
-- Add the short mod name prefix to the entity name.
|
||||||
if s._add_mod_name then
|
if s._add_mod_name then
|
||||||
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
s._name = Mod:getInfo().shortName .. ':' .. s._name
|
||||||
end
|
end
|
||||||
|
|
||||||
local onActivate = c.on_activate or function() end
|
local onActivate = c.on_activate or function() end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
local modInfo = Mod:getInfo('smc__core__formspec')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Formspec')
|
return require('Formspec')
|
||||||
@@ -745,6 +745,41 @@ function Formspec:imageButton(x, y, w, h, textureName, name, label, pressedTextu
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@alias Formspec.ImageButtonRowElement {
|
||||||
|
--- [1] : string,
|
||||||
|
--- [2] : string,
|
||||||
|
--- [3] : string?,
|
||||||
|
--- [4] : string?,
|
||||||
|
--- [5] : boolean?,
|
||||||
|
--- [6] : boolean?,
|
||||||
|
--- }
|
||||||
|
|
||||||
|
---Creates a row of buttons, automatically calculating the coordinates of buttons based on the width.
|
||||||
|
---
|
||||||
|
---@see Formspec.imageButton
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param imageButtonRow Formspec.ImageButtonRowElement[]
|
||||||
|
---@return Formspec
|
||||||
|
function Formspec:imageButtonRow(x, y, w, h, imageButtonRow)
|
||||||
|
---@param element Formspec.ImageButtonRowElement
|
||||||
|
for i, element in ipairs(imageButtonRow) do
|
||||||
|
local ex = x + ( ( i - 1 ) * w)
|
||||||
|
self:imageButton(ex, y, w, h,
|
||||||
|
element[1],
|
||||||
|
element[2],
|
||||||
|
element[3],
|
||||||
|
element[4],
|
||||||
|
element[5],
|
||||||
|
element[6]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
---Clickable item image button. When clicked, fields will be sent.
|
---Clickable item image button. When clicked, fields will be sent.
|
||||||
---
|
---
|
||||||
---**Element:** `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
|
---**Element:** `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__immersive_work_station')
|
local modInfo = Mod:getInfo('smc__core__immersive_work_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ImmersiveWorkStation')
|
return require('ImmersiveWorkStation')
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ end
|
|||||||
|
|
||||||
local handler = CraftSystem:getImmersiveCraftHandler('workbench')
|
local handler = CraftSystem:getImmersiveCraftHandler('workbench')
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
local require = Mod:getInfo('smc__ui__player_inventory').require
|
||||||
local baseGetCraftTab = require('PlayerInventoryUI.baseGetCraftTab')
|
local baseGetCraftTab = require('PlayerInventoryUI.baseGetCraftTab')
|
||||||
|
|
||||||
---@param self PlayerInventoryUI
|
---@param self PlayerInventoryUI
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__item')
|
local modInfo = Mod:getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Item')
|
return require('Item')
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ end
|
|||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
---@return ItemDefinition
|
---@return ItemDefinition
|
||||||
local function itemDefToLuantiDef(itemDef)
|
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)
|
||||||
|
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
@@ -167,7 +167,7 @@ function Item:new(itemDef)
|
|||||||
itemDef = tableMerge(itemDef, self.defaultDef, true) --[[@as Item.ItemDefinition]]
|
itemDef = tableMerge(itemDef, self.defaultDef, true) --[[@as Item.ItemDefinition]]
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
|
|
||||||
local shortModName = Mod.getInfo().shortName
|
local shortModName = Mod:getInfo().shortName
|
||||||
|
|
||||||
if s._add_mod_name then
|
if s._add_mod_name then
|
||||||
s.name = shortModName .. ':' .. s.name
|
s.name = shortModName .. ':' .. s.name
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__item_factory')
|
local modInfo = Mod:getInfo('smc__core__item_factory')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ItemFactory')
|
return require('ItemFactory')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
local modInfo = Mod:getInfo('smc__core__map_gen')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('MapGen')
|
return require('MapGen')
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ local function mglog(text, ...)
|
|||||||
core.log((text):format(...))
|
core.log((text):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---Numeric values defining the surface height and climate for the node.
|
---Numeric values defining the surface height and climate for the node.
|
||||||
---@alias MapGen.Factors {height:number, temp:number, humidity:number, weight:number}
|
---@alias MapGen.Factors {height:number, temp:number, humidity:number, weight:number}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local extend = Class.extend
|
local extend = Class.extend
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local Peak = require('MapGen.Peak')
|
local Peak = require('MapGen.Peak')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local corePosToString, coreGetValueNoise = core.pos_to_string, core.get_value_no
|
|||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local Peak = require('MapGen.Peak')
|
local Peak = require('MapGen.Peak')
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function Tree:new(name, def)
|
|||||||
local intance = getInstance(self, {})
|
local intance = getInstance(self, {})
|
||||||
intance.name = name
|
intance.name = name
|
||||||
intance.path = def.path
|
intance.path = def.path
|
||||||
intance.placerName = Mod.getInfo().shortName..':'..name..'_placer'
|
intance.placerName = Mod:getInfo().shortName..':'..name..'_placer'
|
||||||
|
|
||||||
intance:registerPlacer()
|
intance:registerPlacer()
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local v = vector.new
|
|||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Edge
|
---@type MapGen.Edge
|
||||||
local Edge = require('MapGen.Edge')
|
local Edge = require('MapGen.Edge')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__node')
|
local modInfo = Mod:getInfo('smc__core__node')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Node')
|
return require('Node')
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ local function registerSlab(nodeDef)
|
|||||||
settings.drawtype = 'nodebox'
|
settings.drawtype = 'nodebox'
|
||||||
settings.paramtype = 'light'
|
settings.paramtype = 'light'
|
||||||
settings.paramtype2 = 'facedir'
|
settings.paramtype2 = 'facedir'
|
||||||
settings.groups['segments'] = nil
|
settings.groups.segments = nil
|
||||||
settings.groups['slabs'] = 1
|
settings.groups.slabs = 1
|
||||||
if nodeDef.callbacks ~= nil then
|
if nodeDef.callbacks ~= nil then
|
||||||
nodeDef.callbacks.on_place = core.rotate_and_place
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
else
|
else
|
||||||
@@ -52,8 +52,8 @@ local function registerStair(nodeDef)
|
|||||||
settings.drawtype = 'nodebox'
|
settings.drawtype = 'nodebox'
|
||||||
settings.paramtype = 'light'
|
settings.paramtype = 'light'
|
||||||
settings.paramtype2 = 'facedir'
|
settings.paramtype2 = 'facedir'
|
||||||
settings.groups['segments'] = nil
|
settings.groups.segments = nil
|
||||||
settings.groups['slabs'] = 1
|
settings.groups.stairs = 1
|
||||||
if nodeDef.callbacks ~= nil then
|
if nodeDef.callbacks ~= nil then
|
||||||
nodeDef.callbacks.on_place = core.rotate_and_place
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
else
|
else
|
||||||
@@ -77,7 +77,7 @@ function Node:new(nodeDef)
|
|||||||
-- Registration of segmented blocks.
|
-- Registration of segmented blocks.
|
||||||
-- If you specify a specific group with a specific index for a node,
|
-- If you specify a specific group with a specific index for a node,
|
||||||
-- the slabs and stairs will be registered automatically.
|
-- the slabs and stairs will be registered automatically.
|
||||||
local segmentsIndex = settings.groups and settings.groups['segments']
|
local segmentsIndex = settings.groups and settings.groups.segments
|
||||||
if segmentsIndex == 1 then
|
if segmentsIndex == 1 then
|
||||||
-- Only slabs
|
-- Only slabs
|
||||||
registerSlab(nodeDef)
|
registerSlab(nodeDef)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
---@meta
|
---@meta
|
||||||
|
|
||||||
---@class Node.Settings : Item.Settings, NodeDefinition.Settings
|
---@class Node.Settings : NodeDefinition.Settings, Item.Settings
|
||||||
local Settings = {}
|
local Settings = {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__plant')
|
local modInfo = Mod:getInfo('smc__core__plant')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Plant')
|
return require('Plant')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__player')
|
local modInfo = Mod:getInfo('smc__core__player')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Player')
|
return require('Player')
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
local Player = {}
|
local Player = {}
|
||||||
|
|
||||||
---@type PlayerInventoryUI
|
---@type PlayerInventoryUI
|
||||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
core.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
||||||
@@ -29,7 +29,7 @@ core.register_chatcommand('show_inv',
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__player').require
|
local require = Mod:getInfo('smc__core__player').require
|
||||||
|
|
||||||
require('Player.inventory')
|
require('Player.inventory')
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,2 @@
|
|||||||
|
|
||||||
---@type PlayerInventoryUI
|
---@type PlayerInventoryUI
|
||||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
-- TODO: перенести обработки в PlayerUI
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_container_station')
|
local modInfo = Mod:getInfo('smc__core__processing_container_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingContainerStation')
|
return require('ProcessingContainerStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_fuel_station')
|
local modInfo = Mod:getInfo('smc__core__processing_fuel_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingFuelStation')
|
return require('ProcessingFuelStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_station')
|
local modInfo = Mod:getInfo('smc__core__processing_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingStation')
|
return require('ProcessingStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__progression_system')
|
local modInfo = Mod:getInfo('smc__core__progression_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProgressionSystem')
|
return require('ProgressionSystem')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local assert = assert
|
local assert = assert
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__progression_system').require
|
local require = Mod:getInfo('smc__core__progression_system').require
|
||||||
|
|
||||||
---@type ProgressionSystem.Age
|
---@type ProgressionSystem.Age
|
||||||
local Age = require('ProgressionSystem.Age')
|
local Age = require('ProgressionSystem.Age')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__sound')
|
local modInfo = Mod:getInfo('smc__core__sound')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Sound')
|
return require('Sound')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__tilesheet')
|
local modInfo = Mod:getInfo('smc__core__tilesheet')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('TileSheet')
|
return require('TileSheet')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__tool')
|
local modInfo = Mod:getInfo('smc__core__tool')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Tool')
|
return require('Tool')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
--core.set_mapgen_setting('chunksize', '{x=2,y=10,z=2}', true)
|
--core.set_mapgen_setting('chunksize', '{x=2,y=10,z=2}', true)
|
||||||
|
|
||||||
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
local mapGeneneratorRequire = Mod:getInfo('smc__core__map_generator').require
|
||||||
|
|
||||||
-- Main env init
|
-- Main env init
|
||||||
local mapGenerator = mapGeneneratorRequire('mapGenerator')
|
local mapGenerator = mapGeneneratorRequire('mapGenerator')
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__map_generator
|
name = smc__core__map_generator
|
||||||
depends = smc__core__map_gen, smc__game__items__rocks, smc__game__items__liquids, smc__game__items__soils, smc__game__items__clays, smc__game__items__sands
|
depends = smc__core__map_gen, smc__game__items__rocks, smc__game__items__liquids, smc__game__items__soils, smc__game__items__clays, smc__game__items__sands, smc__game__items__plants
|
||||||
|
|||||||
BIN
mods/ENVIRONMENT/mapGenerator/schems/allwhere_tree_a.mts
Normal file
BIN
mods/ENVIRONMENT/mapGenerator/schems/marentine_tree_a.mts
Normal file
@@ -3,7 +3,7 @@ local id = core.get_content_id
|
|||||||
|
|
||||||
local mathRound = math.round
|
local mathRound = math.round
|
||||||
|
|
||||||
local mapGenRequire = Mod.getInfo('smc__core__map_gen').require
|
local mapGenRequire = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen
|
---@type MapGen
|
||||||
local MapGen = mapGenRequire('MapGen')
|
local MapGen = mapGenRequire('MapGen')
|
||||||
@@ -25,6 +25,11 @@ local MapGen = mapGenRequire('MapGen')
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- --- Layers ---
|
||||||
|
local LAYERS_NAMES = {
|
||||||
|
[1] = 'videre'
|
||||||
|
}
|
||||||
|
|
||||||
local function calcTemp(layer, value, height)
|
local function calcTemp(layer, value, height)
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
@@ -33,7 +38,7 @@ local function calcHumidity(layer, value, height)
|
|||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
mapGenerator:registerLayer('videre', {
|
mapGenerator:registerLayer(LAYERS_NAMES[1], {
|
||||||
minY = -256,
|
minY = -256,
|
||||||
maxY = 256,
|
maxY = 256,
|
||||||
minTemp = -100,
|
minTemp = -100,
|
||||||
@@ -146,7 +151,7 @@ local coldOcean = {
|
|||||||
|
|
||||||
local tropicalSoutheast = {
|
local tropicalSoutheast = {
|
||||||
['landscape'] = {
|
['landscape'] = {
|
||||||
offset = 20,
|
offset = 2,
|
||||||
scale = 5,
|
scale = 5,
|
||||||
spread = {x = 15, y = 15, z = 15},
|
spread = {x = 15, y = 15, z = 15},
|
||||||
seed = 11611411111210599971088311111711610410197115116,
|
seed = 11611411111210599971088311111711610410197115116,
|
||||||
@@ -357,20 +362,196 @@ local icyNorthernMMountains = {
|
|||||||
local v = vector.new
|
local v = vector.new
|
||||||
|
|
||||||
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#5792ce', warmOcean[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#5792ce', warmOcean[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#4978c6', temperateOcean[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#4978c6', temperateOcean[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#4763b1', coldOcean[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#4763b1', coldOcean[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#a0ab72', tropicalSoutheast[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#a0ab72', tropicalSoutheast[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#dcd492', steppeSouthwest[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#dcd492', steppeSouthwest[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#a3c27c', temperateCentralZone[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#a3c27c', temperateCentralZone[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#999d8f', lowMountains[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#999d8f', lowMountains[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#569574', subarcticNorth[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#569574', subarcticNorth[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#76c2b6', arcticNorth[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#76c2b6', arcticNorth[c])
|
||||||
mapGenerator:registerLayerNoiseColor('videre', c, '#bac0ad', icyNorthernMMountains[c])
|
mapGenerator:registerLayerNoiseColor(LAYERS_NAMES[1], c, '#bac0ad', icyNorthernMMountains[c])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- --- Biomes ---
|
-- --- Videre biomes ---
|
||||||
|
-- Chalybeate bog (Оржавинь)
|
||||||
|
--[[
|
||||||
|
mapGenerator:registerBiome(LAYERS_NAMES[1], 'chalybeate_bog', {
|
||||||
|
tempPoint = 30,
|
||||||
|
humidityPoint = 90,
|
||||||
|
minY = -10,
|
||||||
|
maxY = 15,
|
||||||
|
groundNodes = {
|
||||||
|
soil = 'soils:mud',
|
||||||
|
turf = 'soils:turf_bog',
|
||||||
|
rock = 'rocks:basalt',
|
||||||
|
bottom = 'soils:mud',
|
||||||
|
},
|
||||||
|
soilHeight = 5
|
||||||
|
})--]]
|
||||||
|
|
||||||
|
---@type NoiseParams
|
||||||
|
local peatBogTurfNoiseParams = {
|
||||||
|
offset = 0,
|
||||||
|
scale = 0.5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 42,
|
||||||
|
octaves = 6,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type ValueNoise?
|
||||||
|
local peatBogTurfNoise = nil
|
||||||
|
|
||||||
|
local peatBogPlantsNoiseParams = {
|
||||||
|
offset = 0,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 24,
|
||||||
|
octaves = 6,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type ValueNoise?
|
||||||
|
local peatBogPlantsNoise = nil
|
||||||
|
|
||||||
|
local placeParam2 = {
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
34,
|
||||||
|
35,
|
||||||
|
36
|
||||||
|
}
|
||||||
|
|
||||||
|
local ID_BOG_GRASS_1 = id('plants:bog_grass_1')
|
||||||
|
local ID_BOG_GRASS_2 = id('plants:bog_grass_2')
|
||||||
|
local ID_BOG_GRASS_3 = id('plants:bog_grass_3')
|
||||||
|
|
||||||
|
local ID_TURF_BOG = id('soils:turf_bog')
|
||||||
|
local ID_MUD = id('soils:mud')
|
||||||
|
|
||||||
|
-- Peat bog (Багно)
|
||||||
|
mapGenerator:registerBiome(LAYERS_NAMES[1], 'peat_bog', {
|
||||||
|
tempPoint = 25,
|
||||||
|
humidityPoint = 95,
|
||||||
|
minY = -10,
|
||||||
|
maxY = 15,
|
||||||
|
groundNodes = {
|
||||||
|
soil = 'soils:mud',
|
||||||
|
turf = 'soils:mud',
|
||||||
|
rock = 'rocks:basalt',
|
||||||
|
bottom = 'soils:mud',
|
||||||
|
},
|
||||||
|
soilHeight = 5,
|
||||||
|
|
||||||
|
generateTurf = function (self, mapGenerator, factors, data, data2, index, x, y, z)
|
||||||
|
if peatBogTurfNoise == nil then
|
||||||
|
peatBogTurfNoise = core.get_value_noise(peatBogTurfNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = peatBogTurfNoise:get_3d({x=x, y=y, z=z})
|
||||||
|
if value >= 0 then
|
||||||
|
data[index] = ID_TURF_BOG
|
||||||
|
|
||||||
|
local colorIndex = 0
|
||||||
|
if value < 0.1 then
|
||||||
|
colorIndex = 3
|
||||||
|
elseif value < 0.25 then
|
||||||
|
colorIndex = 2
|
||||||
|
else
|
||||||
|
colorIndex = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
data2[index] = mapGenerator:random(x, y, z, 0, 3) + (colorIndex << 2)
|
||||||
|
else
|
||||||
|
data[index] = ID_MUD
|
||||||
|
|
||||||
|
local colorIndex = 0
|
||||||
|
if value > -0.1 then
|
||||||
|
colorIndex = 3
|
||||||
|
elseif value > -0.25 then
|
||||||
|
colorIndex = 2
|
||||||
|
else
|
||||||
|
colorIndex = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
data2[index] = mapGenerator:random(x, y, z, 0, 3) + (colorIndex << 2)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
--[[
|
||||||
|
generateSoil = function (self, mapGenerator, factors, data, data2, index, x, y, z)
|
||||||
|
-- TODO
|
||||||
|
end,
|
||||||
|
|
||||||
|
generateBottom = function (self, mapGenerator, factors, data, data2, index, x, y, z)
|
||||||
|
-- TODO
|
||||||
|
end,
|
||||||
|
--]]
|
||||||
|
|
||||||
|
dataPostProcessing = function (self, mapGenerator, factors, data, data2, index, x, y, z, nodeType, area)
|
||||||
|
if nodeType ~= 'TURF' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if peatBogPlantsNoise == nil then
|
||||||
|
peatBogPlantsNoise = core.get_value_noise(peatBogPlantsNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local grassValue = peatBogPlantsNoise:get_3d({x=x, y=0, z=z}) + mapGenerator:random(x, y, z, 0, 2)
|
||||||
|
|
||||||
|
local i = area:index(x,y+1,z)
|
||||||
|
|
||||||
|
if grassValue > 8 then
|
||||||
|
data[i] = ID_BOG_GRASS_1
|
||||||
|
data2[i] = 8 + placeParam2[mapGenerator:random(x, y, z, 1, #placeParam2)]
|
||||||
|
elseif grassValue > 5 then
|
||||||
|
data[i] = ID_BOG_GRASS_2
|
||||||
|
data2[i] = 8 + placeParam2[mapGenerator:random(x, y, z, 1, #placeParam2)]
|
||||||
|
elseif grassValue > 3 then
|
||||||
|
data[i] = ID_BOG_GRASS_3
|
||||||
|
data2[i] = 8 + placeParam2[mapGenerator:random(x, y, z, 1, #placeParam2)]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
vmPostProcessing = function(self, mapGenerator, factors, voxelManip, x, y, z, nodeType, area)
|
||||||
|
if nodeType ~= 'TURF' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if peatBogPlantsNoise == nil then
|
||||||
|
peatBogPlantsNoise = core.get_value_noise(peatBogPlantsNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local grassValue = peatBogPlantsNoise:get_3d({x=x, y=0, z=z}) + mapGenerator:random(x, y, z, 0, 2)
|
||||||
|
if grassValue <= 3 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local treeValue = mapGenerator:random(x, y, z, 1, 1000)
|
||||||
|
if treeValue >= 990 then
|
||||||
|
local pos = v(x, y-mapGenerator:random(x, y-1, z, 0, 1), z) --[[@as MapVector]]
|
||||||
|
mapGenerator:getTree('allwhere_tree_a'):placeOnVM(voxelManip, pos)
|
||||||
|
elseif treeValue >= 950 then
|
||||||
|
local pos = v(x, y-mapGenerator:random(x, y-1, z, 0, 2), z) --[[@as MapVector]]
|
||||||
|
mapGenerator:getTree('marentine_tree_a'):placeOnVM(voxelManip, pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
mapGenerator:registerTree('allwhere_tree_a', {
|
||||||
|
path = core.get_modpath(core.get_current_modname())..'/schems/allwhere_tree_a.mts',
|
||||||
|
})
|
||||||
|
|
||||||
|
mapGenerator:registerTree('marentine_tree_a', {
|
||||||
|
path = core.get_modpath(core.get_current_modname())..'/schems/marentine_tree_a.mts',
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Debug:
|
||||||
---@type ValueNoise
|
---@type ValueNoise
|
||||||
local rocksNoise
|
local rocksNoise
|
||||||
|
|
||||||
@@ -435,10 +616,10 @@ mapGenerator:registerBiome('videre', 'green_meadow', {
|
|||||||
minY = -50,
|
minY = -50,
|
||||||
maxY = 100,
|
maxY = 100,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = 'soils:humus',
|
soil = 'soils:chernozem',
|
||||||
turf = 'soils:turf_meadow',
|
turf = 'soils:turf_meadow',
|
||||||
rock = 'rocks:basalt',
|
rock = 'rocks:basalt',
|
||||||
bottom = 'soils:humus',
|
bottom = 'soils:chernozem',
|
||||||
},
|
},
|
||||||
soilHeight = 5,
|
soilHeight = 5,
|
||||||
dataPostProcessing = meadowPostProcessing,
|
dataPostProcessing = meadowPostProcessing,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ local function registerRock(name, y, def, staff)
|
|||||||
def = {}
|
def = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local modPrefix = Mod.getInfo().shortName..':'
|
local modPrefix = Mod:getInfo().shortName..':'
|
||||||
local craftGroup = 'rocks_'..name..'_staff'
|
local craftGroup = 'rocks_'..name..'_staff'
|
||||||
|
|
||||||
-- Default rock
|
-- Default rock
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
local modInfo = Mod:getInfo('smc__core__formspec')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type AdminListUI
|
---@type PlayerInventoryUI
|
||||||
local AdminListUI = Mod.getInfo('smc__ui__admin_list').require('AdminListUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
core.register_chatcommand('list', {
|
core.register_chatcommand('list', {
|
||||||
privs = {server = true},
|
privs = {give = true},
|
||||||
|
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player = core.get_player_by_name(name)
|
PlayerInventoryUI:setContex(name, 'left_tab_name', 'admin_list_tab')
|
||||||
|
PlayerInventoryUI:showForm(name)
|
||||||
AdminListUI:showForm(name)
|
|
||||||
|
|
||||||
return true, ''
|
return true, ''
|
||||||
end
|
end
|
||||||
@@ -35,34 +34,6 @@ core.register_chatcommand('set_param2', {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
AdminListUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, fieldName, fieldValue)
|
|
||||||
---@type ItemStackString?
|
|
||||||
local stack = string.match(fieldName, '(%S+)::item_button')
|
|
||||||
|
|
||||||
if stack == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local playerName = player:get_player_name()
|
|
||||||
AdminListUI:setContex(playerName, 'select_item', stack)
|
|
||||||
|
|
||||||
AdminListUI:showForm(playerName)
|
|
||||||
end)
|
|
||||||
|
|
||||||
AdminListUI:registerOnFormFieldAction('admin_commands:list_add_item', function(player, fieldName, fieldValue)
|
|
||||||
---@type InvRef
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
|
|
||||||
local playerName = player:get_player_name()
|
|
||||||
local stack = AdminListUI:getContex(playerName, 'select_item')
|
|
||||||
stack = ItemStack(stack)
|
|
||||||
stack:set_count(fieldValue)
|
|
||||||
|
|
||||||
if inv:room_for_item('main', stack) then
|
|
||||||
inv:add_item('main', stack)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
core.register_on_joinplayer(function(player, last_login)
|
core.register_on_joinplayer(function(player, last_login)
|
||||||
player:set_sky({
|
player:set_sky({
|
||||||
sky_color = {
|
sky_color = {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__game__admin_commands
|
name = smc__game__admin_commands
|
||||||
depends = smc__system__system_loader, smc__ui__admin_list
|
depends = smc__system__system_loader, smc__ui__player_inventory
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ end
|
|||||||
---@generic T:table
|
---@generic T:table
|
||||||
---@param self T Parent class.
|
---@param self T Parent class.
|
||||||
---@param params table Child object parameters.
|
---@param params table Child object parameters.
|
||||||
---@param metatable table? The table that will become the metatable for the object. Note: The `__index` field will be overwritten by a copy of `self`.
|
---@param metatable table? The table that will become the metatable for the object.
|
||||||
|
--- Note: The `__index` field will be overwritten by a copy of `self`.
|
||||||
---@return T
|
---@return T
|
||||||
function Class.getInstance(self, params, metatable)
|
function Class.getInstance(self, params, metatable)
|
||||||
if metatable == nil then
|
if metatable == nil then
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__system__events')
|
local modInfo = Mod:getInfo('smc__system__events')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Events')
|
return require('Events')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__system__helper_lib')
|
local modInfo = Mod:getInfo('smc__system__helper_lib')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
require('Lib')
|
require('Lib')
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__system__helper_lib
|
name = smc__system__helper_lib
|
||||||
depends = smc__system__ensure, smc__system__mod
|
depends = smc__system__ensure, smc__system__mod, smc__system__utf8
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
|
---SMC helper lib
|
||||||
|
---@class Smc
|
||||||
Smc = {}
|
Smc = {}
|
||||||
|
|
||||||
---@type boolean
|
---@type boolean
|
||||||
Smc.isAsync = false
|
Smc.isAsync = false
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__system__helper_lib')
|
local modInfo = Mod:getInfo('smc__system__helper_lib')
|
||||||
local require = modInfo.require
|
local doFile = modInfo.doFile
|
||||||
|
|
||||||
require('Lib.activeFormspecs')
|
-- Independent of SMC methods
|
||||||
require('Lib.globalStep')
|
doFile('Lib.activeFormspecs')
|
||||||
require('Lib.color')
|
doFile('Lib.globalStep')
|
||||||
require('Lib.itemStackInventory')
|
doFile('Lib.inventoryHelpers')
|
||||||
require('Lib.nodeSuperClasses')
|
doFile('Lib.color')
|
||||||
require('Lib.getObjectByGUID')
|
doFile('Lib.itemStackInventory')
|
||||||
require('Lib.receiveFields')
|
doFile('Lib.nodeSuperClasses')
|
||||||
require('Lib.registeredItems')
|
doFile('Lib.getObjectByGUID')
|
||||||
require('Lib.requires')
|
doFile('Lib.receiveFields')
|
||||||
|
doFile('Lib.registeredItems')
|
||||||
|
doFile('Lib.requires')
|
||||||
|
|
||||||
|
--- Dependent of SMC methods
|
||||||
|
doFile('Lib.matchItemDescription')
|
||||||
|
|||||||
23
mods/SYSTEM/HelperLib/src/Lib/inventoryHelpers.lua
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
local ItemStack = ItemStack
|
||||||
|
|
||||||
|
---Adds the specified stack to the player's inventory, provided there is space available.
|
||||||
|
---
|
||||||
|
---If there is no space, it drops the stack on the ground.
|
||||||
|
---
|
||||||
|
---Returns `true` if the stack was placed in the inventory, and `false` if it was dropped.
|
||||||
|
---@param player Player
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param item ItemStack|ItemStackString|ItemStackString
|
||||||
|
---@return boolean
|
||||||
|
function Smc.putOrDrop(player, inventory, item)
|
||||||
|
item = ItemStack(item)
|
||||||
|
if inventory:room_for_item('main', item) then
|
||||||
|
inventory:add_item('main', item)
|
||||||
|
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
core.item_drop(item, player, player:get_pos())
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
70
mods/SYSTEM/HelperLib/src/Lib/matchItemDescription.lua
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
local ipairs = ipairs
|
||||||
|
local tableInsert = table.insert
|
||||||
|
local stringMatch, stringLower = string.match, string_utf8.lower
|
||||||
|
local coreGetTranslatedString = core.get_translated_string
|
||||||
|
|
||||||
|
---Checks whether an item's name and description match a given pattern.
|
||||||
|
---
|
||||||
|
---Use it to create unconventional lists based on text searches.
|
||||||
|
---
|
||||||
|
---
|
||||||
|
---For example:
|
||||||
|
---```lua
|
||||||
|
------A function for determining a list of crafts that match a text-based search query
|
||||||
|
---local function getMathedCrafts(crafts, pattern)
|
||||||
|
--- local pattern = stringLower(pattern)
|
||||||
|
--- local matchedCrafts = {}
|
||||||
|
---
|
||||||
|
--- for _, craft in ipairs(crafts) do
|
||||||
|
--- if Smc.matchItemDescription(ItemStack(craft.output):get_name(), pattern) then
|
||||||
|
--- tableInsert(matchedCrafts, craft)
|
||||||
|
--- end
|
||||||
|
--- end
|
||||||
|
---
|
||||||
|
--- return matchedCrafts
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
---
|
||||||
|
---**Note**: to obtain standard lists of items, use: `Smc.getMathedItems()`
|
||||||
|
---
|
||||||
|
---@param itemName ItemStackString
|
||||||
|
---@return boolean
|
||||||
|
function Smc.matchItemDescription(itemName, pattern)
|
||||||
|
local ItemStack = ItemStack(itemName)
|
||||||
|
|
||||||
|
-- Only items registered via the `Item` wrapper class have an `_title` field.
|
||||||
|
-- Therefore, `short_description` is used as a fallback title.
|
||||||
|
local itemTitle = ItemStack:get_definition()._title or ItemStack:get_short_description() or ''
|
||||||
|
|
||||||
|
local ruName = stringLower(coreGetTranslatedString('ru', itemTitle))
|
||||||
|
local enName = stringLower(coreGetTranslatedString('en', itemTitle))
|
||||||
|
|
||||||
|
if stringMatch(itemName, pattern) or
|
||||||
|
stringMatch(ruName, pattern) or
|
||||||
|
stringMatch(enName, pattern) then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local matchItemDescription = Smc.matchItemDescription
|
||||||
|
|
||||||
|
---Returns a list of items whose name or description matches a pattern.
|
||||||
|
---
|
||||||
|
---Use this method to retrieve lists of items based on a text search.
|
||||||
|
---@param items ItemStackString[]
|
||||||
|
---@param pattern string
|
||||||
|
---@return ItemStackString[]
|
||||||
|
function Smc.getMathedItems(items, pattern)
|
||||||
|
local pattern = stringLower(pattern)
|
||||||
|
local macthedItems = {}
|
||||||
|
|
||||||
|
for _, itemName in ipairs(items) do
|
||||||
|
if matchItemDescription(itemName, pattern) then
|
||||||
|
tableInsert(macthedItems, itemName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return macthedItems
|
||||||
|
end
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
---@return Item
|
---@return Item
|
||||||
function Smc.requireItem()
|
function Smc.requireItem()
|
||||||
---@type Item
|
---@type Item
|
||||||
local class = Mod.getInfo('smc__core__item').require('Item')
|
local class = Mod:getInfo('smc__core__item').require('Item')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -11,7 +11,7 @@ end
|
|||||||
---@return Node
|
---@return Node
|
||||||
function Smc.requireNode()
|
function Smc.requireNode()
|
||||||
---@type Node
|
---@type Node
|
||||||
local class = Mod.getInfo('smc__core__node').require('Node')
|
local class = Mod:getInfo('smc__core__node').require('Node')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -19,7 +19,7 @@ end
|
|||||||
---@return Tool
|
---@return Tool
|
||||||
function Smc.requireTool()
|
function Smc.requireTool()
|
||||||
---@type Tool
|
---@type Tool
|
||||||
local class = Mod.getInfo('smc__core__tool').require('Tool')
|
local class = Mod:getInfo('smc__core__tool').require('Tool')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -27,7 +27,7 @@ end
|
|||||||
---@return Plant
|
---@return Plant
|
||||||
function Smc.requirePlant()
|
function Smc.requirePlant()
|
||||||
---@type Plant
|
---@type Plant
|
||||||
local class = Mod.getInfo('smc__core__plant').require('Plant')
|
local class = Mod:getInfo('smc__core__plant').require('Plant')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -35,7 +35,7 @@ end
|
|||||||
---@return ItemFactory
|
---@return ItemFactory
|
||||||
function Smc.requireItemFactory()
|
function Smc.requireItemFactory()
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
local class = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
local class = Mod:getInfo('smc__core__item_factory').require('ItemFactory')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -43,7 +43,7 @@ end
|
|||||||
---@return TileSheet
|
---@return TileSheet
|
||||||
function Smc.requireTileSheet()
|
function Smc.requireTileSheet()
|
||||||
---@type TileSheet
|
---@type TileSheet
|
||||||
local class = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
local class = Mod:getInfo('smc__core__tilesheet').require('TileSheet')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -51,7 +51,7 @@ end
|
|||||||
---@return BaseUI
|
---@return BaseUI
|
||||||
function Smc.requireBaseUI()
|
function Smc.requireBaseUI()
|
||||||
---@type BaseUI
|
---@type BaseUI
|
||||||
local class = Mod.getInfo('smc__core__base_ui').require('BaseUI')
|
local class = Mod:getInfo('smc__core__base_ui').require('BaseUI')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -59,7 +59,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Smc.requireFormspec()
|
function Smc.requireFormspec()
|
||||||
---@type Formspec
|
---@type Formspec
|
||||||
local class = Mod.getInfo('smc__core__formspec').require('Formspec')
|
local class = Mod:getInfo('smc__core__formspec').require('Formspec')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -67,7 +67,7 @@ end
|
|||||||
---@return ProgressionSystem
|
---@return ProgressionSystem
|
||||||
function Smc.requireProgressionSystem()
|
function Smc.requireProgressionSystem()
|
||||||
---@type ProgressionSystem
|
---@type ProgressionSystem
|
||||||
local class = Mod.getInfo('smc__core__progression_system').require('ProgressionSystem')
|
local class = Mod:getInfo('smc__core__progression_system').require('ProgressionSystem')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -75,7 +75,7 @@ end
|
|||||||
---@return CraftSystem
|
---@return CraftSystem
|
||||||
function Smc.requireCraftSystem()
|
function Smc.requireCraftSystem()
|
||||||
---@type CraftSystem
|
---@type CraftSystem
|
||||||
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem')
|
local class = Mod:getInfo('smc__core__craft_system').require('CraftSystem')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -83,7 +83,7 @@ end
|
|||||||
---@return PlayerInventoryUI
|
---@return PlayerInventoryUI
|
||||||
function Smc.requirePlayerInventoryUI()
|
function Smc.requirePlayerInventoryUI()
|
||||||
---@type PlayerInventoryUI
|
---@type PlayerInventoryUI
|
||||||
local class = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
local class = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -91,7 +91,7 @@ end
|
|||||||
---@return BaseProcessingStation
|
---@return BaseProcessingStation
|
||||||
function Smc.requireBaseProcessingStation()
|
function Smc.requireBaseProcessingStation()
|
||||||
---@type BaseProcessingStation
|
---@type BaseProcessingStation
|
||||||
local class = Mod.getInfo('smc__core__base_processing_station').require('BaseProcessingStation')
|
local class = Mod:getInfo('smc__core__base_processing_station').require('BaseProcessingStation')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -99,7 +99,7 @@ end
|
|||||||
---@return ProcessingContainerStation
|
---@return ProcessingContainerStation
|
||||||
function Smc.requireProcessingContainerStation()
|
function Smc.requireProcessingContainerStation()
|
||||||
---@type ProcessingContainerStation
|
---@type ProcessingContainerStation
|
||||||
local class = Mod.getInfo('smc__core__processing_container_station').require('ProcessingContainerStation')
|
local class = Mod:getInfo('smc__core__processing_container_station').require('ProcessingContainerStation')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -107,7 +107,7 @@ end
|
|||||||
---@return ProcessingFuelStation
|
---@return ProcessingFuelStation
|
||||||
function Smc.requireProcessingFuelStation()
|
function Smc.requireProcessingFuelStation()
|
||||||
---@type ProcessingFuelStation
|
---@type ProcessingFuelStation
|
||||||
local class = Mod.getInfo('smc__core__processing_fuel_station').require('ProcessingFuelStation')
|
local class = Mod:getInfo('smc__core__processing_fuel_station').require('ProcessingFuelStation')
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
@@ -116,7 +116,7 @@ end
|
|||||||
---@return Events
|
---@return Events
|
||||||
function Smc.requireEvents(eventsType)
|
function Smc.requireEvents(eventsType)
|
||||||
---@type Events
|
---@type Events
|
||||||
local class = Mod.getInfo('smc__system__events').require('Events.'..eventsType)
|
local class = Mod:getInfo('smc__system__events').require('Events.'..eventsType)
|
||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
---Luanti mod
|
---Luanti mod
|
||||||
---@class Mod
|
---@class Mod
|
||||||
---@field name string Technical name of the mod.
|
|
||||||
---@field shortName string
|
|
||||||
---@field path string Path to the mod folder.
|
|
||||||
---@field Class any A public class that provides a mod.
|
|
||||||
---@field require fun(FileName:string):table
|
|
||||||
Mod = {}
|
Mod = {}
|
||||||
|
|
||||||
|
---@class Mod.Info
|
||||||
|
---@field name string
|
||||||
|
---@field shortName string
|
||||||
|
---@field path string
|
||||||
|
---@field require fun(fileName:string):table
|
||||||
|
---@field loadFile fun(class:table, fileName:string)
|
||||||
|
---@field doFile fun(fileName:string)
|
||||||
|
|
||||||
---Returns the mod name without prefixes
|
---Returns the mod name without prefixes
|
||||||
---@param name string
|
---@param name string
|
||||||
---@return string
|
---@return string
|
||||||
@@ -18,21 +21,32 @@ end
|
|||||||
|
|
||||||
---Return table with mod name, path and require function.
|
---Return table with mod name, path and require function.
|
||||||
---@param modname? string Specify a name of mod to get its info
|
---@param modname? string Specify a name of mod to get its info
|
||||||
---@return {name: string, shortName: string, path: string, require: fun(FileName : string): table}
|
---@return Mod.Info
|
||||||
function Mod.getInfo(modname)
|
function Mod:getInfo(modname)
|
||||||
local name = modname or core.get_current_modname()
|
local name = modname or core.get_current_modname()
|
||||||
local shortName = getShortModName(name)
|
local shortName = getShortModName(name)
|
||||||
local path = core.get_modpath(name)
|
local path = core.get_modpath(name)
|
||||||
assert(path ~= nil, ('A mod `%s` does not exist.'):format(name))
|
assert(path ~= nil, ('A mod `%s` does not exist.'):format(name))
|
||||||
local require = Require.getModRequire(name, path)
|
local require = Require:getModRequire(name, path)
|
||||||
|
local loadFile = Require:getModLoadFile(name, path)
|
||||||
|
local doFile = Require:getModDoFile(path)
|
||||||
|
|
||||||
return {name = name, shortName = shortName, path = path, require = require}
|
local info = {
|
||||||
|
name = name,
|
||||||
|
shortName = shortName,
|
||||||
|
path = path,
|
||||||
|
require = require,
|
||||||
|
loadFile = loadFile,
|
||||||
|
doFile = doFile
|
||||||
|
}
|
||||||
|
|
||||||
|
return info
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
function Mod:new()
|
function Mod:new()
|
||||||
---@type Mod
|
---@type Mod
|
||||||
local instance = setmetatable(Mod.getInfo(), { __index = self })
|
local instance = setmetatable(Mod:getInfo(), { __index = self })
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,26 +2,36 @@ Require = {}
|
|||||||
local loadedModules = {}
|
local loadedModules = {}
|
||||||
local DS = '/'
|
local DS = '/'
|
||||||
|
|
||||||
--- Creates a scoped require function for a specific module
|
---A helper function that returns the path to a file.
|
||||||
--- This custom require handles module loading relative to a specific module path,
|
---@param modPath string
|
||||||
--- prevents duplicate loading, and caches results appropriately.
|
---@param fileName string
|
||||||
--- @param modName string Namespace identifier for the module (prevents global collisions)
|
---@return string
|
||||||
--- @param modPath string Absolute base path to the module's directory
|
function Require:getFilePath(modPath, fileName)
|
||||||
--- @return function require Custom require function scoped to the specified module
|
return modPath..DS..'src'..DS..fileName:gsub('%.', DS)..'.lua'
|
||||||
function Require.getModRequire(modName, modPath)
|
end
|
||||||
--- Custom require function for module-specific loading
|
|
||||||
--- Resolves files relative to modPath/src, converts dot-notation to path separators
|
---Creates a scoped require function for a specific module.
|
||||||
--- @param fileName string Module path in dot-notation (e.g. "lib.utils")
|
---
|
||||||
--- @return any loadedModule The loaded module's return value or cached result
|
---This custom require handles module loading relative to a specific module path,
|
||||||
|
---prevents duplicate loading, and caches results appropriately.
|
||||||
|
---@param modName string Namespace identifier for the module (prevents global collisions)
|
||||||
|
---@param modPath string Absolute base path to the module's directory
|
||||||
|
---@return function require Custom require function scoped to the specified module
|
||||||
|
function Require:getModRequire(modName, modPath)
|
||||||
|
---Custom require function for module-specific loading.
|
||||||
|
---
|
||||||
|
---Resolves files relative to modPath/src, converts dot-notation to path separators.
|
||||||
|
---@param fileName string Module path in dot-notation (e.g. "lib.utils")
|
||||||
|
---@return table loadedModule The loaded module's return value or cached result
|
||||||
local function require(fileName)
|
local function require(fileName)
|
||||||
local fullName = modName .. '..' .. fileName
|
local fullName = modName..'..'..fileName
|
||||||
|
|
||||||
local module = loadedModules[fullName]
|
local module = loadedModules[fullName]
|
||||||
if module ~= nil then
|
if module ~= nil then
|
||||||
return module
|
return module
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = dofile(modPath .. DS .. 'src' .. DS .. fileName:gsub('%.', DS) .. '.lua')
|
local result = dofile(self:getFilePath(modPath, fileName))
|
||||||
|
|
||||||
if result ~= nil then
|
if result ~= nil then
|
||||||
loadedModules[fullName] = result
|
loadedModules[fullName] = result
|
||||||
@@ -35,4 +45,57 @@ function Require.getModRequire(modName, modPath)
|
|||||||
return require
|
return require
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Creates a load function bound to a specific module.
|
||||||
|
---
|
||||||
|
---This specialized load function ensures that scripts are executed with the specified class passed to them,
|
||||||
|
---and prevents scripts from being executed more than once by throwing an error.
|
||||||
|
---@param modName string Namespace identifier for the module (prevents global collisions)
|
||||||
|
---@param modPath string Absolute base path to the module's directory
|
||||||
|
---@return function load Custom load function scoped to the specified module
|
||||||
|
function Require:getModLoadFile(modName, modPath)
|
||||||
|
---Custom load function for loading modules.
|
||||||
|
---
|
||||||
|
---Resolves file paths relative to modPath/src and converts dot notation into path separators.
|
||||||
|
---@param class table A class within the scope of which a script is to be executed
|
||||||
|
---@param fileName string Module path in dot-notation (e.g. "lib.utils")
|
||||||
|
local function loadFile(class, fileName)
|
||||||
|
local fullName = modName..'..'..fileName
|
||||||
|
|
||||||
|
if loadedModules[fullName] ~= nil then
|
||||||
|
error(('Repeated execute of script `%s` is not allowed.'):format(modPath))
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = loadfile(self:getFilePath(modPath, fileName))
|
||||||
|
if result == nil then
|
||||||
|
error()
|
||||||
|
end
|
||||||
|
|
||||||
|
result(class)
|
||||||
|
|
||||||
|
loadedModules[fullName] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return loadFile
|
||||||
|
end
|
||||||
|
|
||||||
|
---Creates dofile function for loading files.
|
||||||
|
---
|
||||||
|
---This loading function will execute a standard `dofile` for the specified script.
|
||||||
|
---@param modPath string Absolute base path to the module's directory
|
||||||
|
---@return function doFile Custom dofile function scoped to the specified file
|
||||||
|
function Require:getModDoFile(modPath)
|
||||||
|
---Custom `dofile` function for loading files.
|
||||||
|
---
|
||||||
|
---Resolves file paths relative to modPath/src and converts dot notation into path separators.
|
||||||
|
---@param fileName string File path in dot-notation (e.g. "lib.utils")
|
||||||
|
---@return any?
|
||||||
|
local function doFile(fileName)
|
||||||
|
local result = dofile(self:getFilePath(modPath, fileName))
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
return doFile
|
||||||
|
end
|
||||||
|
|
||||||
return Require
|
return Require
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
local modInfo = Mod.getInfo('smc__ui__admin_list')
|
|
||||||
local require = modInfo.require
|
|
||||||
|
|
||||||
return require('AdminListUI')
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
name = smc__ui__admin_list
|
|
||||||
depends = smc__core__formspec
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
|
||||||
|
|
||||||
---@param self BaseUI
|
|
||||||
---@param playerName string
|
|
||||||
---@param isSelect boolean?
|
|
||||||
---@return string
|
|
||||||
local function getFormSpecString(self, playerName, isSelect)
|
|
||||||
if isSelect == nil and self:getContex(playerName, 'select_item') ~= nil then
|
|
||||||
isSelect = true
|
|
||||||
else
|
|
||||||
isSelect = false
|
|
||||||
end
|
|
||||||
|
|
||||||
local items = {}
|
|
||||||
|
|
||||||
for name, def in pairs(core.registered_items) do
|
|
||||||
if def.groups and not def.groups.not_in_creative_inventory then
|
|
||||||
table.insert(items, name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
table.sort(items)
|
|
||||||
|
|
||||||
local listFormItems = Formspec:new()
|
|
||||||
|
|
||||||
local w, h = 0, 0
|
|
||||||
---@param name string
|
|
||||||
for _, name in ipairs(items) do
|
|
||||||
listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button')
|
|
||||||
|
|
||||||
w = w + 1
|
|
||||||
|
|
||||||
if w >= 9 then
|
|
||||||
w = 0
|
|
||||||
h = h + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local listForm = Formspec:new({
|
|
||||||
size = {x=21, y=12},
|
|
||||||
})
|
|
||||||
|
|
||||||
listForm
|
|
||||||
:list('current_player', 'main', 10.5, 6.5, 8, 4)
|
|
||||||
:scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical')
|
|
||||||
:scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items', self:getContex(playerName, 'scroll'))
|
|
||||||
|
|
||||||
if isSelect then
|
|
||||||
---@type ItemStackString
|
|
||||||
local item = self:getContex(playerName, 'select_item')
|
|
||||||
local itemSettings = Smc.getItemDefinition(item).settings
|
|
||||||
listForm
|
|
||||||
:itemImage(11, 0.5, 2, 2, item)
|
|
||||||
:areaLabel(11, 4.5, 4, 1, 'Add to inventory:')
|
|
||||||
:button(11, 5, 3, 1, 'admin_commands:list_add_item', '1')
|
|
||||||
:button(14, 5,3, 1, 'admin_commands:list_add_item', ''..tostring(itemSettings.stack_max))
|
|
||||||
:areaLabel(14.5, 0.5, 6, 4,
|
|
||||||
item..'\n\n'..
|
|
||||||
(itemSettings._title or itemSettings.description)..'\n'..
|
|
||||||
(itemSettings._description or ''))
|
|
||||||
end
|
|
||||||
|
|
||||||
return listForm:toString()
|
|
||||||
end
|
|
||||||
|
|
||||||
---@class AdminListUI : BaseUI
|
|
||||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean?):string
|
|
||||||
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean?):string
|
|
||||||
local AdminListUI = BaseUI:new('admin_commands:list_form', getFormSpecString, false)
|
|
||||||
|
|
||||||
AdminListUI:registerOnFormFieldAction('admin_commands:list_items', function(player, fieldName, fieldValue)
|
|
||||||
local scrollValue = string.match(fieldValue, 'CHG:(%S+)')
|
|
||||||
if scrollValue then
|
|
||||||
AdminListUI:setContex(player, 'scroll', scrollValue)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return AdminListUI
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__ui__player_inventory')
|
local modInfo = Mod:getInfo('smc__ui__player_inventory')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('PlayerInventoryUI')
|
return require('PlayerInventoryUI')
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = ...
|
||||||
|
|
||||||
|
local assert = assert
|
||||||
|
local tonumber = tonumber
|
||||||
|
local stringMatch = string.match
|
||||||
|
|
||||||
|
local coreCheckPlayerPrivs = core.check_player_privs
|
||||||
|
local coreChatSendPlayer = core.chat_send_player
|
||||||
|
|
||||||
|
local SmcPutOrDrop = Smc.putOrDrop
|
||||||
|
|
||||||
|
local ItemStack = ItemStack
|
||||||
|
|
||||||
|
-- Handling the addition of an item from the admin list.
|
||||||
|
-- If the player does not have the 'give' privilege, nothing will happen.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::add_item::%S+', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, count = stringMatch(fieldName, '(%S+)::add_item::(%S+)')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
count = tonumber(count)
|
||||||
|
assert(count ~= nil)
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if not coreCheckPlayerPrivs(playerName, 'give') then
|
||||||
|
coreChatSendPlayer(
|
||||||
|
player:get_player_name(),
|
||||||
|
'Your attempt to retrieve the item has been reported to the administrators.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local craftListTabData = PlayerInventoryUI:getAdminListTabData(playerName, tabType)
|
||||||
|
local stack = ItemStack(craftListTabData.selectedItem)
|
||||||
|
stack:set_count(count)
|
||||||
|
|
||||||
|
---@type InvRef
|
||||||
|
local inventory = player:get_inventory()
|
||||||
|
|
||||||
|
SmcPutOrDrop(player, inventory, stack)
|
||||||
|
end)
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = ...
|
||||||
|
|
||||||
|
local ipairs = ipairs
|
||||||
|
local assert = assert
|
||||||
|
local tonumber = tonumber
|
||||||
|
local stringMatch = string.match
|
||||||
|
|
||||||
|
local SmcPutOrDrop = Smc.putOrDrop
|
||||||
|
|
||||||
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
|
-- Handlings the click of the button to move back in the list of alternative recipes.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::alt_recipe_[%a]+', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName, pageFlip = stringMatch(fieldName, '(%S+)::(%S+)::alt_recipe_([%a]+)')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab')
|
||||||
|
assert(pageFlip == 'back' or pageFlip == 'forward')
|
||||||
|
|
||||||
|
---A factor that determines whether the page moves backward or forward
|
||||||
|
---@type integer
|
||||||
|
local pageFactor
|
||||||
|
if pageFlip == 'back' then
|
||||||
|
pageFactor = -1
|
||||||
|
else
|
||||||
|
pageFactor = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
local craftListTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
local recipeIndex = craftListTabData.selectedRecipeIndex or 1
|
||||||
|
recipeIndex = recipeIndex + pageFactor
|
||||||
|
|
||||||
|
local handler = craftListTabData.handler
|
||||||
|
local craft = handler:getCraftByName(craftListTabData.selectedCraft)
|
||||||
|
local crafts = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
||||||
|
assert(crafts ~= nil)
|
||||||
|
|
||||||
|
if recipeIndex < 1 then
|
||||||
|
recipeIndex = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if recipeIndex > #crafts then
|
||||||
|
recipeIndex = #crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
craftListTabData.selectedRecipeIndex = recipeIndex
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Handling the click to craft an item.
|
||||||
|
-- If the player has crafting materials,
|
||||||
|
-- they are removed and the crafted item is added to the inventory.
|
||||||
|
--
|
||||||
|
-- Note: Materials are only searched in the player's main inventory.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item::%S+', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName, count = stringMatch(fieldName, '(%S+)::(%S+)::craft_item::(%S+)')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab')
|
||||||
|
count = tonumber(count)
|
||||||
|
assert(count ~= nil)
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
-- We get the recipe selected in the crafting menu.
|
||||||
|
local craftListTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
local handler = craftListTabData.handler
|
||||||
|
local craftName = craftListTabData.selectedCraft
|
||||||
|
assert(craftName ~= nil)
|
||||||
|
local recipeIndex = craftListTabData.selectedRecipeIndex
|
||||||
|
assert(recipeIndex ~= nil)
|
||||||
|
local craft = handler:getCraftByName(craftName)
|
||||||
|
|
||||||
|
local allowCrafting, materialStacks = CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
|
||||||
|
if allowCrafting and handler.baseType == 'primitive' then
|
||||||
|
---@type CraftSystem.PrimitiveCraft
|
||||||
|
craft = craft
|
||||||
|
local inventory = player:get_inventory()
|
||||||
|
|
||||||
|
for _, item in ipairs(materialStacks) do
|
||||||
|
inventory:remove_item('main', item)
|
||||||
|
end
|
||||||
|
|
||||||
|
SmcPutOrDrop(player, inventory, craft.output)
|
||||||
|
elseif allowCrafting and tabName == 'node_tab' and handler.baseType == 'immersive' then
|
||||||
|
---@type CraftSystem.ImmersiveCraft
|
||||||
|
craft = craft
|
||||||
|
local inventory = player:get_inventory()
|
||||||
|
local nodePos = PlayerInventoryUI:getContex(playerName, 'node_tab_pos')
|
||||||
|
|
||||||
|
local isCraftStart = craft:startCraft(nodePos, player, count)
|
||||||
|
if not isCraftStart then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, item in ipairs(materialStacks) do
|
||||||
|
inventory:remove_item('main', item)
|
||||||
|
end
|
||||||
|
|
||||||
|
PlayerInventoryUI:closeForm(playerName)
|
||||||
|
end
|
||||||
|
end)
|
||||||
@@ -0,0 +1,376 @@
|
|||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = ...
|
||||||
|
|
||||||
|
local ipairs = ipairs
|
||||||
|
local assert = assert
|
||||||
|
local stringMatch = string.match
|
||||||
|
|
||||||
|
local coreGetItemGroup = core.get_item_group
|
||||||
|
|
||||||
|
local SmcGetItemDefinition = Smc.getItemDefinition
|
||||||
|
local SmcGetItemInventoryList = Smc.getItemInventoryList
|
||||||
|
local SmcSetItemInventoryList = Smc.setItemInventoryList
|
||||||
|
local SmcGetItemInventoryListSize = Smc.getItemInventoryListSize
|
||||||
|
|
||||||
|
---Automatically places equipment items into their corresponding slots.
|
||||||
|
---@param player Player
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param fromList string
|
||||||
|
---@param fromIndex integer
|
||||||
|
local function equipListring(player, inventory, fromList, fromIndex)
|
||||||
|
local itemStack = inventory:get_stack(fromList, fromIndex)
|
||||||
|
assert(itemStack ~= nil)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
-- We check whether the item has a group that matches the equipment slot.
|
||||||
|
-- If so, we move the item to the slot.
|
||||||
|
--
|
||||||
|
-- We also check if the target slot is empty.
|
||||||
|
-- If it's already occupied, we prevent items from being moved.
|
||||||
|
if coreGetItemGroup(itemStack:get_name(), 'equip_head') == 1 then
|
||||||
|
if not inventory:get_stack('equip_head', 1):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_head', 1, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_torso') == 1 then
|
||||||
|
if not inventory:get_stack('equip_torso', 1):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_torso', 1, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_legs') == 1 then
|
||||||
|
if not inventory:get_stack('equip_legs', 1):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_legs', 1, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_feet') == 1 then
|
||||||
|
if not inventory:get_stack('equip_feet', 1):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_feet', 1, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_head') == 2 then
|
||||||
|
if not inventory:get_stack('equip_head', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_head', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_torso') == 2 then
|
||||||
|
if not inventory:get_stack('equip_torso', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_torso', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_legs') == 2 then
|
||||||
|
if not inventory:get_stack('equip_legs', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_legs', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif coreGetItemGroup(itemStack:get_name(), 'equip_feet') == 2 then
|
||||||
|
if not inventory:get_stack('equip_feet', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_feet', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
else
|
||||||
|
-- If an item does not have any equipment groups,
|
||||||
|
-- then we prohibit its movement (the item remains in its original location)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We only allow items to be placed in equipment slot
|
||||||
|
-- that have groups that match the slot name and index.
|
||||||
|
core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||||
|
if action == 'move' then
|
||||||
|
-- If the move occurs in a special slot, then we add the item to the desired slot.
|
||||||
|
-- This is necessary to bypass the standard listring[] limitation.
|
||||||
|
-- Equipment items will automatically place themselves in their slots
|
||||||
|
-- when you hold down the shift key.
|
||||||
|
if inventoryInfo.to_list == 'listring_equip' then
|
||||||
|
return equipListring(player --[[@as Player]], inventory, inventoryInfo.from_list, inventoryInfo.from_index)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checking if a slot is an equipment slot.
|
||||||
|
local equipGroup = stringMatch(inventoryInfo.to_list, 'equip_%S+')
|
||||||
|
if equipGroup == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We receive the item that the player wants to place in the equipment slot.
|
||||||
|
local itemStack = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index)
|
||||||
|
assert(itemStack ~= nil)
|
||||||
|
|
||||||
|
if coreGetItemGroup(itemStack:get_name(), equipGroup) == inventoryInfo.to_index then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
elseif action == 'put' then
|
||||||
|
-- Checking if a slot is an equipment slot.
|
||||||
|
local equipGroup = stringMatch(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
if equipGroup == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We receive the item that the player wants to place in the equipment slot.
|
||||||
|
local itemStack = inventoryInfo.stack
|
||||||
|
|
||||||
|
if coreGetItemGroup(itemStack:get_name(), equipGroup) == inventoryInfo.index then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
---Checks if the inventory list is an inventory list of bags.
|
||||||
|
---@param listName string
|
||||||
|
---@return boolean
|
||||||
|
local function isBagInventoryList(listName)
|
||||||
|
if listName == 'inventory_back' or
|
||||||
|
listName == 'inventory_left_thigh' or
|
||||||
|
listName == 'inventory_right_thigh' then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns the copy ItemStack of the bag whose inventory is
|
||||||
|
---expanded in the specified inventory list.
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param listName string
|
||||||
|
---@return ItemStack
|
||||||
|
local function getBagSlotListName(inventory, listName)
|
||||||
|
local bagSlotName = stringMatch(listName, 'inventory_(%S+)')
|
||||||
|
assert(bagSlotName ~= nil)
|
||||||
|
|
||||||
|
local bagItem = inventory:get_stack('equip_'..bagSlotName, 1)
|
||||||
|
assert(not bagItem:is_empty())
|
||||||
|
|
||||||
|
return bagItem
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We check whether an item contains allow or disallow item groups
|
||||||
|
-- to ensure that only allow items are placed in bags.
|
||||||
|
core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||||
|
if action == 'move' and isBagInventoryList(inventoryInfo.to_list) then
|
||||||
|
local bagItem = getBagSlotListName(inventory, inventoryInfo.to_list)
|
||||||
|
local movableItemName = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index):get_name()
|
||||||
|
|
||||||
|
local bagSetting = SmcGetItemDefinition(bagItem).settings
|
||||||
|
local allowedGroups = bagSetting._itemstack_inventory_allowed_groups
|
||||||
|
local disallowedGroups = bagSetting._itemstack_inventory_disallowed_groups
|
||||||
|
|
||||||
|
if allowedGroups ~= nil then
|
||||||
|
for _, group in ipairs(allowedGroups) do
|
||||||
|
if coreGetItemGroup(movableItemName, group) > 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if disallowedGroups ~= nil then
|
||||||
|
for _, group in ipairs(disallowedGroups) do
|
||||||
|
if coreGetItemGroup(movableItemName, group) > 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif action == 'put' and isBagInventoryList(inventoryInfo.listname) then
|
||||||
|
local bagItem = getBagSlotListName(inventory, inventoryInfo.listname)
|
||||||
|
local movableItemName = inventoryInfo.stack
|
||||||
|
|
||||||
|
local bagSetting = SmcGetItemDefinition(bagItem).settings
|
||||||
|
local allowedGroups = bagSetting._itemstack_inventory_allowed_groups
|
||||||
|
local disallowedGroups = bagSetting._itemstack_inventory_disallowed_groups
|
||||||
|
|
||||||
|
if allowedGroups ~= nil then
|
||||||
|
for _, group in ipairs(allowedGroups) do
|
||||||
|
if coreGetItemGroup(movableItemName, group) > 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if disallowedGroups ~= nil then
|
||||||
|
for _, group in ipairs(disallowedGroups) do
|
||||||
|
if coreGetItemGroup(movableItemName, group) > 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
---Returns the name of the inventory list that will contain the items in the bag.
|
||||||
|
---@param equipList string
|
||||||
|
---@return string
|
||||||
|
local function getBagInventoryListName(equipList)
|
||||||
|
local bagInventoryList = stringMatch(equipList, 'equip_(%S+)')
|
||||||
|
assert(bagInventoryList ~= nil)
|
||||||
|
|
||||||
|
return 'inventory_'..bagInventoryList
|
||||||
|
end
|
||||||
|
|
||||||
|
---Creates a corresponding inventory list by getting it from the item's metadata.
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param equipList string
|
||||||
|
---@param bagItem ItemStack
|
||||||
|
local function onBagEquipped(inventory, equipList, bagItem)
|
||||||
|
local bagInventoryListName = getBagInventoryListName(equipList)
|
||||||
|
local bagInventoryList = SmcGetItemInventoryList(bagItem) or {}
|
||||||
|
|
||||||
|
inventory:set_size(bagInventoryListName, SmcGetItemInventoryListSize(bagItem))
|
||||||
|
inventory:set_list(bagInventoryListName, bagInventoryList)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Saves the inventory list corresponding to the equipped bag to the item's metadata.
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param equipList string
|
||||||
|
---@param bagItem ItemStack
|
||||||
|
local function onBagUnequipped(inventory, equipList, bagItem)
|
||||||
|
local bagInventoryListName = getBagInventoryListName(equipList)
|
||||||
|
local bagInventoryList = inventory:get_list(bagInventoryListName)
|
||||||
|
|
||||||
|
SmcSetItemInventoryList(bagItem, bagInventoryList)
|
||||||
|
|
||||||
|
inventory:set_size(bagInventoryListName, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Checks if a slot is a bag slot by matching the inventory list name.
|
||||||
|
---@param equipGroup string
|
||||||
|
---@return boolean
|
||||||
|
local function isBagSlot(equipGroup)
|
||||||
|
if equipGroup == 'equip_back' or
|
||||||
|
equipGroup == 'equip_left_thigh' or
|
||||||
|
equipGroup == 'equip_right_thigh' then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Handling the movement of bags slots in the player's inventory.
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param inventoryInfo table
|
||||||
|
local function onBagSlotMove(inventory, inventoryInfo)
|
||||||
|
-- We get the copy items currently at the destination and source positions.
|
||||||
|
local newItem = inventory:get_stack(inventoryInfo.to_list, inventoryInfo.to_index)
|
||||||
|
local oldItem = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index)
|
||||||
|
|
||||||
|
-- Handling the case where both slots are bag slots.
|
||||||
|
if isBagSlot(inventoryInfo.to_list) and isBagSlot(inventoryInfo.from_list) then
|
||||||
|
-- If the target slot is empty (we put a bag from one slot to another),
|
||||||
|
-- then we unequip the bag and equip it again
|
||||||
|
if oldItem:is_empty() then
|
||||||
|
onBagUnequipped(inventory, inventoryInfo.from_list, newItem)
|
||||||
|
onBagEquipped(inventory, inventoryInfo.to_list, newItem)
|
||||||
|
-- If a slot is occupied, we swap bags.
|
||||||
|
-- We unequip them, then equip them in their correct slots.
|
||||||
|
else
|
||||||
|
onBagUnequipped(inventory, inventoryInfo.to_list, oldItem)
|
||||||
|
onBagUnequipped(inventory, inventoryInfo.from_list, newItem)
|
||||||
|
onBagEquipped(inventory, inventoryInfo.from_list, oldItem)
|
||||||
|
onBagEquipped(inventory, inventoryInfo.to_list, newItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handling the case where only the target slot is a bag slot
|
||||||
|
-- (equipping a bag from other inventory slots).
|
||||||
|
elseif isBagSlot(inventoryInfo.to_list) and not isBagSlot(inventoryInfo.from_list) then
|
||||||
|
-- If the target slot is empty (we put a bag from one slot to another),
|
||||||
|
-- then we just equip the bag.
|
||||||
|
if oldItem:is_empty() then
|
||||||
|
onBagEquipped(inventory, inventoryInfo.to_list, newItem)
|
||||||
|
-- Else we swap the bags.
|
||||||
|
-- We unequip the old bag and equip the new one.
|
||||||
|
else
|
||||||
|
onBagUnequipped(inventory, inventoryInfo.to_list, oldItem)
|
||||||
|
onBagEquipped(inventory, inventoryInfo.to_list, newItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handling the case where a bag is moved from a bag slot to a non-bag slot.
|
||||||
|
elseif not isBagSlot(inventoryInfo.to_list) and isBagSlot(inventoryInfo.from_list) then
|
||||||
|
-- If the target slot is empty,
|
||||||
|
-- then we just unequip the bag.
|
||||||
|
if oldItem:is_empty() then
|
||||||
|
onBagUnequipped(inventory, inventoryInfo.from_list, newItem)
|
||||||
|
end
|
||||||
|
-- The case where the slot is occupied should not be handling here.
|
||||||
|
-- It is handling in the previous else-if block.
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We are updating the item stacks in the inventory,
|
||||||
|
-- since we were previously working with copies
|
||||||
|
-- (we need to save the items with new metadata).
|
||||||
|
inventory:set_stack(inventoryInfo.to_list, inventoryInfo.to_index, newItem)
|
||||||
|
inventory:set_stack(inventoryInfo.from_list, inventoryInfo.from_index, oldItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: скорее всего будет проблема со сваппингом сумок из сундуков
|
||||||
|
-- Возможно стоит запретить свапать сумки
|
||||||
|
|
||||||
|
-- Update the interface if the player has moved something from the equipment slots
|
||||||
|
-- (this enables and disables the slot overlay).
|
||||||
|
core.register_on_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if action == 'move' then
|
||||||
|
local equipGroup = stringMatch(inventoryInfo.to_list, 'equip_%S+') or
|
||||||
|
stringMatch(inventoryInfo.from_list, 'equip_%S+')
|
||||||
|
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
onBagSlotMove(inventory, inventoryInfo)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
elseif action == 'put' then
|
||||||
|
local equipGroup = stringMatch(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
elseif action == 'take' then
|
||||||
|
local equipGroup = stringMatch(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = ...
|
||||||
|
|
||||||
|
local assert = assert
|
||||||
|
local stringMatch = string.match
|
||||||
|
|
||||||
|
-- Handling the press of the inventory mode change button.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldAction('change_compact_mode', function(player, fieldName, fieldValue)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
local compactMode = PlayerInventoryUI:getContex(playerName, 'compact_mode')
|
||||||
|
|
||||||
|
-- By default, the player will be shown a compact form.
|
||||||
|
if compactMode == nil then
|
||||||
|
compactMode = true
|
||||||
|
end
|
||||||
|
|
||||||
|
PlayerInventoryUI:setContex(playerName, 'compact_mode', (not compactMode))
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Handling the inventory tab selection button press.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('select_[%a]+_%S+', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName = stringMatch(fieldName, 'select_([%a]+)_(%S+)')
|
||||||
|
assert(tabType == 'right' or tabType == 'left')
|
||||||
|
assert(tabName ~= nil)
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
PlayerInventoryUI:setContex(playerName, tabType..'_tab_name', tabName)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = ...
|
||||||
|
|
||||||
|
local assert = assert
|
||||||
|
local stringMatch = string.match
|
||||||
|
|
||||||
|
-- Handling input in the items list search bar.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::items_list_search_field', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName = stringMatch(fieldName, '(%S+)::(%S+)::items_list_search_field')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab' or tabName == 'admin_list_tab')
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
---@type PlayerInventoryUI.CraftListTabData|PlayerInventoryUI.AdminListTabData
|
||||||
|
local tabData
|
||||||
|
if tabName == 'craft_tab' or tabName == 'node_tab' then
|
||||||
|
tabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
elseif tabName == 'admin_list_tab' then
|
||||||
|
tabData = PlayerInventoryUI:getAdminListTabData(playerName, tabType)
|
||||||
|
else
|
||||||
|
error('Invalid tabName: '..tabName)
|
||||||
|
end
|
||||||
|
|
||||||
|
if tabData.searchFieldValue == fieldValue then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
tabData.searchFieldValue = fieldValue
|
||||||
|
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Handling the button press for flipping through the pages of an item list.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::items_list_page_[%a]+', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName, pageFlip = stringMatch(fieldName, '(%S+)::(%S+)::items_list_page_([%a]+)')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab' or tabName == 'admin_list_tab')
|
||||||
|
assert(pageFlip == 'back' or pageFlip == 'forward')
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
---A factor that determines whether the page moves backward or forward
|
||||||
|
---@type integer
|
||||||
|
local pageFactor
|
||||||
|
if pageFlip == 'back' then
|
||||||
|
pageFactor = -1
|
||||||
|
else
|
||||||
|
pageFactor = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type PlayerInventoryUI.CraftListTabData|PlayerInventoryUI.AdminListTabData
|
||||||
|
local tabData
|
||||||
|
if tabName == 'craft_tab' or tabName == 'node_tab' then
|
||||||
|
tabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
elseif tabName == 'admin_list_tab' then
|
||||||
|
tabData = PlayerInventoryUI:getAdminListTabData(playerName, tabType)
|
||||||
|
else
|
||||||
|
error('Invalid tabName: '..tabName)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pageNumber = tabData.pageNumber or 1
|
||||||
|
pageNumber = pageNumber + pageFactor
|
||||||
|
if pageNumber <= 0 then
|
||||||
|
pageNumber = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
tabData.pageNumber = pageNumber
|
||||||
|
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Processing closing of the selected item group in the crafting menu (returning to the main list of crafts).
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::close_group', function(player, fieldName, fieldValue)
|
||||||
|
local tabType, tabName = stringMatch(fieldName, '(%S+)::(%S+)::close_group')
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab')
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
local craftListTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
craftListTabData.selectedGroup = nil
|
||||||
|
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Handling the button click for selecting an item for crafting.
|
||||||
|
-- Opens the item description and allows you to craft the selected item.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('.+::%S+::%S+::items_list_button', function(player, fieldName, fieldValue)
|
||||||
|
local name, tabType, tabName = string.match(fieldName, '(.+)::(%S+)::(%S+)::items_list_button')
|
||||||
|
assert(name ~= nil)
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab' or tabName == 'admin_list_tab')
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
if tabName == 'craft_tab' or tabName == 'node_tab' then
|
||||||
|
local craftListTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
|
||||||
|
craftListTabData.selectedRecipeIndex = 1
|
||||||
|
craftListTabData.selectedCraft = name
|
||||||
|
elseif tabName == 'admin_list_tab' then
|
||||||
|
local craftListTabData = PlayerInventoryUI:getAdminListTabData(playerName, tabType)
|
||||||
|
|
||||||
|
craftListTabData.selectedItem = name
|
||||||
|
else
|
||||||
|
error('Invalid tabName: '..tabName)
|
||||||
|
end
|
||||||
|
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Handling the click of the crafting group selection button.
|
||||||
|
-- Causes grouped items to be expanded into a separate list.
|
||||||
|
PlayerInventoryUI:registerOnFormFieldActionMatch('.+::%S+::%S+::group_button',function(player, fieldName, fieldValue)
|
||||||
|
local groupName, tabType, tabName = string.match(fieldName, '(.+)::(%S+)::(%S+)::group_button')
|
||||||
|
assert(groupName ~= nil)
|
||||||
|
assert(tabType == 'left' or tabType == 'right')
|
||||||
|
assert(tabName == 'craft_tab' or tabName == 'node_tab')
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
local craftListTabData = PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName)
|
||||||
|
|
||||||
|
craftListTabData.selectedGroup = groupName
|
||||||
|
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local mathFloor = math.floor
|
local mathFloor = math.floor
|
||||||
|
|
||||||
---Number of crafting recipes on one menu page.
|
---Number of crafting recipes on one menu page.
|
||||||
local PAGE_NUMBER_ITEMS = 20
|
local PAGE_NUMBER_ITEMS = 36
|
||||||
|
|
||||||
local Formspec = Smc.requireFormspec()
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
@@ -24,16 +24,16 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
|||||||
|
|
||||||
local CraftTab = Formspec:new()
|
local CraftTab = Formspec:new()
|
||||||
|
|
||||||
local craftTabData = self:getTabCraftData(playerName, tabType, tabName)
|
local craftListTabData = self:getTabCraftData(playerName, tabType, tabName)
|
||||||
if craftTabData == nil then
|
if craftListTabData == nil then
|
||||||
craftTabData = {handler = handler}
|
craftListTabData = {handler = handler}
|
||||||
self:setTabCraftData(playerName, tabType, tabName, craftTabData)
|
self:setTabCraftData(playerName, tabType, tabName, craftListTabData)
|
||||||
end
|
end
|
||||||
|
|
||||||
local selectedCraft = craftTabData.selected_craft or ''
|
local selectedCraft = craftListTabData.selectedCraft or ''
|
||||||
local selectedGroup = craftTabData.selected_group
|
local selectedGroup = craftListTabData.selectedGroup
|
||||||
local searchFieldValue = craftTabData.search_field_value
|
local searchFieldValue = craftListTabData.searchFieldValue
|
||||||
local pageNumber = craftTabData.page_number or 1
|
local pageNumber = craftListTabData.pageNumber or 1
|
||||||
|
|
||||||
local crafts
|
local crafts
|
||||||
if searchFieldValue ~= '' and searchFieldValue ~= nil then
|
if searchFieldValue ~= '' and searchFieldValue ~= nil then
|
||||||
@@ -59,14 +59,14 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
|||||||
|
|
||||||
if pageNumber > pagesMax then
|
if pageNumber > pagesMax then
|
||||||
pageNumber = pagesMax
|
pageNumber = pagesMax
|
||||||
craftTabData.page_number = pageNumber
|
craftListTabData.pageNumber = pageNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
local w, h = 0.0, 0.0
|
local w, h = 0.0, 0.0
|
||||||
|
|
||||||
if selectedGroup ~= nil and (searchFieldValue == nil or searchFieldValue == '') then
|
if selectedGroup ~= nil and (searchFieldValue == nil or searchFieldValue == '') then
|
||||||
craftsListForm
|
craftsListForm
|
||||||
:imageButton(0, 0, 1.125, 1.125, 'player_inventory_craft_tab_close_group_button_background.png', tabType..'::'..tabName..'::close_group')
|
:imageButton(0, 0, 1.125, 1.125, 'player_inventory_items_list_tab_close_group_button_background.png', tabType..'::'..tabName..'::close_group')
|
||||||
w = 1.125
|
w = 1.125
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -82,10 +82,10 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
|||||||
if output ~= nil then
|
if output ~= nil then
|
||||||
if craft.name == selectedCraft then
|
if craft.name == selectedCraft then
|
||||||
craftsListForm
|
craftsListForm
|
||||||
:imageButton(w, h, 1.125, 1.125, 'player_inventory_craft_tab_button_pressed_background.png', craft.name..'::'..tabType..'::'..tabName..'::item_button')
|
:imageButton(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_button_pressed_background.png', craft.name..'::'..tabType..'::'..tabName..'::items_list_button')
|
||||||
else
|
else
|
||||||
craftsListForm
|
craftsListForm
|
||||||
:imageButton(w, h, 1.125, 1.125, 'player_inventory_craft_tab_button_background.png', craft.name..'::'..tabType..'::'..tabName..'::item_button')
|
:imageButton(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_button_background.png', craft.name..'::'..tabType..'::'..tabName..'::items_list_button')
|
||||||
end
|
end
|
||||||
|
|
||||||
craftsListForm
|
craftsListForm
|
||||||
@@ -95,29 +95,29 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
|||||||
assert(craft ~= nil)
|
assert(craft ~= nil)
|
||||||
|
|
||||||
craftsListForm
|
craftsListForm
|
||||||
:imageButton(w, h, 1.125, 1.125, 'player_inventory_craft_tab_button_background.png', craft.group..'::'..tabType..'::'..tabName..'::group_button')
|
:imageButton(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_button_background.png', craft.group..'::'..tabType..'::'..tabName..'::group_button')
|
||||||
:itemImage(w+0.0625, h+0.0625, 1, 1, craft.output)
|
:itemImage(w+0.0625, h+0.0625, 1, 1, craft.output)
|
||||||
:image(w, h, 1.125, 1.125, 'player_inventory_craft_tab_group_button_overlay.png')
|
:image(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_group_button_overlay.png')
|
||||||
end
|
end
|
||||||
w = w + 1.125
|
w = w + 1.125
|
||||||
|
|
||||||
if w >= 4 then
|
if w >= 6 then
|
||||||
w = 0
|
w = 0
|
||||||
h = h + 1.125
|
h = h + 1.125
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CraftTab
|
CraftTab
|
||||||
:background(0, 0, 14, 9, 'player_inventory_craft_tab_background.png')
|
:background(0, 0, 14, 9, 'player_inventory_items_list_tab_background.png')
|
||||||
:field(0.25, 0.5, 5, 0.75, tabType..'::'..tabName..'::craft_search_field', nil, searchFieldValue)
|
:field(7.75, 0.5, 6, 0.75, tabType..'::'..tabName..'::items_list_search_field', nil, searchFieldValue)
|
||||||
:fieldCloseOnEnter(tabType..'::'..tabName..'::craft_search_field', false)
|
:fieldCloseOnEnter(tabType..'::'..tabName..'::items_search_field', false)
|
||||||
:container(craftsListForm, 0.5, 1.5)
|
:container(craftsListForm, 0.5, 0.5)
|
||||||
:button(1.75, 7.75, 1, 0.5, tabType..'::'..tabName..'::page_back', '<')
|
:button(1.75, 7.75, 1, 0.5, tabType..'::'..tabName..'::items_list_page_back', '<')
|
||||||
:button(2.75, 7.75, 1, 0.5, tabType..'::'..tabName..'::page_forward', '>')
|
:button(2.75, 7.75, 1, 0.5, tabType..'::'..tabName..'::items_list_page_forward', '>')
|
||||||
:label(2.5,8.5, ('%s/%s'):format(pageNumber, pagesMax))
|
:label(2.5,8.5, ('%s/%s'):format(pageNumber, pagesMax))
|
||||||
|
|
||||||
if selectedCraft ~= '' then
|
if selectedCraft ~= '' then
|
||||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
local recipeIndex = craftListTabData.selectedRecipeIndex or 1
|
||||||
local craft = handler:getCraftByName(selectedCraft)
|
local craft = handler:getCraftByName(selectedCraft)
|
||||||
craft = handler:getLearnedCraftsByOutput(playerName, craft.output)[recipeIndex]
|
craft = handler:getLearnedCraftsByOutput(playerName, craft.output)[recipeIndex]
|
||||||
|
|
||||||
@@ -129,16 +129,16 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler)
|
|||||||
local mainList = player:get_inventory():get_list('main')
|
local mainList = player:get_inventory():get_list('main')
|
||||||
|
|
||||||
local craftsByOutput = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
local craftsByOutput = handler:getLearnedCraftsByOutput(playerName, craft.output)
|
||||||
local recipeIndex = craftTabData.selected_recipe_index or 1
|
local recipeIndex = craftListTabData.selectedRecipeIndex or 1
|
||||||
|
|
||||||
CraftTab
|
CraftTab
|
||||||
:itemImage(5.5, 0.5, 2, 2, craft.output)
|
:itemImage(8, 1.5, 2, 2, craft.output)
|
||||||
:label(10, 0.5, ('%s/%s'):format(recipeIndex, #craftsByOutput))
|
:label(13, 1.75, ('%s/%s'):format(recipeIndex, #craftsByOutput))
|
||||||
:textArea(5.5, 3, 5, 4, nil, nil, craft:toString(mainList))
|
:textArea(8, 4, 5, 4, nil, nil, craft:toString(mainList))
|
||||||
:button(5.5, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_back', '<')
|
:button(8.25, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_back', '<')
|
||||||
:button(6, 7.5, 2, 1, tabType..'::'..tabName..'::craft_item', '1')
|
:button(8.75, 7.5, 2, 1, tabType..'::'..tabName..'::craft_item::'..'1', '1')
|
||||||
:button(8, 7.5,2, 1, tabType..'::'..tabName..'::craft_item', ''..tostring(itemDef.stack_max))
|
:button(10.75, 7.5,2, 1, tabType..'::'..tabName..'::craft_item::'..tostring(itemDef.stack_max), tostring(itemDef.stack_max))
|
||||||
:button(10, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_forward', '>')
|
:button(12.75, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_forward', '>')
|
||||||
end
|
end
|
||||||
|
|
||||||
return CraftTab
|
return CraftTab
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
---Number of crafting recipes on one menu page.
|
||||||
|
local PAGE_NUMBER_ITEMS = 36
|
||||||
|
|
||||||
|
---@param self PlayerInventoryUI
|
||||||
|
---@param playerName string
|
||||||
|
---@param tabType PlayerInventoryUI.TabType
|
||||||
|
---@return Formspec
|
||||||
|
local function getAdminListTab(self, playerName, tabType)
|
||||||
|
if tabType ~= 'left' and tabType ~= 'right' then
|
||||||
|
error('Incorrect argument `tabType`: '..tabType)
|
||||||
|
end
|
||||||
|
|
||||||
|
local AdminListTab = Formspec:new()
|
||||||
|
|
||||||
|
local listTabData = self:getAdminListTabData(playerName, tabType)
|
||||||
|
if listTabData == nil then
|
||||||
|
listTabData = {}
|
||||||
|
self:setAdminListTabData(playerName, tabType, listTabData)
|
||||||
|
end
|
||||||
|
|
||||||
|
local selectedItem = listTabData.selectedItem or ''
|
||||||
|
local searchFieldValue = listTabData.searchFieldValue
|
||||||
|
local pageNumber = listTabData.pageNumber or 1
|
||||||
|
|
||||||
|
---@type string[]
|
||||||
|
local items = {}
|
||||||
|
|
||||||
|
for name, def in pairs(core.registered_items) do
|
||||||
|
if def.groups and not def.groups.not_in_creative_inventory then
|
||||||
|
table.insert(items, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(items)
|
||||||
|
|
||||||
|
if searchFieldValue ~= nil and searchFieldValue ~= '' then
|
||||||
|
items = Smc.getMathedItems(items, searchFieldValue)
|
||||||
|
end
|
||||||
|
|
||||||
|
local ItemListForm = Formspec:new()
|
||||||
|
|
||||||
|
---Maximum number of items pages
|
||||||
|
---@type integer
|
||||||
|
local pagesMax = math.ceil(#items/PAGE_NUMBER_ITEMS)
|
||||||
|
|
||||||
|
if pagesMax == 0 then
|
||||||
|
pagesMax = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if pageNumber > pagesMax then
|
||||||
|
pageNumber = pagesMax
|
||||||
|
listTabData.pageNumber = pageNumber
|
||||||
|
end
|
||||||
|
|
||||||
|
local w, h = 0.0, 0.0
|
||||||
|
|
||||||
|
for i = PAGE_NUMBER_ITEMS*pageNumber-PAGE_NUMBER_ITEMS+1, PAGE_NUMBER_ITEMS*pageNumber do
|
||||||
|
local item = items[i]
|
||||||
|
if item == nil then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
if item == selectedItem then
|
||||||
|
ItemListForm
|
||||||
|
:imageButton(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_button_pressed_background.png', item..'::'..tabType..'::admin_list_tab::items_list_button')
|
||||||
|
else
|
||||||
|
ItemListForm
|
||||||
|
:imageButton(w, h, 1.125, 1.125, 'player_inventory_items_list_tab_button_background.png', item..'::'..tabType..'::admin_list_tab::items_list_button')
|
||||||
|
end
|
||||||
|
|
||||||
|
ItemListForm
|
||||||
|
:itemImage(w+0.0625, h+0.0625, 1, 1, item)
|
||||||
|
|
||||||
|
w = w + 1.125
|
||||||
|
|
||||||
|
if w >= 6 then
|
||||||
|
w = 0
|
||||||
|
h = h + 1.125
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
AdminListTab
|
||||||
|
:background(0, 0, 14, 9, 'player_inventory_items_list_tab_background.png')
|
||||||
|
:field(7.75, 0.5, 6, 0.75, tabType..'::admin_list_tab::items_list_search_field', nil, searchFieldValue)
|
||||||
|
:fieldCloseOnEnter(tabType..'::admin_list_tab::items_list_search_field', false)
|
||||||
|
:container(ItemListForm, 0.5, 0.5)
|
||||||
|
:button(1.75, 7.75, 1, 0.5, tabType..'::admin_list_tab::items_list_page_back', '<')
|
||||||
|
:button(2.75, 7.75, 1, 0.5, tabType..'::admin_list_tab::items_list_page_forward', '>')
|
||||||
|
:label(2.5,8.5, ('%s/%s'):format(pageNumber, pagesMax))
|
||||||
|
|
||||||
|
if selectedItem ~= '' then
|
||||||
|
local item = ItemStack(selectedItem)
|
||||||
|
local itemDef = item:get_definition()
|
||||||
|
|
||||||
|
AdminListTab
|
||||||
|
:itemImage(8, 1.5, 2, 2, selectedItem)
|
||||||
|
:textArea(8, 4, 5, 4, nil, nil, selectedItem)
|
||||||
|
:button(8.75, 7.5, 2, 1, tabType..'::add_item::'..'1', '1')
|
||||||
|
:button(10.75, 7.5,2, 1, tabType..'::add_item::'..tostring(itemDef.stack_max), ''..tostring(itemDef.stack_max))
|
||||||
|
end
|
||||||
|
|
||||||
|
return AdminListTab
|
||||||
|
end
|
||||||
|
|
||||||
|
return getAdminListTab
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
local require = Mod:getInfo('smc__ui__player_inventory').require
|
||||||
local getCraftTabTemplate = require('PlayerInventoryUI.baseGetCraftTab')
|
local getCraftTabTemplate = require('PlayerInventoryUI.baseGetCraftTab')
|
||||||
|
|
||||||
local CraftSystem = Smc.requireCraftSystem()
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 631 B |
|
After Width: | Height: | Size: 630 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__ui__work_station')
|
local modInfo = Mod:getInfo('smc__ui__work_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('WorkStationUI')
|
return require('WorkStationUI')
|
||||||
|
|||||||