Compare commits
79 Commits
tahrion_te
...
eeffae6852
| Author | SHA1 | Date | |
|---|---|---|---|
| eeffae6852 | |||
| fe3298d112 | |||
| 7d49bbf535 | |||
| efcbc909e0 | |||
| 17413df9c4 | |||
| 2eede05436 | |||
| b863c88838 | |||
| 692105abfa | |||
| 1a6086190e | |||
| e20c3b4ef4 | |||
| 8b55ccff72 | |||
| c7cfe26335 | |||
| 51e6763457 | |||
| c47ab6ac3c | |||
| 6fd8295500 | |||
| b12f890740 | |||
| 4c90041c68 | |||
| b50d642bcf | |||
| e0b9024458 | |||
| 745eaa8569 | |||
| b6051e5724 | |||
| 5c936025f1 | |||
| 5be847bf58 | |||
| 0198771c51 | |||
| 5272294aeb | |||
| 2eb7d04039 | |||
| c70bf96734 | |||
| b64c8e9350 | |||
| 319f155849 | |||
| ed4094d964 | |||
| 6b074c7a8c | |||
| 00633226cf | |||
| 6156a4bb6f | |||
| b6f354f6fe | |||
| cfc4502cb0 | |||
| bafe26983c | |||
| 7b43def5fb | |||
| f4896b89ef | |||
| c58467f22b | |||
| 1d5f93c35a | |||
| 46427f565f | |||
| 8fb4e4db00 | |||
| 9c56db6ac4 | |||
| 15bb906df7 | |||
| e9818fba24 | |||
| a6fa46bb96 | |||
| 44adcf9535 | |||
| 97292d6205 | |||
| f2af5e725a | |||
| 25f38d1acd | |||
| 1d43ae1255 | |||
| 9426ac01dd | |||
| 21232bd1f7 | |||
| 0c02c0045d | |||
| 205cbc10c2 | |||
| 660c96ab5c | |||
| ec8499ff76 | |||
| 430ac78ea1 | |||
| f7140fb3cc | |||
| 6153b053f6 | |||
| bc03aa4ba6 | |||
| 04f90a7b2d | |||
| 66380fb873 | |||
| 169dd64bce | |||
| 613b7ead83 | |||
| 94dc3fa819 | |||
| 6c77b5a38c | |||
| c41ee05b55 | |||
| 87c6e5f3f3 | |||
| e435b21b43 | |||
| 0baa7af759 | |||
| 83304bbfc1 | |||
| 7dbd2f3be8 | |||
| b41448da7b | |||
| 865f46b734 | |||
| 3dd28858f5 | |||
| 9119582ddd | |||
| a12091fc93 | |||
| cfadf47951 |
@@ -1,5 +1,5 @@
|
||||
name: Сообщение об ошибке
|
||||
about: Сообщить о недоработке игры, которую необходимо исправить.
|
||||
name: PR-template
|
||||
about: PR-template
|
||||
labels:
|
||||
- pr/wait review
|
||||
- review/need a maintainer
|
||||
@@ -23,12 +23,12 @@ body:
|
||||
attributes:
|
||||
label: Требования
|
||||
options:
|
||||
- label: Я запускал игру и убедился в том, что она работает.
|
||||
required: true
|
||||
- label: Я ознакомлен с соглашением по разработке и мои изменения следуют принятым стандартам.
|
||||
required: true
|
||||
- label: Я запускал игру и убедился в том, что она работает.
|
||||
required: false
|
||||
- label: Я указал в описании запроса метки (label) с префиксом `Edit:` в соответствии с теми изменениями, которые сделал.
|
||||
required: true
|
||||
required: false
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
|
||||
4
mods/CORE/BaseUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__base_ui')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('BaseUI')
|
||||
2
mods/CORE/BaseUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__core__base_ui
|
||||
depends = smc__system__system_loader
|
||||
130
mods/CORE/BaseUI/src/BaseUI.lua
Normal file
@@ -0,0 +1,130 @@
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
---@class BaseUI
|
||||
---Context for transferring data between displaying
|
||||
---the form spec to the player and handling callbacks.
|
||||
---@field name string
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,...):string
|
||||
---@field contex table<string, table>
|
||||
local BaseUI = {
|
||||
contex = {}
|
||||
}
|
||||
|
||||
---@param name string The name of the formspec that will be shown to the player. It is recommended that the name be unique.
|
||||
---@param getFormSpecString fun(self:BaseUI,playerName:string,...):string
|
||||
---@param clearContex boolean? Whether to clear the context stored for a player when that player closes the form. Default `true`.
|
||||
function BaseUI:new(name, getFormSpecString, clearContex)
|
||||
if clearContex == nil then
|
||||
clearContex = true
|
||||
end
|
||||
|
||||
---@type BaseUI
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.getFormSpecString = getFormSpecString
|
||||
|
||||
if clearContex then
|
||||
core.log(name)
|
||||
-- Ensure that when the form is closed, the context is cleared.
|
||||
instance:registerOnFormQuit(function(player)
|
||||
instance:clearContex(player)
|
||||
end)
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Set a value for a specific key.
|
||||
---Recommended for use where `core.show_formspec` is used.
|
||||
---
|
||||
---In the future, the key value can be obtained in the formspec callback.
|
||||
---@param player string|Player Player as an object (entity) or his name
|
||||
---@param key string
|
||||
---@param value any
|
||||
function BaseUI:setContex(player, key, value)
|
||||
if type(player) ~= 'string' then
|
||||
player = player:get_player_name()
|
||||
end
|
||||
|
||||
local contex = self.contex[player]
|
||||
|
||||
if contex == nil then
|
||||
self.contex[player] = {[key]=value}
|
||||
else
|
||||
contex[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
---Get the value of a specific key.
|
||||
---Recommended for use in a formspec callback.
|
||||
---@param player string|Player Player as an object (entity) or his name
|
||||
---@param key string
|
||||
---@return any?
|
||||
function BaseUI:getContex(player, key)
|
||||
if type(player) ~= 'string' then
|
||||
player = player:get_player_name()
|
||||
end
|
||||
|
||||
local contex = self.contex[player] or {}
|
||||
return contex[key]
|
||||
end
|
||||
|
||||
---Clear saved context data for a player.
|
||||
---Recommended for use when closing formspec.
|
||||
---@param player string|Player Player as an object (entity) or his name
|
||||
function BaseUI:clearContex(player)
|
||||
if type(player) ~= 'string' then
|
||||
player = player:get_player_name()
|
||||
end
|
||||
|
||||
self.contex[player] = {}
|
||||
end
|
||||
|
||||
---Register a callback for a specific player action in FormSpec.
|
||||
---
|
||||
---The callback is guaranteed to be called only for the specified field.
|
||||
---@param fieldName string the name of the field for which the callback will be called.
|
||||
---@param callback fun(player:Player, fieldName:string, fieldValue:any) Callback to handle the action. Parameters:
|
||||
--- * `player` - the player who performed the action.
|
||||
--- * `fieldName` - the name of the field on which the callback is called.
|
||||
--- * `fieldValue` - the field value that is passed in the `fields` table.
|
||||
function BaseUI:registerOnFormFieldAction(fieldName, callback)
|
||||
Smc.registerOnFormFieldAction(self.name, fieldName, callback)
|
||||
end
|
||||
|
||||
---Register a callback function to close the FormSpec.
|
||||
---
|
||||
---The callback is guaranteed to be called only for the specified form.
|
||||
---@param callback fun(player:Player) Callback to handle the close. Parameters:
|
||||
--- * `player` - the player who closed the form.
|
||||
function BaseUI:registerOnFormQuit(callback)
|
||||
Smc.registerOnFormQuit(self.name, callback)
|
||||
end
|
||||
|
||||
---Register a callback for a specific player action in FormSpec.
|
||||
---
|
||||
---The callback function is guaranteed to be called only for the specified form and
|
||||
---for the field whose name matches the pattern.
|
||||
---@param fieldNamePattern string the name pattern of the field for which the callback will be called.
|
||||
---@param callback fun(player:Player, fieldName:string, fieldValue:any) Callback to handle the action. Parameters:
|
||||
--- * `player` - the player who performed the action.
|
||||
--- * `fieldName` - the name of the field on which the callback is called (will match the pattern).
|
||||
--- * `fieldValue` - the field value that is passed in the `fields` table.
|
||||
function BaseUI:registerOnFormFieldActionMatch( fieldNamePattern, callback)
|
||||
Smc.registerOnFormFieldActionMatch(self.name, fieldNamePattern, callback)
|
||||
end
|
||||
|
||||
---Shows the player the FormSpec registered by the instance of this UI.
|
||||
---@param playerName string
|
||||
function BaseUI:showForm(playerName, ...)
|
||||
core.show_formspec(playerName, self.name, self:getFormSpecString(playerName, ...))
|
||||
end
|
||||
|
||||
---Close the player the FormSpec registered by the instance of this UI.
|
||||
---@param playerName string
|
||||
function BaseUI:closeForm(playerName)
|
||||
core.close_formspec(playerName, self.name)
|
||||
end
|
||||
|
||||
|
||||
return BaseUI
|
||||
@@ -2,7 +2,6 @@
|
||||
local Control = {}
|
||||
|
||||
-- control.on_press
|
||||
Events.registerEvent('control.on_press')
|
||||
|
||||
---@param callbackFunc fun(player:Player, controlName:string)
|
||||
function Control.subcribeOnPress(callbackFunc)
|
||||
@@ -11,7 +10,6 @@ end
|
||||
|
||||
|
||||
-- control.on_release
|
||||
Events.registerEvent('control.on_release')
|
||||
|
||||
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number)
|
||||
function Control.subcribeOnRelease(callbackFunc)
|
||||
@@ -20,7 +18,6 @@ end
|
||||
|
||||
|
||||
-- control.on_hold
|
||||
Events.registerEvent('control.on_hold')
|
||||
|
||||
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number, dtime:number)
|
||||
function Control.subcribeOnHold(callbackFunc)
|
||||
@@ -29,7 +26,6 @@ end
|
||||
|
||||
|
||||
-- control.on_wield_change
|
||||
Events.registerEvent('control.on_wield_change')
|
||||
|
||||
---@param callbackFunc fun(player:Player, player_wield_index:number, player_last_wield_index:number)
|
||||
function Control.subcribeOnWieldChange(callbackFunc)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('CraftSystem')
|
||||
return require('CraftSystem')
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
name = smc__core__craft_system
|
||||
depends = smc__system__system_loader
|
||||
depends = smc__system__system_loader, smc__core__creature
|
||||
|
||||
@@ -1,117 +1,28 @@
|
||||
local HASH_SPLITTER = '&'
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@alias CraftSystem.shapelessCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ShapelessCraft[]>>
|
||||
---@alias CraftSystem.processualCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ProcessualCraft[]>>
|
||||
---@type CraftSystem.PrimitiveCraftHandler
|
||||
local PrimitiveCraftHandler = require('CraftSystem.PrimitiveCraftHandler')
|
||||
---@type CraftSystem.ImmersiveCraftHandler
|
||||
local ImmersiveCraftHandler= require('CraftSystem.ImmersiveCraftHandler')
|
||||
|
||||
---@alias CraftSystem.CraftGroup string
|
||||
---@alias CraftSystem.CraftRecipe string[]
|
||||
---@alias CraftSystem.CraftType 'primitive'|'immersive'
|
||||
|
||||
---@class CraftSystem
|
||||
---@field shapelessCraftsList CraftSystem.shapelessCraftsList
|
||||
---@field processualCraftsList CraftSystem.processualCraftsList
|
||||
local CraftSystem = {
|
||||
shapelessCraftsList = {},
|
||||
processualCraftsList = {},
|
||||
}
|
||||
local CraftSystem = {}
|
||||
|
||||
---@alias CraftSystem.Craft.Type
|
||||
---|'shapeless'
|
||||
---|'processual'
|
||||
---@alias CraftSystem.Craft.Group string
|
||||
---@alias CraftSystem.Craft.Recipe string[]
|
||||
|
||||
---@alias shapelessCraftFunc fun(self:CraftSystem.ShapelessCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?):boolean
|
||||
---@alias processualCraftFunc fun(self:CraftSystem.ProcessualCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?, processTime:number):boolean
|
||||
|
||||
---@class CraftSystem.BaseCraft
|
||||
---@field type CraftSystem.Craft.Type
|
||||
---@field group CraftSystem.Craft.Group
|
||||
---@field output string
|
||||
---@field recipe CraftSystem.Craft.Recipe
|
||||
---@field return table? TODO: доделать тут тип
|
||||
---@field craftFunc (fun(self, ...):boolean)?
|
||||
|
||||
---@class CraftSystem.ShapelessCraft : CraftSystem.BaseCraft
|
||||
---@field craftFunc shapelessCraftFunc?
|
||||
|
||||
---@class CraftSystem.ProcessualCraft : CraftSystem.BaseCraft
|
||||
---@field processTime number
|
||||
---@field craftFunc processualCraftFunc?
|
||||
|
||||
---@param type CraftSystem.Craft.Type
|
||||
---@return CraftSystem.shapelessCraftsList|CraftSystem.processualCraftsList
|
||||
local function getCraftList(type)
|
||||
local craftList
|
||||
|
||||
if type == 'shapeless' then
|
||||
craftList = CraftSystem.shapelessCraftsList
|
||||
elseif type == 'processual' then
|
||||
craftList = CraftSystem.processualCraftsList
|
||||
else
|
||||
error(string.format('Craft type `%s` does not exist.', type))
|
||||
end
|
||||
|
||||
return craftList
|
||||
---@param craftName string
|
||||
---@param def CraftSystem.PrimitiveCraftDef
|
||||
function CraftSystem.registerPrimitiveCraft(craftName, def)
|
||||
PrimitiveCraftHandler:registerCraft(craftName, def)
|
||||
end
|
||||
|
||||
---@param type CraftSystem.Craft.Type
|
||||
---@param group CraftSystem.Craft.Group
|
||||
---@return table<string, table>
|
||||
local function getCraftGroup(type, group)
|
||||
local craftList = getCraftList(type)
|
||||
|
||||
---@type table<string, table>?
|
||||
local craftGroup = craftList[group]
|
||||
|
||||
assert(craftGroup ~= nil, string.format('Craft group `%s` does not exist.', type))
|
||||
|
||||
return craftGroup
|
||||
---@param craftName string
|
||||
---@param def CraftSystem.ImmersiveCraftDef
|
||||
function CraftSystem.registerImmersiveCraft(craftName, def)
|
||||
ImmersiveCraftHandler:registerCraft(craftName, def)
|
||||
end
|
||||
|
||||
---@param type CraftSystem.Craft.Type
|
||||
---@param group CraftSystem.Craft.Group
|
||||
function CraftSystem.registerCraftGroup(type, group)
|
||||
local craftList = getCraftList(type)
|
||||
|
||||
assert(craftList[group] == nil, string.format('Craft group `%s` is already registered.', type))
|
||||
|
||||
craftList[group] = {}
|
||||
end
|
||||
|
||||
---@param recipe CraftSystem.Craft.Recipe
|
||||
---@return string
|
||||
function CraftSystem.getCraftHash(recipe)
|
||||
table.sort(recipe)
|
||||
|
||||
local hash = ''
|
||||
|
||||
for i = 0, #recipe-1 do
|
||||
hash = hash..recipe[i]..HASH_SPLITTER
|
||||
end
|
||||
|
||||
return hash..recipe[#recipe]
|
||||
end
|
||||
|
||||
---@param craftDef CraftSystem.ShapelessCraft|CraftSystem.ProcessualCraft
|
||||
function CraftSystem.registerCraft(craftDef)
|
||||
local craftGroup = getCraftGroup(craftDef.type, craftDef.group)
|
||||
|
||||
local hash = CraftSystem.getCraftHash(craftDef.recipe)
|
||||
|
||||
table.insert(craftGroup[hash], craftDef)
|
||||
end
|
||||
|
||||
---@param type CraftSystem.Craft.Type
|
||||
---@param group CraftSystem.Craft.Group
|
||||
---@return CraftSystem.ShapelessCraft[] |
|
||||
--- CraftSystem.processualCraftsList[] |
|
||||
--- nil
|
||||
function CraftSystem.getCraftResults(type, group, recipe)
|
||||
local craftGroup = getCraftGroup(type, group)
|
||||
|
||||
local hash = CraftSystem.getCraftHash(recipe)
|
||||
|
||||
return craftGroup[hash]
|
||||
end
|
||||
|
||||
return CraftSystem
|
||||
return CraftSystem
|
||||
|
||||
13
mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
---Abstract class for craft.
|
||||
---@class CraftSystem.BaseCraft
|
||||
---@field name string
|
||||
---@field group CraftSystem.CraftGroup
|
||||
local BaseCraft = {}
|
||||
|
||||
---Definition table for the `CraftSystem.BaseCraft`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.BaseCraftDef
|
||||
---@field group CraftSystem.CraftGroup
|
||||
|
||||
return BaseCraft
|
||||
47
mods/CORE/CraftSystem/src/CraftSystem/BaseCraftHandler.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
---Abstract class for handling crafting.
|
||||
---@class CraftSystem.BaseCraftHandler
|
||||
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
||||
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
||||
---@field craftsList CraftSystem.BaseCraft[]
|
||||
---@field learnedCrafts table<string, table<string, CraftSystem.BaseCraft>>
|
||||
local BaseCraftHandler = {
|
||||
craftsByName = {},
|
||||
craftsByGroup = {},
|
||||
craftsList = {},
|
||||
learnedCrafts = {},
|
||||
}
|
||||
|
||||
---@param craftName string
|
||||
---@return CraftSystem.BaseCraft
|
||||
function BaseCraftHandler:getCraftByName(craftName)
|
||||
local craft = self.craftsByName[craftName]
|
||||
|
||||
assert(craft ~= nil, ('There is no primitive craft named `%s`.'):format(
|
||||
craftName))
|
||||
|
||||
return craft
|
||||
end
|
||||
|
||||
---@param craftGroup CraftSystem.CraftGroup
|
||||
---@return CraftSystem.BaseCraft[]
|
||||
function BaseCraftHandler:getCraftsByGroup(craftGroup)
|
||||
local crafts = self.craftsByGroup[craftGroup]
|
||||
|
||||
assert(crafts ~= nil, ('There are no primitive crafts with `%s` group'):format(
|
||||
craftGroup))
|
||||
|
||||
return crafts
|
||||
end
|
||||
|
||||
---@param playerName string
|
||||
---@return table<string, CraftSystem.BaseCraft>
|
||||
function BaseCraftHandler:getLearnedCrafts(playerName)
|
||||
local crafts = self.learnedCrafts[playerName]
|
||||
|
||||
assert(crafts ~= nil, ('There is no primitive crafting data for a player named `%s`.'):format(
|
||||
playerName))
|
||||
|
||||
return crafts
|
||||
end
|
||||
|
||||
return BaseCraftHandler
|
||||
237
mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua
Normal file
@@ -0,0 +1,237 @@
|
||||
local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type CraftSystem.BaseCraft
|
||||
local BaseCraft = require('CraftSystem.BaseCraft')
|
||||
---@type CraftSystem.ImmersiveCraftCounter
|
||||
local ImmersiveCraftCounter = require('CraftSystem.ImmersiveCraftCounter')
|
||||
|
||||
---Types of immersive stages.
|
||||
---@class CraftSystem.StagesTypes : table<CraftSystem.ImmersiveCraftStage.Type, CraftSystem.ImmersiveCraftStage>
|
||||
local stageTypes = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStage
|
||||
tapping = require('CraftSystem.ImmersiveCraftStage.TappingStage'),
|
||||
}
|
||||
|
||||
---Immersive crafting aimed at a more logical process of crafting items.
|
||||
---@class CraftSystem.ImmersiveCraft : CraftSystem.BaseCraft
|
||||
---@field startStageName string
|
||||
---@field triggerItem string
|
||||
---@field output ItemStackString
|
||||
---@field stagesByName table<string, CraftSystem.ImmersiveCraftStage>
|
||||
local ImmersiveCraft = extend(BaseCraft, {})
|
||||
|
||||
---Definition table for the `CraftSystem.ImmersiveCraft`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.ImmersiveCraftDef : CraftSystem.BaseCraftDef
|
||||
---@field startStageName string
|
||||
---@field triggerItem string
|
||||
---@field output string
|
||||
---@field stages CraftSystem.ImmersiveCraftStageDef[]
|
||||
|
||||
---@param name string
|
||||
---@param def CraftSystem.ImmersiveCraftDef
|
||||
---@return CraftSystem.ImmersiveCraft
|
||||
function ImmersiveCraft:new(name, def)
|
||||
-- We create a table of crafting stages that the player needs to complete.
|
||||
---@type table<string, CraftSystem.ImmersiveCraftStage>
|
||||
local stagesByName = {}
|
||||
|
||||
for _, stageDef in ipairs(def.stages) do
|
||||
-- We get the stage class based on its type.
|
||||
local StageClass = stageTypes[stageDef.type]
|
||||
|
||||
-- Create a stage and add the craft name to the instance.
|
||||
stageDef.craftName = name
|
||||
local stage = StageClass:new(stageDef)
|
||||
|
||||
-- We add an instance of the stage to the table by name.
|
||||
stagesByName[stageDef.name] = stage
|
||||
end
|
||||
|
||||
---@type CraftSystem.ImmersiveCraft
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.group = def.group
|
||||
instance.startStageName = def.startStageName
|
||||
instance.triggerItem = def.triggerItem
|
||||
instance.output = def.output
|
||||
instance.stagesByName = stagesByName
|
||||
|
||||
-- Subscribe to an event that will determine that the player has completed the crafting stage.
|
||||
Events.subscribe('craft_system:next_immersive_stage:'..name,
|
||||
---@param eventName string
|
||||
---@param stage CraftSystem.ImmersiveCraftStage
|
||||
---@param pos MapPosition
|
||||
---@param Player Player
|
||||
function(eventName, stage, pos, Player)
|
||||
-- From the current stage (which has been completed) we get the name of the next one.
|
||||
local nextStageName = stage.nextStage
|
||||
|
||||
-- If there is no next stage...
|
||||
if nextStageName == nil then
|
||||
-- ...we are finishing the craft.
|
||||
instance:endCraft(pos, Player)
|
||||
else
|
||||
-- ...else we start the next stage.
|
||||
local nextStage = instance.stagesByName[nextStageName]
|
||||
|
||||
-- We get a table of temporary data.
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
-- We are updating the crafting stage in it.
|
||||
craftData.stageName = nextStageName
|
||||
-- We save it to the workstation metadata.
|
||||
Smc.setCraftDataByPos(pos, craftData)
|
||||
|
||||
-- We are starting the next stage of crafting.
|
||||
nextStage:startHandler(pos, Player)
|
||||
end
|
||||
end)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Initialize the start of the immersive crafting process.
|
||||
---
|
||||
---Returns `true` if the crafting process was running.
|
||||
---@param pos MapPosition
|
||||
---@param player Player
|
||||
---@param amount integer
|
||||
---@return boolean
|
||||
function ImmersiveCraft:startCraft(pos, player, amount)
|
||||
-- Adding craft to the counter.
|
||||
-- If crafting has not been added...
|
||||
if not ImmersiveCraftCounter:addCraft(pos, player:get_player_name()) then
|
||||
-- ...then we don't let the player start a new craft.
|
||||
core.chat_send_player(player:get_player_name(),
|
||||
'The limit of simultaneously active crafts has been reached: '..
|
||||
'complete or cancel active crafts to start a new one')
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- We get the material as an ItemStack.
|
||||
---@type ItemStack
|
||||
local stack = ItemStack(self.triggerItem)
|
||||
-- We edit the amount of materials in accordance with the number of crafts being performed.
|
||||
stack:set_count(stack:get_count() * amount)
|
||||
|
||||
-- We get the player's inventory, from where we must take the materials for crafting.
|
||||
local playerInventory = player:get_inventory()
|
||||
|
||||
-- If the player does not have the necessary materials for crafting...
|
||||
if not playerInventory:contains_item('main', stack) then
|
||||
-- ...we inform him about this.
|
||||
core.chat_send_player(player:get_player_name(),
|
||||
'Not enough materials for crafting')
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- If we have the materials, we take them and start initializing the craft.
|
||||
playerInventory:remove_item('main', stack)
|
||||
|
||||
-- We get the first stage of crafting.
|
||||
local stage = self.stagesByName[self.startStageName]
|
||||
|
||||
-- Create a temporary data table for crafting.
|
||||
---@type ImmersiveCraftData
|
||||
local craftData = {
|
||||
playerName = player:get_player_name(), -- The name of the player who started the craft.
|
||||
craftName = self.name,
|
||||
stageName = stage.name,
|
||||
amount = amount,
|
||||
}
|
||||
-- We save it to the workstation metadata.
|
||||
Smc.setCraftDataByPos(pos, craftData)
|
||||
|
||||
-- We are starting the first stage of crafting.
|
||||
stage:startHandler(pos, player)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
---Complete the immersive crafting process.
|
||||
---@param pos MapPosition
|
||||
---@param player Player
|
||||
function ImmersiveCraft:endCraft(pos, player)
|
||||
-- We get current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
-- We drop the result of crafting.
|
||||
local dropPos = vector.new(pos) + vector.new(0, 0.9,0)
|
||||
for i=1, craftData.amount do
|
||||
core.item_drop(ItemStack(self.output), nil, dropPos)
|
||||
end
|
||||
|
||||
-- Remove craft from the counter.
|
||||
ImmersiveCraftCounter:removeCraft(pos, craftData.playerName)
|
||||
|
||||
-- Clearing the temporary data table for crafting, freeing up the work station for new crafts.
|
||||
Smc.setCraftDataByPos(pos)
|
||||
end
|
||||
|
||||
---Stop the crafting process and free up the workbench.
|
||||
---@param pos MapPosition
|
||||
function ImmersiveCraft:abortCraft(pos)
|
||||
-- We get current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
-- We get the current stage and start the abort process.
|
||||
local stage = self.stagesByName[craftData.stageName]
|
||||
stage:abortHandler(pos)
|
||||
|
||||
-- Clearing the temporary data table for crafting, freeing up the work station for new crafts.
|
||||
Smc.setCraftDataByPos(pos)
|
||||
|
||||
-- Remove craft from the counter.
|
||||
ImmersiveCraftCounter:removeCraft(pos, craftData.playerName)
|
||||
end
|
||||
|
||||
---Returns a human-readable description of the crafting process.
|
||||
---@return string
|
||||
function ImmersiveCraft:toString()
|
||||
-- We get the material as an ItemStack.
|
||||
---@type ItemStack
|
||||
local stack = ItemStack(self.triggerItem)
|
||||
-- We obtain a table of item parameters.
|
||||
---@type ItemDefinition
|
||||
local itemDef = stack:get_definition()
|
||||
|
||||
-- Let's start writing a description of the craft.
|
||||
local craftDesc = ('Material: %s x%s\n\n'):format(itemDef._title, stack:get_count())..
|
||||
'Crafting process:\n'
|
||||
|
||||
-- Let's start with the first crafting stage.
|
||||
---@type string?
|
||||
local stageName = self.startStageName
|
||||
local stages = self.stagesByName
|
||||
|
||||
-- While we have a stage name...
|
||||
local count = 1
|
||||
while stageName ~= nil do
|
||||
-- We get a crafting stage...
|
||||
local stage = stages[stageName]
|
||||
|
||||
-- ...and we add its description to the list of actions for crafting.
|
||||
craftDesc = craftDesc..tostring(count)..'. '..stage:toString()..'\n'
|
||||
|
||||
-- We also get the name of the next stage.
|
||||
stageName = stage.nextStage
|
||||
end
|
||||
|
||||
-- If the cycle is interrupted, it means we have processed all the stages.
|
||||
-- Return the craft description.
|
||||
return craftDesc
|
||||
end
|
||||
|
||||
return ImmersiveCraft
|
||||
@@ -0,0 +1,78 @@
|
||||
local posToString, getSize = core.pos_to_string, table.get_size
|
||||
|
||||
local CRAFT_LIMIT_PER_PLAYER = 2
|
||||
local CRAFT_LIMIT_PER_SERVER = 10
|
||||
|
||||
local modStorage = core.get_mod_storage()
|
||||
|
||||
---@param key string
|
||||
---@return table
|
||||
local function getStorageTable(key)
|
||||
return core.deserialize(modStorage:get_string(key)) or {}
|
||||
end
|
||||
|
||||
---@param key string
|
||||
---@param t table
|
||||
local function setStorageTable(key, t)
|
||||
modStorage:set_string(key, core.serialize(t))
|
||||
end
|
||||
|
||||
---Designed to keep track of active immersive
|
||||
---crafts so as not to overload the server.
|
||||
---
|
||||
---The counter is individual for each player,
|
||||
---but the total number of active crafts is also tracked.
|
||||
---@class CraftSystem.ImmersiveCraftCounter
|
||||
---@field craftsCountForPlayers table<string, table<string, boolean>>
|
||||
---@field craftsCountForServer table<string, boolean>
|
||||
local ImmersiveCraftCounter = {
|
||||
craftsCountForPlayers = getStorageTable('crafts_count_for_players'),
|
||||
craftsCountForServer = getStorageTable('crafts_count_for_serves')
|
||||
}
|
||||
|
||||
---Add craft to the counter.
|
||||
---
|
||||
---Returns `false` if the counter is already full.
|
||||
---@param pos MapPosition
|
||||
---@param playerName string
|
||||
---@return boolean
|
||||
function ImmersiveCraftCounter:addCraft(pos, playerName)
|
||||
if self.craftsCountForPlayers[playerName] == nil then
|
||||
self.craftsCountForPlayers[playerName] = {}
|
||||
end
|
||||
|
||||
if getSize(self.craftsCountForPlayers[playerName]) >= CRAFT_LIMIT_PER_PLAYER then
|
||||
return false
|
||||
end
|
||||
|
||||
if getSize(self.craftsCountForServer) >= CRAFT_LIMIT_PER_SERVER then
|
||||
return false
|
||||
end
|
||||
|
||||
local posString = posToString(pos)
|
||||
self.craftsCountForPlayers[playerName][posString] = true
|
||||
self.craftsCountForServer[posString] = true
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
---Remove craft from the counter.
|
||||
---@param pos MapPosition
|
||||
---@param playerName string
|
||||
function ImmersiveCraftCounter:removeCraft(pos, playerName)
|
||||
local playerCrafts = self.craftsCountForPlayers[playerName]
|
||||
if playerCrafts == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local posString = posToString(pos)
|
||||
playerCrafts[posString] = nil
|
||||
self.craftsCountForServer[posString] = nil
|
||||
end
|
||||
|
||||
core.register_on_shutdown(function()
|
||||
setStorageTable('crafts_count_for_players', ImmersiveCraftCounter.craftsCountForPlayers)
|
||||
setStorageTable('crafts_count_for_server', ImmersiveCraftCounter.craftsCountForServer)
|
||||
end)
|
||||
|
||||
return ImmersiveCraftCounter
|
||||
@@ -0,0 +1,71 @@
|
||||
local extend = Class.extend
|
||||
|
||||
local tableInsert = table.insert
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type CraftSystem.BaseCraftHandler
|
||||
local BaseCraftHandler = require('CraftSystem.BaseCraftHandler')
|
||||
---@type CraftSystem.ImmersiveCraft
|
||||
local ImmersiveCraft = require('CraftSystem.ImmersiveCraft')
|
||||
|
||||
---A handler for immersive crafting that requires the player to complete
|
||||
---crafting stages and interact with entities (crafting nodes)
|
||||
---@class CraftSystem.ImmersiveCraftHandler : CraftSystem.BaseCraftHandler
|
||||
---@field craftsByTriggerItem table<string, CraftSystem.ImmersiveCraft[]>
|
||||
---@field getCraftByName fun(self, craftName:string):CraftSystem.ImmersiveCraft
|
||||
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.ImmersiveCraft[]
|
||||
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.ImmersiveCraft>
|
||||
local ImmersiveCraftHandler = extend(BaseCraftHandler, {
|
||||
craftsByTriggerItem = {},
|
||||
})
|
||||
|
||||
---Register an immersive crafting experience that requires the player to complete
|
||||
---one or more crafting stages that involve interaction with entities (crafting nodes)
|
||||
---@param craftName string
|
||||
---@param def CraftSystem.ImmersiveCraftDef
|
||||
function ImmersiveCraftHandler:registerCraft(craftName, def)
|
||||
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
||||
craftName))
|
||||
|
||||
-- We obtain a crafting instance according to the given parameters.
|
||||
local craft = ImmersiveCraft:new(craftName, def)
|
||||
|
||||
-- The craft group to which the craft belongs.
|
||||
local group = def.group
|
||||
|
||||
-- If no craft with this group has been registered before...
|
||||
if self.craftsByGroup[group] == nil then
|
||||
-- ...then we create a list for this group.
|
||||
self.craftsByGroup[group] = {}
|
||||
end
|
||||
|
||||
-- The material from which crafting begins (also known as the starting item).
|
||||
local triggerItem = def.triggerItem
|
||||
|
||||
-- If no crafting for such a starting item has been registered before...
|
||||
if self.craftsByTriggerItem[triggerItem] == nil then
|
||||
-- ...then we create a list for this item.
|
||||
self.craftsByTriggerItem[triggerItem] = {}
|
||||
end
|
||||
|
||||
-- Adding craft to the lists:
|
||||
self.craftsByName[craftName] = craft
|
||||
tableInsert(self.craftsByGroup[group], craft)
|
||||
tableInsert(self.craftsByTriggerItem[triggerItem], craft)
|
||||
tableInsert(self.craftsList, craft)
|
||||
end
|
||||
|
||||
---Returns a list of crafts that use the given item as a starting material.
|
||||
---
|
||||
---Will return `nil` if the item is not used in any craft as a starting item.
|
||||
---@param triggerItem string
|
||||
---@return CraftSystem.ImmersiveCraft[]?
|
||||
function ImmersiveCraftHandler:getCraftsByTriggerItem(triggerItem)
|
||||
local crafts = self.craftsByTriggerItem[triggerItem]
|
||||
|
||||
return crafts
|
||||
end
|
||||
|
||||
return ImmersiveCraftHandler
|
||||
14
mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
---@type Creature
|
||||
local Creature = Mod.getInfo('smc__core__creature').require('Creature')
|
||||
|
||||
---The entity the player interacts with during immersive crafting.
|
||||
---@class CraftSystem.ImmersiveCraftNode : Creature
|
||||
local ImmersiveCraftNode = Creature:getExtended({
|
||||
settings = {
|
||||
_name = 'craft_system:immersive_craft_node',
|
||||
_add_mod_name = false,
|
||||
initial_properties = {},
|
||||
}
|
||||
})
|
||||
|
||||
return ImmersiveCraftNode
|
||||
@@ -0,0 +1,95 @@
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type CraftSystem.ImmersiveCraftNode
|
||||
local ImmersiveCraftNode = require('CraftSystem.ImmersiveCraftNode')
|
||||
|
||||
---A class that extends `Creature.LuaEntity` to annotate custom fields needed for immersive crafting.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.ImmersiveCraftNode.LuaTappingNode : Creature.LuaEntity
|
||||
---The name of the item that the crafting node display.
|
||||
---@field _item_name ItemStackString
|
||||
---Sets the entity display of the item. If the item stack was not transferred, `self._item_name` is used.
|
||||
---@field _set_item fun(self:CraftSystem.ImmersiveCraftNode.LuaTappingNode, itemName:ItemStackString?)
|
||||
---@field _craft_name string
|
||||
---@field _stage_name string
|
||||
---@field _work_station_pos MapPosition
|
||||
|
||||
-- A crafting node (entity) that is used in the tapping crafting stage.
|
||||
local tappingNode = ImmersiveCraftNode:new({
|
||||
settings = {
|
||||
_name = 'craft_system:tapping_node',
|
||||
_add_mod_name = false,
|
||||
|
||||
---@type ObjectProperties
|
||||
initial_properties = {
|
||||
visual = 'wielditem',
|
||||
visual_size = {x=0.5, y=0.5, z=0.5},
|
||||
collisionbox = {
|
||||
-0.375, -0.375, -0.375,
|
||||
0.375, 0.375, 0.375
|
||||
},
|
||||
},
|
||||
|
||||
_item_name = '',
|
||||
_craft_name = '',
|
||||
_stage_name = '',
|
||||
_work_station_pos = {},
|
||||
},
|
||||
callbacks = {
|
||||
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
||||
on_activate = function(luaEntity, staticdata, dtime)
|
||||
-- We obtain a table of initial parameters for the craft node entity.
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingNode.InitParams?
|
||||
local params = core.deserialize(staticdata)
|
||||
|
||||
-- We enter parameters into the entity's custom fields.
|
||||
if params ~= nil then
|
||||
luaEntity._item_name = params.targetItem
|
||||
luaEntity._craft_name = params.craftName
|
||||
luaEntity._stage_name = params.stageName
|
||||
luaEntity._work_station_pos = params.WorkStationPos
|
||||
end
|
||||
|
||||
-- we set the appearance of the item to be processed on the crafting node.
|
||||
luaEntity:_set_item(luaEntity._item_name)
|
||||
-- We add an immortal group to the entity so that it cannot be killed.
|
||||
luaEntity.object:set_armor_groups({immortal = 1})
|
||||
end,
|
||||
|
||||
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
||||
on_punch = function(luaEntity, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
-- We simply trigger the event that the player hits the crafting node, bound to the work station with coordinates.
|
||||
Events.call(('craft_system:punch_tapping_node:%s:%s'):format(
|
||||
luaEntity._craft_name, luaEntity._stage_name), luaEntity._work_station_pos, puncher, luaEntity)
|
||||
|
||||
return false
|
||||
end,
|
||||
|
||||
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
||||
get_staticdata = function(luaEntity)
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingNode.InitParams?
|
||||
local params = {
|
||||
targetItem = luaEntity._item_name,
|
||||
craftName = luaEntity._craft_name,
|
||||
stageName = luaEntity._stage_name,
|
||||
WorkStationPos = luaEntity._work_station_pos
|
||||
}
|
||||
|
||||
return core.serialize(params)
|
||||
end,
|
||||
|
||||
---Sets the entity display of the item. If the item stack was not transferred, `self._item_name` is used.
|
||||
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
||||
---@param itemName ItemStackString?
|
||||
_set_item = function(luaEntity, itemName)
|
||||
-- We change the entity field so that the engine itself displays it as a given item.
|
||||
luaEntity.object:set_properties({
|
||||
wield_item = itemName or luaEntity._item_name,
|
||||
})
|
||||
end,
|
||||
}
|
||||
})
|
||||
|
||||
return tappingNode
|
||||
@@ -0,0 +1,43 @@
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
---@alias CraftSystem.ImmersiveCraftStage.Type 'tapping'
|
||||
|
||||
---One of the stages of immersive crafting.
|
||||
---@class CraftSystem.ImmersiveCraftStage
|
||||
---@field name string
|
||||
---@field type CraftSystem.ImmersiveCraftStage.Type
|
||||
---@field craftName string
|
||||
---@field startHandler fun(self, pos:Position, player:Player)
|
||||
---@field processHandler fun(self, pos:Position, player:Player)
|
||||
---@field endHandler fun(self, pos:Position, player:Player)
|
||||
---@field abortHandler fun(self, pos:Position)
|
||||
---@field toString fun(self):string
|
||||
---@field nextStage string?
|
||||
---@field returnItems ItemStackString[]?
|
||||
local ImmersiveCraftStage = {}
|
||||
|
||||
---Definition table for the `CraftSystem.ImmersiveCraft`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.ImmersiveCraftStageDef
|
||||
---@field name string
|
||||
---@field type CraftSystem.ImmersiveCraftStage.Type
|
||||
---@field craftName string?
|
||||
---@field nextStage string?
|
||||
---@field returnItems ItemStackString[]?
|
||||
|
||||
---@param def CraftSystem.ImmersiveCraftStageDef
|
||||
---@return CraftSystem.ImmersiveCraftStage
|
||||
function ImmersiveCraftStage:new(def)
|
||||
---@type CraftSystem.ImmersiveCraftStage
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = def.name
|
||||
instance.type = def.type
|
||||
instance.craftName = def.craftName
|
||||
instance.nextStage = def.nextStage
|
||||
instance.returnItems = def.returnItems
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return ImmersiveCraftStage
|
||||
@@ -0,0 +1,202 @@
|
||||
local extend = Class.extend
|
||||
|
||||
local getStageDataByPos, setStageDataByPos = Smc.getStageDataByPos, Smc.setStageDataByPos
|
||||
|
||||
local require = Mod.getInfo('smc__core__craft_system').require
|
||||
|
||||
---@type CraftSystem.ImmersiveCraftStage
|
||||
local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
||||
|
||||
---A crafting step that requires the player to hit a crafting node (entity) a certain number of times.
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingStage : CraftSystem.ImmersiveCraftStage
|
||||
---@field targetItem string
|
||||
---@field clicksNeed string
|
||||
---@field toolGroup string?
|
||||
---@field startHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
|
||||
---@field processHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
|
||||
---@field endHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
|
||||
---@field toString fun(self:CraftSystem.ImmersiveCraftStage.TappingStage):string
|
||||
local TappingStage = extend(ImmersiveCraftStage, {})
|
||||
|
||||
---Definition table for the `CraftSystem.ImmersiveCraftStage.TappingStage`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingStageDef : CraftSystem.ImmersiveCraftStageDef
|
||||
---@field targetItem string
|
||||
---@field clicksNeed string
|
||||
---@field toolGroup string?
|
||||
|
||||
---Data table for transferring various time parameters between calls.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class ImmersiveStageData.TappingStageData : ImmersiveStageData
|
||||
---How many clicks were made by the player on the entity.
|
||||
---@field clickCount integer
|
||||
---Unique identifier of the entity (craft node).
|
||||
---@field entityGUID string
|
||||
|
||||
---@param def CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
function TappingStage:new(def)
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStage
|
||||
local instance = ImmersiveCraftStage:new(def)
|
||||
instance.targetItem = def.targetItem
|
||||
instance.clicksNeed = def.clicksNeed
|
||||
instance.toolGroup = def.toolGroup
|
||||
|
||||
-- Registering the crafting stage start handler.
|
||||
instance.startHandler = function(tappingStage , pos, player)
|
||||
-- We determine the coordinate where we will create the crafting node (entity).
|
||||
local entityPos = vector.new(pos) + vector.new(0,0.875,0)
|
||||
|
||||
-- We create a table of initial parameters that we will pass to the entity.
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams
|
||||
local params = {
|
||||
targetItem = tappingStage.targetItem,
|
||||
craftName = tappingStage.craftName,
|
||||
stageName = tappingStage.name,
|
||||
WorkStationPos = pos,
|
||||
}
|
||||
|
||||
-- Adding an entity to the world.
|
||||
local obj = core.add_entity(entityPos, 'craft_system:tapping_node', core.serialize(params))
|
||||
|
||||
-- If the entity was not returned, something went wrong.
|
||||
if obj == nil then
|
||||
return
|
||||
end
|
||||
|
||||
-- Create a temporary table of crafting stage data.
|
||||
---@type ImmersiveStageData.TappingStageData
|
||||
local stageData = {
|
||||
clickCount = 0,
|
||||
entityGUID = obj:get_guid()
|
||||
}
|
||||
|
||||
-- Saving temporary data in work station metadata.
|
||||
setStageDataByPos(pos, stageData)
|
||||
end
|
||||
|
||||
-- Registering the crafting stage process handler.
|
||||
-- Called when a player clicks on a crafting node (entity).
|
||||
instance.processHandler = function(tappingStage, pos, player)
|
||||
-- Obtaining stage time data from work station metadata.
|
||||
---@type ImmersiveStageData.TappingStageData?
|
||||
local stageData = getStageDataByPos(pos)
|
||||
assert(stageData ~= nil, 'Immersive stage data is empty.')
|
||||
|
||||
-- Increasing the click counter
|
||||
local clickCount = stageData.clickCount
|
||||
clickCount = clickCount + 1
|
||||
|
||||
-- If the number of clicks is greater than required to complete the step...
|
||||
if clickCount >= tappingStage.clicksNeed then
|
||||
-- ...we are completing the stage.
|
||||
tappingStage:endHandler(pos, player)
|
||||
else
|
||||
-- ...else we save the number of clicks in the temporary data table.
|
||||
stageData.clickCount = clickCount
|
||||
Smc.setStageDataByPos(pos, stageData)
|
||||
end
|
||||
end
|
||||
|
||||
-- Registering the crafting stage end handler.
|
||||
instance.endHandler = function(tappingStage, pos, player)
|
||||
-- Obtaining stage time data from work station metadata.
|
||||
---@type ImmersiveStageData.TappingStageData?
|
||||
local stageData = getStageDataByPos(pos)
|
||||
assert(stageData ~= nil, 'Immersive stage data is empty.')
|
||||
|
||||
-- We get the entity object.
|
||||
local entity = Smc.getObjectByGUID(stageData.entityGUID)
|
||||
assert(entity ~= nil, 'The entity for immersive crafting is nil.')
|
||||
|
||||
-- Removing an entity from the world.
|
||||
entity:remove()
|
||||
|
||||
-- We trigger an event that the crafting stage has been completed.
|
||||
Events.call('craft_system:next_immersive_stage:'..tappingStage.craftName, tappingStage, pos, player)
|
||||
end
|
||||
|
||||
-- Registering the aborting the crafting process handler.
|
||||
---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage
|
||||
instance.abortHandler = function(tappingStage, pos)
|
||||
-- We receive current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
-- Obtaining stage time data from work station metadata.
|
||||
---@type ImmersiveStageData.TappingStageData?
|
||||
local stageData = craftData.stageData
|
||||
assert(stageData ~= nil, 'Immersive stage data is empty.')
|
||||
|
||||
-- We get the entity object.
|
||||
local entity = Smc.getObjectByGUID(stageData.entityGUID)
|
||||
assert(entity ~= nil, 'The entity for immersive crafting is nil.')
|
||||
|
||||
-- Removing an entity from the world.
|
||||
entity:remove()
|
||||
|
||||
-- We drop the item as it was before processing.
|
||||
local dropPos = vector.new(pos)+vector.new(0, 0.9,0)
|
||||
for i=1, craftData.amount do
|
||||
core.item_drop(ItemStack(tappingStage.targetItem), nil, dropPos)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns a human-readable description of the crafting stage.
|
||||
instance.toString = function(tappingStage)
|
||||
local stageDesc
|
||||
if tappingStage.toolGroup ~= nil then
|
||||
stageDesc = ('Tapping x%s tool with a group "%s"'):format(tappingStage.clicksNeed, tappingStage.toolGroup)
|
||||
else
|
||||
stageDesc = ('Tapping x%s'):format(tappingStage.clicksNeed)
|
||||
end
|
||||
|
||||
return stageDesc
|
||||
end
|
||||
|
||||
-- Subscribe to an event that means the player hit the entity.
|
||||
Events.subscribe(('craft_system:punch_tapping_node:%s:%s'):format(instance.craftName, instance.name),
|
||||
---@param craftNode LuaEntity
|
||||
---@param player Player
|
||||
function(eventName, pos, player, craftNode)
|
||||
-- We get the item that the player clicked on the crafting node.
|
||||
local toolDef = player:get_wielded_item():get_definition()
|
||||
|
||||
-- If a crafting stage requires a specific tool group and he doesn't have it...
|
||||
if instance.toolGroup and (not toolDef.groups or not toolDef.groups[instance.toolGroup]) then
|
||||
-- ...then we don't do anything.
|
||||
return
|
||||
end
|
||||
|
||||
-- DRAFT START:
|
||||
-- Creating particles
|
||||
for i=0, 10 do
|
||||
core.add_particle({
|
||||
pos = vector.new(pos)+vector.new(0,0.5,0),
|
||||
velocity = {x=math.random(-1,1), y=4, z=math.random(-1,1)},
|
||||
acceleration = {x=0, y=-9.8, z=0},
|
||||
expirationtime = 2,
|
||||
collision_removal = true,
|
||||
node = {name=instance.targetItem}
|
||||
})
|
||||
end
|
||||
|
||||
-- Making the entity shake (silly method :P).
|
||||
craftNode.object:set_rotation(vector.new(0.01,0.1,0.01))
|
||||
core.after(0.1, function() craftNode.object:set_rotation(vector.new(-0.01,-0.1,-0.01))end)
|
||||
core.after(0.2, function() craftNode.object:set_rotation(vector.new(0,0,0))end)
|
||||
-- DRAFT END
|
||||
|
||||
-- Calling the crafting stage process handler.
|
||||
instance:processHandler(pos, player)
|
||||
end)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
-- Registering an entity for immersive tapping crafting.
|
||||
require('CraftSystem.ImmersiveCraftNode.tappingNode')
|
||||
|
||||
return TappingStage
|
||||
39
mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraft.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type CraftSystem.BaseCraft
|
||||
local BaseCraft = require('CraftSystem.BaseCraft')
|
||||
|
||||
---@class CraftSystem.PrimitiveCraft : CraftSystem.BaseCraft
|
||||
---@field output string
|
||||
---@field recipe CraftSystem.CraftRecipe
|
||||
---@field returnItems ItemStackString[]
|
||||
local PrimitiveCraft = extend(BaseCraft, {})
|
||||
|
||||
---Definition table for the `CraftSystem.PrimitiveCraft`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class CraftSystem.PrimitiveCraftDef : CraftSystem.BaseCraftDef
|
||||
---@field output string
|
||||
---@field recipe CraftSystem.CraftRecipe
|
||||
---@field returnItems ItemStackString[]
|
||||
|
||||
---@param name string
|
||||
---@param def CraftSystem.PrimitiveCraftDef
|
||||
---@return CraftSystem.PrimitiveCraft
|
||||
function PrimitiveCraft:new(name, def)
|
||||
---@type CraftSystem.PrimitiveCraft
|
||||
local instance = getInstance(self, {
|
||||
name = name,
|
||||
group = def.group,
|
||||
output = def.output,
|
||||
recipe = def.recipe,
|
||||
returnItems = def.returnItems or {}
|
||||
})
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return PrimitiveCraft
|
||||
@@ -0,0 +1,42 @@
|
||||
local extend = Class.extend
|
||||
|
||||
local tableInsert = table.insert
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type CraftSystem.BaseCraftHandler
|
||||
local BaseCraftHandler = require('CraftSystem.BaseCraftHandler')
|
||||
|
||||
---@type CraftSystem.PrimitiveCraft
|
||||
local PrimitiveCraft = require('CraftSystem.PrimitiveCraft')
|
||||
|
||||
---A primitive crafting processor that doesn't require much interaction and provides
|
||||
---simple crafting based on a recipe-result scheme.
|
||||
---@class CraftSystem.PrimitiveCraftHandler : CraftSystem.BaseCraftHandler
|
||||
---@field getCraftByName fun(self, craftName:string):CraftSystem.PrimitiveCraft
|
||||
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.PrimitiveCraft[]
|
||||
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.PrimitiveCraft>
|
||||
local PrimitiveCraftHandler = extend(BaseCraftHandler, {})
|
||||
|
||||
---Register a primitive craft that does not require special interaction.
|
||||
---@param craftName string
|
||||
---@param def CraftSystem.PrimitiveCraftDef
|
||||
function PrimitiveCraftHandler:registerCraft(craftName, def)
|
||||
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
||||
craftName))
|
||||
|
||||
local craft = PrimitiveCraft:new(craftName, def)
|
||||
|
||||
local group = def.group
|
||||
|
||||
if self.craftsByGroup[group] == nil then
|
||||
self.craftsByGroup[group] = {}
|
||||
end
|
||||
|
||||
self.craftsByName[craftName] = craft
|
||||
tableInsert(self.craftsByGroup[group], craft)
|
||||
tableInsert(self.craftsList, craft)
|
||||
end
|
||||
|
||||
return PrimitiveCraftHandler
|
||||
4
mods/CORE/Creature/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__creature')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('Creature')
|
||||
1
mods/CORE/Creature/mod.conf
Normal file
@@ -0,0 +1 @@
|
||||
name = smc__core__creature
|
||||
109
mods/CORE/Creature/src/Creature.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local tableCopy, tableMerge = table.copy, table.merge
|
||||
|
||||
---@class Creature
|
||||
---@field entityDef Creature.CreatureDefinition
|
||||
---@field luantiDef EntityDefinition
|
||||
---@field defaultDef Creature.CreatureDefinition
|
||||
local Creature = {
|
||||
defaultDef = {
|
||||
settings = {
|
||||
_name = '',
|
||||
_add_mod_name = true,
|
||||
initial_properties = {},
|
||||
},
|
||||
callbacks = {}
|
||||
}
|
||||
}
|
||||
|
||||
---@param entityDef Creature.CreatureDefinition
|
||||
---@return EntityDefinition
|
||||
local function entityDefToLuantiDef(entityDef)
|
||||
entityDef = tableCopy(entityDef)
|
||||
local s = entityDef.settings
|
||||
local c = entityDef.callbacks or {}
|
||||
|
||||
---@type EntityDefinition
|
||||
local luantiDef = tableMerge(s, c)
|
||||
|
||||
return luantiDef
|
||||
end
|
||||
|
||||
---@param entityDef Creature.CreatureDefinition
|
||||
---@return Creature
|
||||
function Creature:new(entityDef)
|
||||
-- Adding default parameters.
|
||||
---@type Creature.CreatureDefinition
|
||||
entityDef = tableMerge(entityDef, self.defaultDef, true)
|
||||
|
||||
-- The callback table may not be specified.
|
||||
if entityDef.callbacks == nil then
|
||||
---@type Creature.Callbacks
|
||||
entityDef.callbacks = {}
|
||||
end
|
||||
|
||||
local s = entityDef.settings
|
||||
local c = entityDef.callbacks
|
||||
|
||||
-- Add the short mod name prefix to the entity name.
|
||||
if s._add_mod_name then
|
||||
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
||||
end
|
||||
|
||||
local onActivate = c.on_activate or function() end
|
||||
|
||||
-- We rewrite the entity initialization function so that custom fields
|
||||
-- can be passed to it directly via `core.add_entity(pos, name, [staticdata])`.
|
||||
c.on_activate = function(luaEntity, staticdata, dtime)
|
||||
local initCustomFields = {}
|
||||
|
||||
if staticdata and staticdata ~= '' then
|
||||
initCustomFields = core.deserialize(staticdata) or {}
|
||||
end
|
||||
|
||||
-- We reset the fields that should not be overwritten.
|
||||
initCustomFields.name = nil
|
||||
initCustomFields.object = nil
|
||||
|
||||
---@type LuaEntity
|
||||
self = tableMerge(self, initCustomFields)
|
||||
|
||||
-- If an initialization callback was specified for the entity, then we call it.
|
||||
if c.on_activate ~= nil then
|
||||
onActivate(luaEntity, staticdata, dtime)
|
||||
end
|
||||
end
|
||||
|
||||
---@type Creature
|
||||
local instance = getInstance(self, {})
|
||||
|
||||
local luantiDef = entityDefToLuantiDef(entityDef)
|
||||
|
||||
instance.entityDef = entityDef
|
||||
instance.luantiDef = luantiDef
|
||||
|
||||
core.register_entity(':'..s._name, luantiDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Allows you to create a child class of an entity by specifying
|
||||
---default parameters that will be added to the entity's parameters
|
||||
---when an instance is received.
|
||||
---@param defaultDef Creature.CreatureDefinition
|
||||
---@return Creature
|
||||
function Creature:getExtended(defaultDef)
|
||||
-- Adding default parameters.
|
||||
---@type Creature.CreatureDefinition
|
||||
defaultDef = tableMerge(self.defaultDef, defaultDef)
|
||||
|
||||
---@type Creature
|
||||
local ChildClass = extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
return ChildClass
|
||||
end
|
||||
|
||||
return Creature
|
||||
72
mods/CORE/Creature/src/Creature/Callbacks.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
---@class Creature.Callbacks
|
||||
local Callbacks = {}
|
||||
|
||||
---Called when the object is instantiated.
|
||||
--- * `dtime_s` is the time passed since the object was unloaded,
|
||||
---which can be used for updating the entity state.
|
||||
---@type fun(self:LuaEntity, staticdata:string, dtime_s:number)?
|
||||
Callbacks.on_activate = nil
|
||||
|
||||
---Called when the object is about to get removed or unloaded.
|
||||
--- * `removal`: boolean indicating whether the object is about to get removed.
|
||||
--- Calling `object:remove()` on an active object will call this with `removal=true`.
|
||||
--- The mapblock the entity resides in being unloaded will call this with `removal=false`.
|
||||
---
|
||||
---Note that this won't be called if the object hasn't been activated in the first place.
|
||||
---In particular, `core.clear_objects({mode = "full"})` won't call this,
|
||||
---whereas `core.clear_objects({mode = "quick"})` might call this.
|
||||
---@type fun(self:LuaEntity, removal:boolean)?
|
||||
Callbacks.on_deactivate = nil
|
||||
|
||||
---Called on every server tick, after movement and collision processing.
|
||||
--- * `dtime`: elapsed time since last call
|
||||
--- * `s`: table with collision info (only available if `physical=true`)
|
||||
---@type fun(self:LuaEntity, dtime:number, moveresult:table)? -- TODO: дописать более точный тип moveresult
|
||||
Callbacks.on_step = nil
|
||||
|
||||
---Called when somebody punches the object.
|
||||
---Note that you probably want to handle most punches using the automatic armor group system.
|
||||
--- * `puncher`: an `ObjectRef `(can be `nil`)
|
||||
--- * `time_from_last_punch`: Meant for disallowing spamming of clicks (can be `nil`).
|
||||
--- * `tool_capabilities`: capability table of used item
|
||||
--- * `dir`: unit vector of direction of punch. Always defined. Points from the puncher to the punched.
|
||||
--- * `damage``: damage that will be done to entity.
|
||||
---
|
||||
---Can return `true` to prevent the default damage mechanism.
|
||||
---@type (fun(self:LuaEntity, puncher:ObjectRef|Player|nil, time_from_last_punch:number|nil, tool_capabilities:table|nil, dir:vector, damage:number):boolean)? -- TODO: дописать более точный тип для tool_capabilities
|
||||
Callbacks.on_punch = nil
|
||||
|
||||
---Called when the object dies.
|
||||
--- * `killer`: an `ObjectRef` (can be `nil`)
|
||||
---@type fun(self:LuaEntity, killer:ObjectRef|Player|nil)?
|
||||
Callbacks.on_death = nil
|
||||
|
||||
---Called when `clicker` pressed the 'place/use' key while
|
||||
---pointing to the object (not necessarily an actual rightclick)
|
||||
--- * `clicker`: an `ObjectRef` (may or may not be a player)
|
||||
---@type fun(self:LuaEntity, clicker:ObjectRef|Player)?
|
||||
Callbacks.on_rightclick = nil
|
||||
|
||||
---Called after another object is attached to this object.
|
||||
--- * `child`: an `ObjectRef` of the child
|
||||
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||
Callbacks.on_attach_child = nil
|
||||
|
||||
---Called after another object has detached from this object.
|
||||
--- * `child`: an `ObjectRef` of the child
|
||||
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||
Callbacks.on_detach_child = nil
|
||||
|
||||
---Called after detaching from another object.
|
||||
--- * `parent`: an ObjectRef from where it got detached
|
||||
---
|
||||
---**Note**: this is also called before removal from the world.
|
||||
---@type fun(self:LuaEntity, parent)?
|
||||
Callbacks.on_detach = nil
|
||||
|
||||
---Should return a string that will be passed to `on_activate` when the object
|
||||
---is instantiated the next time.
|
||||
---@type (fun(self:LuaEntity):string)?
|
||||
Callbacks.get_staticdata = nil
|
||||
|
||||
return Callbacks
|
||||
6
mods/CORE/Creature/src/Creature/CreatureDefinition.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
---@class Creature.CreatureDefinition
|
||||
---@field settings Creature.Settings
|
||||
---@field callbacks Creature.Callbacks?
|
||||
local CreatureDefinition = {}
|
||||
|
||||
return CreatureDefinition
|
||||
9
mods/CORE/Creature/src/Creature/LuaEntity.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
---A class that extends `LuaEntity` to annotate custom fields.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class Creature.LuaEntity : LuaEntity
|
||||
---@field _name string
|
||||
---@field _add_mod_name boolean
|
||||
local LuaEntity = {}
|
||||
|
||||
return LuaEntity
|
||||
14
mods/CORE/Creature/src/Creature/Settings.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
---@class Creature.Settings
|
||||
local Settings = {}
|
||||
|
||||
---Registration name for the entity. Must be unique.
|
||||
---@type string
|
||||
Settings._name = nil
|
||||
|
||||
---Whether to add the mod name to the settings._name. Default: `true`
|
||||
Settings._add_mod_name = nil
|
||||
|
||||
---@type ObjectProperties
|
||||
Settings.initial_properties = nil
|
||||
|
||||
return Settings
|
||||
@@ -1 +0,0 @@
|
||||
name = smc__core__entity
|
||||
@@ -1,4 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__item')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('Item')
|
||||
return require('Item')
|
||||
|
||||
9
mods/CORE/Item/locale/item.ru.tr
Normal file
@@ -0,0 +1,9 @@
|
||||
# textdomain: item
|
||||
|
||||
Rarity=Редкость
|
||||
common=простой
|
||||
uncommon=необычный
|
||||
distinguished=выдающийся
|
||||
eminent=исключительный
|
||||
prime=Превосходный
|
||||
unique=Уникальный
|
||||
@@ -1,51 +1,111 @@
|
||||
local getInstance = Class.getInstance
|
||||
local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__item')
|
||||
local require = modInfo.require
|
||||
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||
|
||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
local ItemFactory = Smc.requireItemFactory()
|
||||
|
||||
---Determines whether common rarity will be shown in item descriptions or not.
|
||||
local SHOW_COMMON_RARITY = true
|
||||
|
||||
---Colors corresponding to the rarity color in the item description.
|
||||
---@type table<Item.Rarity, ColorString>
|
||||
local RARITY_COLORS = {
|
||||
['common'] = '#C0C0C0',
|
||||
['uncommon'] = '#7cd2e2',
|
||||
['distinguished'] = '#7ce2da',
|
||||
['eminent'] = '#44d1a9',
|
||||
['prime'] = '#9CF0B1',
|
||||
['unique'] = '#f4c95a'
|
||||
}
|
||||
|
||||
---Whether to show the numeric index in the rarity description.
|
||||
local SHOW_RARITY_INDEX = true
|
||||
|
||||
---@type table<Item.Rarity, integer>
|
||||
local RARITY_INDEX = {
|
||||
['common'] = 1,
|
||||
['uncommon'] = 2,
|
||||
['distinguished'] = 3,
|
||||
['eminent'] = 4,
|
||||
['prime'] = 5,
|
||||
['unique'] = 0
|
||||
}
|
||||
|
||||
-- Keys indicating the languages for which localization presence is checked.
|
||||
local LANG_CODES = {'en', 'ru'}
|
||||
|
||||
-- Number of missed localizations.
|
||||
local missedLocaleCount = 0
|
||||
|
||||
---@class Item
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef table
|
||||
---@field getVisual fun(): string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef ItemDefinition
|
||||
---@field getType fun():string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
local Item = {
|
||||
defaultDef = {
|
||||
settings = {
|
||||
name = '',
|
||||
title = '',
|
||||
description = '',
|
||||
titleColor = '#FFFFFF',
|
||||
descriptionColor = '#C0C0C0',
|
||||
addModName = true,
|
||||
name = '',
|
||||
_title = '',
|
||||
_description = '',
|
||||
_title_color = '#FFFFFF',
|
||||
_description_color = '#C0C0C0',
|
||||
_rarity = 'common',
|
||||
_add_mod_name = true,
|
||||
stack_max = 128,
|
||||
},
|
||||
callbacks = {}
|
||||
}
|
||||
}
|
||||
|
||||
---Adds an item's rarity tag to the description.
|
||||
---@param rarity Item.Rarity
|
||||
---@param desc string
|
||||
---@return string
|
||||
local function addRarityToDesc(rarity, desc)
|
||||
if not SHOW_COMMON_RARITY and rarity == 'common' then
|
||||
return desc
|
||||
end
|
||||
|
||||
local S = core.get_translator('item')
|
||||
local color = RARITY_COLORS[rarity]
|
||||
|
||||
local rarityString = S('Rarity')..': '..S(rarity)
|
||||
|
||||
if SHOW_RARITY_INDEX then
|
||||
rarityString = rarityString..' ['..RARITY_INDEX[rarity]..']'
|
||||
end
|
||||
|
||||
return desc..'\n'..colorize(color, rarityString)
|
||||
end
|
||||
|
||||
---The alias `table.merge` for EmmyLua
|
||||
---@type fun(...):(NodeDefinition|ItemDefinition)
|
||||
local defMerge = function(...)
|
||||
return table.merge(...)
|
||||
return tableMerge(...)
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition
|
||||
---@return NodeDefinition|ItemDefinition
|
||||
local function checkLocale(str, strTranslate)
|
||||
local modName = Mod.getInfo().name
|
||||
for _, langCode in ipairs(LANG_CODES) do
|
||||
if core.get_translated_string(langCode, strTranslate) == str then
|
||||
missedLocaleCount = missedLocaleCount + 1
|
||||
Logger.warningLog('Localization missing[%s][%s]. String: `%s`. Mod: `%s`', missedLocaleCount, langCode, str, modName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition
|
||||
---@return NodeDefinition|ItemDefinition
|
||||
local function itemDefToLuantiDef(itemDef)
|
||||
local modName = Mod.getInfo().shortName
|
||||
local S = core.get_translator(modName)
|
||||
|
||||
itemDef = table.copy(itemDef)
|
||||
itemDef = tableCopy(itemDef)
|
||||
local s = itemDef.settings
|
||||
local c = itemDef.callbacks
|
||||
|
||||
if s.addModName then
|
||||
s.name = modName .. ':' .. s.name
|
||||
end
|
||||
|
||||
local title = s.title
|
||||
local description = s.description
|
||||
local title, description = s._title, s._description
|
||||
|
||||
if title == nil or title == '' then
|
||||
title = string.match(s.name, '%S:(%S+)')..'-title'
|
||||
@@ -55,69 +115,101 @@ local function itemDefToLuantiDef(itemDef)
|
||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||
end
|
||||
|
||||
if s.titleColor ~= nil and s.descriptionColor ~= nil then
|
||||
description = core.colorize(s.titleColor ,S(title))..'\n'..
|
||||
core.colorize(s.descriptionColor, S(description))
|
||||
local titleTranslate, descriptionTranslate = S(title), S(description)
|
||||
|
||||
checkLocale(title, titleTranslate)
|
||||
checkLocale(description, descriptionTranslate)
|
||||
|
||||
if s._title_color ~= nil and s._description_color ~= nil then
|
||||
titleTranslate = colorize(s._title_color , titleTranslate)
|
||||
descriptionTranslate = colorize(s._description_color, descriptionTranslate)
|
||||
else
|
||||
error('Item description color parameters cannot be empty.')
|
||||
end
|
||||
|
||||
s.title, s.description = nil, description
|
||||
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||
|
||||
local luantiDescription = addRarityToDesc(s._rarity, title..'\n'..description)
|
||||
|
||||
s._title = title
|
||||
s._description = description
|
||||
s.description = luantiDescription..core.get_background_escape_sequence('#110F13')
|
||||
|
||||
local luantiDef = defMerge(s, c)
|
||||
|
||||
return luantiDef
|
||||
end
|
||||
|
||||
---@param luantiDef NodeDefinition|ItemDefinition
|
||||
local function register3dItem(luantiDef)
|
||||
local ld = luantiDef
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
---@param luantiDef NodeDefinition
|
||||
local function registerNode(luantiDef)
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
core.register_node(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
---@param luantiDef ItemDefinition
|
||||
local function registerFlatItem(luantiDef)
|
||||
local ld = luantiDef
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
local function registerCraftitem(luantiDef)
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
core.register_craftitem(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
---@param luantiDef ItemDefinition
|
||||
local function registerTool(luantiDef)
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
core.register_tool(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
---The alias `table.merge` for EmmyLua
|
||||
---@type fun(...):(Item.ItemDefinition)
|
||||
local defMerge = function(...)
|
||||
return table.merge(...)
|
||||
return tableMerge(...)
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||
---@return Item
|
||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||
---@return Item
|
||||
function Item:new(itemDef)
|
||||
---Adding default parameters
|
||||
assert(itemDef.settings.description == nil,
|
||||
'The item description was specified using `description`, not `_description`. '..
|
||||
'Please note that the `description` field should not be used when registering an item. '..
|
||||
'Use `_title` and `_description` instead.')
|
||||
|
||||
-- Adding default parameters
|
||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||
local s = itemDef.settings
|
||||
|
||||
if s._add_mod_name then
|
||||
s.name = Mod.getInfo().shortName .. ':' .. s.name
|
||||
end
|
||||
|
||||
---@type Item
|
||||
local instance = getInstance(self, {})
|
||||
|
||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||
local visual = itemDef.settings.visual
|
||||
local type = itemDef.settings._type
|
||||
|
||||
if visual == nil then
|
||||
visual = 'item_2d'
|
||||
if type == nil then
|
||||
type = 'craftitem'
|
||||
end
|
||||
|
||||
itemDef.settings.visual = nil
|
||||
itemDef.settings._type = nil
|
||||
|
||||
if visual == 'item_3d' then
|
||||
register3dItem(luantiDef)
|
||||
if type == 'node' then
|
||||
registerNode(luantiDef)
|
||||
elseif type == 'craftitem' then
|
||||
registerCraftitem(luantiDef)
|
||||
elseif type == 'tool' then
|
||||
registerTool(luantiDef)
|
||||
else
|
||||
visual = 'item_2d'
|
||||
registerFlatItem(luantiDef)
|
||||
error(('Unknown item type: `%s`.'):format(type))
|
||||
end
|
||||
|
||||
function instance:getVisual()
|
||||
return visual
|
||||
function instance:getType()
|
||||
return type
|
||||
end
|
||||
|
||||
instance.itemDef = itemDef
|
||||
@@ -132,8 +224,10 @@ end
|
||||
---@param defaultDef Item.ItemDefinition
|
||||
---@return Item
|
||||
function Item:getExtended(defaultDef)
|
||||
defaultDef = defMerge(defaultDef, self.defaultDef, true)
|
||||
|
||||
---@type Item
|
||||
local ChildClass = Class.extend(self, {
|
||||
local ChildClass = extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
@@ -146,6 +240,8 @@ end
|
||||
function Item:getFactory(defaultDef)
|
||||
if defaultDef == nil then
|
||||
defaultDef = self.defaultDef
|
||||
else
|
||||
defaultDef = defMerge(self.defaultDef, defaultDef, true)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
|
||||
@@ -64,4 +64,4 @@ Callbacks.on_use = nil
|
||||
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, node, digparams)?
|
||||
Callbacks.after_use = nil
|
||||
|
||||
return Callbacks
|
||||
return Callbacks
|
||||
|
||||
8
mods/CORE/Item/src/Item/Rarity.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
---Rarity of items:
|
||||
--- * `common`
|
||||
--- * `uncommon`
|
||||
--- * `distinguished`
|
||||
--- * `eminent`
|
||||
--- * `prime`
|
||||
--- * `unique`
|
||||
---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique'
|
||||
@@ -5,38 +5,40 @@ local Settings = {}
|
||||
---@type string
|
||||
Settings.name = ''
|
||||
|
||||
---@type string?
|
||||
Settings.description = nil
|
||||
|
||||
---Whether to add the mod name to the settings.name. Default: `true`
|
||||
---@type boolean?
|
||||
Settings.addModName = nil
|
||||
Settings._add_mod_name = nil
|
||||
|
||||
---Item description. 1st line of item description.
|
||||
---@type string?
|
||||
Settings.title = nil
|
||||
Settings._title = nil
|
||||
|
||||
---Item description. The rest of item description.
|
||||
---@type string?
|
||||
Settings.description = nil
|
||||
Settings._description = nil
|
||||
|
||||
---Item title color in description.
|
||||
---
|
||||
---Default: `#FFFFFF`
|
||||
---@type ColorString?
|
||||
Settings.titleColor = nil
|
||||
Settings._title_color = nil
|
||||
|
||||
---Item description color in description.
|
||||
---
|
||||
---Default: `#C0C0C0`
|
||||
---@type ColorString?
|
||||
Settings.descriptionColor = nil
|
||||
|
||||
---@alias Item.Visual
|
||||
---'item_2d'|
|
||||
---'item_3d'
|
||||
Settings._description_color = nil
|
||||
|
||||
---Visual node type.
|
||||
---@type Item.Visual?
|
||||
Settings.visual = nil
|
||||
---@type Item.Type?
|
||||
Settings._type = nil
|
||||
|
||||
---Formal (lore) rarity of an item. Default `common`.
|
||||
---@type Item.Rarity?
|
||||
Settings._rarity = nil
|
||||
|
||||
|
||||
---Table of groups-characteristics of Item.
|
||||
@@ -183,4 +185,4 @@ Settings.touch_interaction = nil
|
||||
Settings.sound = nil
|
||||
|
||||
|
||||
return Settings
|
||||
return Settings
|
||||
|
||||
1
mods/CORE/Item/src/Item/Type.lua
Normal file
@@ -0,0 +1 @@
|
||||
---@alias Item.Type 'craftitem'|'node'|'tool'
|
||||
@@ -6,6 +6,8 @@ local getInstance = Class.getInstance
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@alias MapGen.factors {height:number, temp:number, humidity:number}
|
||||
|
||||
---@alias MapGen.PastCalcNoiseValue {triangle:MapGen.Triangle?, x:integer?, z:integer?, noiseValue:number?}
|
||||
|
||||
---@type table<MapGen.Layer.Category, MapGen.PastCalcNoiseValue>
|
||||
@@ -133,7 +135,7 @@ end
|
||||
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
||||
---@param layer string|MapGen.Layer The layer or name of the layer in which the peak is located.
|
||||
---@param category MapGen.Layer.Category The category in which the peak is located.
|
||||
---@param pos Position Coordinate of the desired peak.
|
||||
---@param pos MapPosition Coordinate of the desired peak.
|
||||
---@return MapGen.Peak?
|
||||
function MapGen:getPeakByPos(layer, category, pos)
|
||||
if type(layer) == 'string' then
|
||||
@@ -177,7 +179,7 @@ end
|
||||
---**Important:** works only in the XZ plane.
|
||||
---@param layer string|MapGen.Layer The layer or name of the layer the triangle is in.
|
||||
---@param category MapGen.Layer.Category The category in which the triangle is in.
|
||||
---@param pos Position Coordinate of the desired peak.
|
||||
---@param pos MapPosition Coordinate of the desired peak.
|
||||
---@return MapGen.Triangle?
|
||||
function MapGen:getTriangleByPos2D(layer, category, pos)
|
||||
if type(layer) == 'string' then
|
||||
@@ -196,7 +198,7 @@ end
|
||||
---If the point is inside the region, it will also return the distance to the nearest border.
|
||||
---@param layer MapGen.Layer The name of the layer in which the region is located.
|
||||
---@param regionName string The name of the region in which the location of the point is checked.
|
||||
---@param point Position Point position.
|
||||
---@param point MapPosition Point position.
|
||||
---@return boolean, number?
|
||||
function MapGen:pointInRegion2D(layer, regionName, point)
|
||||
local region = layer.regionsByName[regionName]
|
||||
@@ -315,7 +317,7 @@ function MapGen:getTriangulateBoundaryVertices(triangles)
|
||||
end
|
||||
|
||||
-- Walk along boundary edges to create ordered vertex list
|
||||
---@type Position[]
|
||||
---@type MapPosition[]
|
||||
local boundary = {}
|
||||
---@type table<string, boolean>
|
||||
local visited = {}
|
||||
@@ -425,9 +427,9 @@ end
|
||||
function MapGen:registerPeak(layerName, category, def)
|
||||
local layer = self:getLayerByName(layerName)
|
||||
|
||||
assert(self:getPeakByPos(layer, category, def.pos) == nil,
|
||||
('In the `%s` layer in the `%s` category there is already a peak with coordinates: %s, %s, %s.'):format(
|
||||
layerName, category, def.pos.x, def.pos.y, def.pos.z))
|
||||
--assert(self:getPeakByPos(layer, category, def.pos) == nil,
|
||||
--('In the `%s` layer in the `%s` category there is already a peak with coordinates: %s, %s, %s.'):format(
|
||||
-- layerName, category, def.pos.x, def.pos.y, def.pos.z))
|
||||
|
||||
---@type MapGen.Peak
|
||||
local peak = Peak:new(def)
|
||||
@@ -473,7 +475,7 @@ end
|
||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
||||
---@param map string The name of the image from which the peaks will be extracted. It should be located in the `<mod_name>/textures/maps` folder and have the following format `<image_name>.ff`
|
||||
---@param scale number Multiplier of how many blocks (nodes) will be between image pixels. It is not recommended to set the value below 50 for performance reasons.
|
||||
---@param zeroPos Position2d The position in pixels where the zero world coordinate will be in the image.
|
||||
---@param zeroPos IntegerPosition2d The position in pixels where the zero world coordinate will be in the image.
|
||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
||||
---@param groups? table<string, number> Groups that will be added to all peaks.
|
||||
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
|
||||
@@ -495,16 +497,17 @@ function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category,
|
||||
|
||||
for color, peaksPos in pairs(peaks) do
|
||||
for _, peakPos in ipairs(peaksPos) do
|
||||
---@type integer, integer
|
||||
x, z = (peakPos.x - zeroPos.x - 1) * scale, (peakPos.y - zeroPos.y - 1) * -scale
|
||||
|
||||
-- Converting a rectangular grid into an isometric-like one.
|
||||
if peakPos.y % 2 == 1 then
|
||||
x = x + (scale/2)
|
||||
x = mathRound(x + (scale/2))
|
||||
end
|
||||
|
||||
---@type MapGen.PeakDef
|
||||
local def = {
|
||||
pos = vector.new(x, 0, z),
|
||||
pos = {x=x, y=0, z=z},
|
||||
color = color,
|
||||
groups = groups,
|
||||
}
|
||||
@@ -518,7 +521,7 @@ end
|
||||
---If the peak does not exist, an error will be raised.
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
||||
---@param pos Position The position of the peak to which the group should be added.
|
||||
---@param pos MapPosition The position of the peak to which the group should be added.
|
||||
---@param groups table<string, number> Groups to be added.
|
||||
function MapGen:addGroupsToPeakByPos(layerName, category, pos, groups)
|
||||
local layer = self:getLayerByName(layerName)
|
||||
@@ -546,7 +549,7 @@ end
|
||||
---@param layerName string The name of the layer in which the new cavern will be included.
|
||||
---@param cavernName string The name to be assigned to the cavern. The name must be unique for each cavern.
|
||||
---@param def MapGen.CavernDef Cavern description table, see details `MapGen.CavernDef`
|
||||
---@param regionVertices Position[]? The region to which the cave generation will be limited.
|
||||
---@param regionVertices MapPosition[]? The region to which the cave generation will be limited.
|
||||
function MapGen:registerCavern(layerName, cavernName, def, regionVertices)
|
||||
local layer = self:getLayerByName(layerName)
|
||||
|
||||
@@ -648,26 +651,58 @@ end
|
||||
|
||||
-- --- GENERATION METHODS ---
|
||||
|
||||
---The core logic of world generation. Determines which node type (water, rock, soil, air)
|
||||
---and which biome will be generated at the specified coordinates.
|
||||
---@alias MapGen.nodeType 'AIR'|'WATER'|'CAVERN_AIR'|'TURF'|'SOIL'|'ROCK'|'BOTTOM'
|
||||
---@alias MapGen.postProcessingData {biome:MapGen.Biome, mapGenerator:MapGen, factors:MapGen.factors, data:number[], index:number, x:number, y:number, z:number, nodeType:MapGen.nodeType}
|
||||
|
||||
---@type table<number, MapGen.postProcessingData>
|
||||
local postProcessing = {}
|
||||
|
||||
---@param biome MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param layer MapGen.Layer
|
||||
---@param height number
|
||||
---@param temp number
|
||||
---@param humidity number
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@param z integer
|
||||
local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z)
|
||||
---@param nodeType MapGen.nodeType
|
||||
local function addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, nodeType)
|
||||
if biome.postProcessing == nil then
|
||||
return
|
||||
end
|
||||
|
||||
postProcessing[index] = {
|
||||
biome = biome,
|
||||
mapGenerator = mapGenerator,
|
||||
factors = factors,
|
||||
data = data,
|
||||
index = index,
|
||||
x = x,
|
||||
y = y,
|
||||
z = z,
|
||||
nodeType = nodeType
|
||||
}
|
||||
end
|
||||
|
||||
---The core logic of world generation. Determines which node type (water, rock, soil, air)
|
||||
---and which biome will be generated at the specified coordinates.
|
||||
---@param mapGenerator MapGen
|
||||
---@param layer MapGen.Layer
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@param z integer
|
||||
local function generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
||||
local ids = mapGenerator.nodeIDs
|
||||
local waterLevel = layer.waterLevel
|
||||
local height, temp, humidity = factors.height, factors.temp, factors.humidity
|
||||
|
||||
-- Creating a rougher biome boundary.
|
||||
local scatteringGorizontal = layer.biomesGorizontalScattering or 0
|
||||
local scatteringVertical = layer.biomesVerticalScattering or 0
|
||||
local scattTemp = temp
|
||||
local scattTemp = factors.temp
|
||||
local scattHumidity = humidity
|
||||
---@type number
|
||||
local scattHeight = y
|
||||
@@ -694,33 +729,39 @@ local function generateNode(mapGenerator, layer, height, temp, humidity, data, i
|
||||
-- If the block is above surface height and above water level...
|
||||
if y > height and y > waterLevel then
|
||||
-- ... then airspace is generated.
|
||||
biome:generateAir(mapGenerator, data, index, x, y, z)
|
||||
biome:generateAir(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'AIR')
|
||||
|
||||
-- If the block is above the surface height BUT below the water level...
|
||||
elseif y > height and y <= waterLevel then
|
||||
-- ... then underwater space is generated.
|
||||
biome:generateWater(mapGenerator, data, index, x, y, z)
|
||||
biome:generateWater(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'WATER')
|
||||
|
||||
-- If the block is below the surface height...
|
||||
elseif y <= height then
|
||||
-- ... and a cavern is generated in the block...
|
||||
if mapGenerator:isCavern(layer, x, y, z) then
|
||||
-- ... then airspace is generated.
|
||||
biome:generateCavernAir(mapGenerator, data, index, x, y, z)
|
||||
biome:generateCavernAir(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'CAVERN_AIR')
|
||||
|
||||
-- ... or if the surface height is above the water level...
|
||||
elseif height > waterLevel then
|
||||
--- ... and the height of the block is equal to the height of the surface...
|
||||
if y == height then
|
||||
-- ... then turf is generated.
|
||||
biome:generateTurf(mapGenerator, data, index, x, y, z)
|
||||
biome:generateTurf(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'TURF')
|
||||
-- ... or if the height of the block falls within the thickness of the soil layer...
|
||||
elseif y > height - biome.soilHeight then
|
||||
-- ... then soil is generated.
|
||||
biome:generateSoil(mapGenerator, data, index, x, y, z)
|
||||
biome:generateSoil(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'SOIL')
|
||||
else
|
||||
-- ... else e a stone is generated.
|
||||
biome:generateRock(mapGenerator, data, index, x, y, z)
|
||||
-- ... else a stone is generated.
|
||||
biome:generateRock(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'ROCK')
|
||||
end
|
||||
|
||||
-- ... or if the surface height is below the water level...
|
||||
@@ -728,10 +769,12 @@ local function generateNode(mapGenerator, layer, height, temp, humidity, data, i
|
||||
-- ... and if the height of the block falls within the thickness of the soil layer...
|
||||
if y > height - biome.soilHeight then
|
||||
-- ... then the river/ocean bottom is generated.
|
||||
biome:generateBottom(mapGenerator, data, index, x, y, z)
|
||||
biome:generateBottom(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'BOTTOM')
|
||||
else
|
||||
-- ... else a stone is generated.
|
||||
biome:generateRock(mapGenerator, data, index, x, y, z)
|
||||
biome:generateRock(mapGenerator, factors, data, index, x, y, z)
|
||||
addPostProccessing(biome, mapGenerator, factors, data, index, x, y, z, 'ROCK')
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -1018,13 +1061,20 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||
noiseTempValue = layer:calcTemp(noiseTempValue, y)
|
||||
noiseHumidityValue = layer:calcHumidity(noiseHumidityValue, y)
|
||||
|
||||
generateNode(mapGenerator, layer, noiseHeightValue, noiseTempValue, noiseHumidityValue, data, index, x, y, z)
|
||||
---@type MapGen.factors
|
||||
local factors = {
|
||||
height = noiseHeightValue,
|
||||
temp = noiseTempValue,
|
||||
humidity = noiseHumidityValue,
|
||||
}
|
||||
|
||||
generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---Chunk generation handler.
|
||||
---@param voxelManip VoxelManip
|
||||
---@param minPos Position
|
||||
---@param maxPos Position
|
||||
---@param minPos MapPosition
|
||||
---@param maxPos MapPosition
|
||||
---@param blockseed number
|
||||
function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
-- We obtain a generation area for further manipulations
|
||||
@@ -1058,6 +1108,21 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
end
|
||||
end
|
||||
|
||||
-- Post-proccesing generation
|
||||
for _, ppdata in pairs(postProcessing) do
|
||||
if ppdata.biome.postProcessing ~= nil then
|
||||
ppdata.biome:postProcessing(ppdata.mapGenerator,
|
||||
ppdata.factors,
|
||||
ppdata.data,
|
||||
ppdata.index,
|
||||
ppdata.x,
|
||||
ppdata.y,
|
||||
ppdata.z,
|
||||
ppdata.nodeType,
|
||||
area)
|
||||
end
|
||||
end
|
||||
|
||||
-- We make changes back to LVM and recalculate light & liquids
|
||||
voxelManip:set_data(data)
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ local getInstance = Class.getInstance
|
||||
---@field generateTurf generateFunc
|
||||
---@field generateSoil generateFunc
|
||||
---@field generateBottom generateFunc
|
||||
---@field postProcessing fun(self, mapGenerator:MapGen, factors:MapGen.factors, data:number[], index:number, x:number, y:number, z:number, nodeType:MapGen.nodeType, area:VoxelArea)?
|
||||
local Biome = {}
|
||||
|
||||
---@alias generateFunc fun(self, mapGenerator:MapGen, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@alias generateFunc fun(self, mapGenerator:MapGen, factors:MapGen.factors, data:number[], index:number, x:number, y:number, z:number)
|
||||
|
||||
---Definition table for the `MapGen.Biome`.
|
||||
---
|
||||
@@ -39,84 +40,91 @@ local Biome = {}
|
||||
---@field generateTurf generateFunc?
|
||||
---@field generateSoil generateFunc?
|
||||
---@field generateBottom generateFunc?
|
||||
|
||||
---@field postProcessing fun(self, mapGenerator:MapGen, factors:MapGen.factors, data:number[], index:number, x:number, y:number, z:number, nodeType:MapGen.nodeType, area:VoxelArea)?
|
||||
|
||||
-- Default generate functions
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateAir = function(self, mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateAir = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = mapGenerator.nodeIDs.air
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateCavernAir = function(self, mapGenerator, data, index, x, y, z)
|
||||
self:generateAir(mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateCavernAir = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
self:generateAir(mapGenerator, factors, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateWater = function(self, mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateWater = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = mapGenerator.nodeIDs.water
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateRock = function(self, mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateRock = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = self.groundNodesIDs.rock
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateTurf = function(self, mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateTurf = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = self.groundNodesIDs.turf
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateSoil = function(self, mapGenerator,data, index, x, y, z)
|
||||
local defaultGenerateSoil = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = self.groundNodesIDs.soil
|
||||
end
|
||||
|
||||
---@param self MapGen.Biome
|
||||
---@param mapGenerator MapGen
|
||||
---@param factors MapGen.factors
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
local defaultGenerateBottom = function(self, mapGenerator, data, index, x, y, z)
|
||||
local defaultGenerateBottom = function(self, mapGenerator, factors, data, index, x, y, z)
|
||||
data[index] = self.groundNodesIDs.bottom
|
||||
end
|
||||
|
||||
@@ -167,23 +175,23 @@ function Biome:new(name, def)
|
||||
end
|
||||
|
||||
---@type MapGen.Biome
|
||||
local instance = getInstance(self, {
|
||||
name = name,
|
||||
tempPoint = def.tempPoint,
|
||||
humidityPoint = def.humidityPoint,
|
||||
minY = def.minY,
|
||||
maxY = def.maxY,
|
||||
groundNodes = def.groundNodes,
|
||||
groundNodesIDs = groundNodesIDs,
|
||||
soilHeight = def.soilHeight,
|
||||
generateAir = def.generateAir,
|
||||
generateCavernAir = def.generateCavernAir,
|
||||
generateWater = def.generateWater,
|
||||
generateRock = def.generateRock,
|
||||
generateSoil = def.generateSoil,
|
||||
generateTurf = def.generateTurf,
|
||||
generateBottom = def.generateBottom,
|
||||
})
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.tempPoint = def.tempPoint
|
||||
instance.humidityPoint = def.humidityPoint
|
||||
instance.minY = def.minY
|
||||
instance.maxY = def.maxY
|
||||
instance.groundNodes = def.groundNodes
|
||||
instance.groundNodesIDs = groundNodesIDs
|
||||
instance.soilHeight = def.soilHeight
|
||||
instance.generateAir = def.generateAir
|
||||
instance.generateCavernAir = def.generateCavernAir
|
||||
instance.generateWater = def.generateWater
|
||||
instance.generateRock = def.generateRock
|
||||
instance.generateSoil = def.generateSoil
|
||||
instance.generateTurf = def.generateTurf
|
||||
instance.generateBottom = def.generateBottom
|
||||
instance.postProcessing = def.postProcessing
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -16,14 +16,14 @@ local Peak = {
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGen.PeakDef
|
||||
---@field pos vector
|
||||
---@field pos MapPosition|vector
|
||||
---@field color ColorString
|
||||
---@field groups? table<string, number>
|
||||
|
||||
---@param def MapGen.PeakDef
|
||||
---@return MapGen.Peak
|
||||
function Peak:new(def)
|
||||
local _pos = def.pos
|
||||
local _pos = vector.new(def.pos)
|
||||
local _color = def.color
|
||||
local _groups
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ local getInstance = Class.getInstance
|
||||
|
||||
---@class MapGen.Region
|
||||
---@field name string
|
||||
---@field vertices Position[]
|
||||
---@field vertices MapPosition[]
|
||||
local Region = {}
|
||||
|
||||
---@class MapGen.RegionDef
|
||||
---@field vertices Position[]
|
||||
---@field vertices MapPosition[]
|
||||
|
||||
---@param def MapGen.RegionDef
|
||||
---@return MapGen.Region
|
||||
@@ -50,7 +50,7 @@ local function calcDistanceSq(px, pz, x1, z1, x2, z2)
|
||||
end
|
||||
|
||||
---Checks if a point is inside a `MapGen.Region` (2D check using x and z coordinates).
|
||||
---@param point Position
|
||||
---@param point MapPosition
|
||||
---@return boolean, number?
|
||||
function Region:pointInRegion(point)
|
||||
local vertices = self.vertices
|
||||
|
||||
@@ -8,7 +8,7 @@ local getInstance = Class.getInstance
|
||||
---@field maxY number
|
||||
---@field staticNode string
|
||||
---@field staticNodeID number
|
||||
---@field generateStaticNode generateFunc
|
||||
---@field generateStaticNode fun(self, mapGenerator:MapGen, data:number[], index:number, x:number, y:number, z:number)
|
||||
local StaticLayer = {}
|
||||
|
||||
---Definition table for the `MapGen.StaticLayer`.
|
||||
@@ -18,7 +18,7 @@ local StaticLayer = {}
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field staticNode string
|
||||
---@field generateStaticNode generateFunc
|
||||
---@field generateStaticNode fun(self, mapGenerator:MapGen, data:number[], index:number, x:number, y:number, z:number)
|
||||
|
||||
---@param self MapGen.StaticLayer
|
||||
---@param mapGenerator MapGen
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
---@diagnostic disable: param-type-not-match
|
||||
local mathAbs = math.abs
|
||||
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
---@diagnostic disable: param-type-not-match
|
||||
-- Tringulation lib
|
||||
-- Original code: https://github.com/iskolbin/Triangulation/blob/master/Triangulation.lua
|
||||
-- Date of copying: 07.11.2025
|
||||
|
||||
@@ -14,7 +14,7 @@ local FakePeak = Class.extend(Peak, {})
|
||||
|
||||
---Returns a fake `MapGen.Peak` that has no noise parameters.
|
||||
---Note that the initialized peak should not be used in generation.
|
||||
---@param peakPos vector
|
||||
---@param peakPos MapPosition|vector
|
||||
---@return MapGen.Peak
|
||||
function FakePeak:new(peakPos)
|
||||
local instance = Peak:new({pos = peakPos, color = '#000000'})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__node')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('Node')
|
||||
return require('Node')
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
local itemRequire = Mod.getInfo('smc__core__item').require
|
||||
|
||||
---@type Item
|
||||
local Item = itemRequire('Item')
|
||||
|
||||
---@type ItemFactory
|
||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
|
||||
|
||||
---@class Node : Item
|
||||
---@field defaultDef Node.NodeDefinition
|
||||
@@ -22,7 +16,7 @@ function Node:new(nodeDef)
|
||||
---Adding default parameters
|
||||
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
||||
|
||||
nodeDef.settings.visual = 'item_3d'
|
||||
nodeDef.settings._type = 'node'
|
||||
|
||||
---@type Node
|
||||
local instance = Item:new(nodeDef)
|
||||
@@ -35,6 +29,8 @@ end
|
||||
---@param defaultDef Node.NodeDefinition
|
||||
---@return Node
|
||||
function Node:getExtended(defaultDef)
|
||||
defaultDef = defMerge(defaultDef, self.defaultDef)
|
||||
|
||||
---@type Node
|
||||
local ChildClass = Class.extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
@@ -49,6 +45,8 @@ end
|
||||
function Node:getFactory(defaultDef)
|
||||
if defaultDef == nil then
|
||||
defaultDef = self.defaultDef
|
||||
else
|
||||
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
@@ -57,4 +55,4 @@ function Node:getFactory(defaultDef)
|
||||
return instance
|
||||
end
|
||||
|
||||
return Node
|
||||
return Node
|
||||
|
||||
@@ -187,4 +187,4 @@ Callbacks.on_metadata_inventory_take = nil
|
||||
---@type (fun(pos:Position, intensity:number): void)?
|
||||
Callbacks.on_blast = nil
|
||||
|
||||
return Callbacks
|
||||
return Callbacks
|
||||
|
||||
@@ -337,4 +337,4 @@ Settings.sounds = nil
|
||||
---@type (table|string)?
|
||||
Settings.drop = nil
|
||||
|
||||
return Settings
|
||||
return Settings
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
local nodeRequire = Mod.getInfo('smc__core__node').require
|
||||
|
||||
---@type Node
|
||||
local Node = nodeRequire('Node')
|
||||
|
||||
-- -@type ItemFactory
|
||||
---local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
---@class Plant : Node
|
||||
local Plant = Node:getExtended({
|
||||
@@ -24,4 +18,4 @@ local Plant = Node:getExtended({
|
||||
}
|
||||
})
|
||||
|
||||
return Plant
|
||||
return Plant
|
||||
|
||||
4
mods/CORE/Tool/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__tool')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('Tool')
|
||||
2
mods/CORE/Tool/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__core__tool
|
||||
depends = smc__core__item
|
||||
70
mods/CORE/Tool/src/Tool.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
|
||||
|
||||
---@class Tool : Item
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
local Tool = Class.extend(Item, {})
|
||||
|
||||
---The alias `table.merge` for EmmyLua
|
||||
---@type fun(...):(Item.ItemDefinition)
|
||||
local defMerge = function(...)
|
||||
return table.merge(...)
|
||||
end
|
||||
|
||||
---@param ToolDef Item.ItemDefinition
|
||||
---@return Tool
|
||||
function Tool:new(ToolDef)
|
||||
---Adding default parameters
|
||||
ToolDef = defMerge(ToolDef, self.defaultDef, true)
|
||||
|
||||
ToolDef.settings._type = 'tool'
|
||||
|
||||
---@type Tool
|
||||
local instance = Item:new(ToolDef)
|
||||
return instance
|
||||
end
|
||||
|
||||
---Allows you to create a child class of an tool by specifying
|
||||
---default parameters that will be added to the tool's parameters
|
||||
---when an instance is received.
|
||||
---@param defaultDef Item.ItemDefinition
|
||||
---@return Tool
|
||||
function Tool:getExtended(defaultDef)
|
||||
defaultDef = defMerge(defaultDef, self.defaultDef)
|
||||
|
||||
---@type Tool
|
||||
local ChildClass = Class.extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
return ChildClass
|
||||
end
|
||||
|
||||
---Returns an instance of the `ItemFactory` class that can be used to mass-register identical items.
|
||||
---@param defaultDef? Item.ItemDefinition
|
||||
---@return ItemFactory
|
||||
function Tool:getFactory(defaultDef)
|
||||
if defaultDef == nil then
|
||||
defaultDef = self.defaultDef
|
||||
else
|
||||
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
local instance = ItemFactory:new(self, defaultDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
--[[
|
||||
Tool:new({
|
||||
settings = {
|
||||
name = 'tool',
|
||||
inventory_image = 'anoba.png',
|
||||
tool_capabilities = {
|
||||
groupcaps={
|
||||
crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
|
||||
},
|
||||
}
|
||||
}
|
||||
})--]]
|
||||
|
||||
return Tool
|
||||
4
mods/CORE/WorkStation/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__work_station')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('WorkStation')
|
||||
2
mods/CORE/WorkStation/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__core__work_station
|
||||
depends = smc__core__craft_system, smc__core__node, smc__ui__work_station
|
||||
258
mods/CORE/WorkStation/src/WorkStation.lua
Normal file
@@ -0,0 +1,258 @@
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
---@type CraftSystem.ImmersiveCraftHandler
|
||||
local ImmersiveCraftHandler = Mod.getInfo('smc__core__craft_system').require('CraftSystem.ImmersiveCraftHandler')
|
||||
|
||||
---@type WorkStationUI
|
||||
local WorkStationUI = Mod.getInfo('smc__ui__work_station').require('WorkStationUI')
|
||||
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
-- Default settings that a work station node should have.
|
||||
local WorkStationNode = Node:getExtended({
|
||||
settings = {
|
||||
name = 'work_station',
|
||||
drawtype = 'normal',
|
||||
paramtype = 'light',
|
||||
groups = {work_station = 1, dig_immediate = 2,}
|
||||
}
|
||||
})
|
||||
|
||||
---A work station (node) that enables player interaction
|
||||
---with the immersive crafting mechanics.
|
||||
---@class WorkStation
|
||||
---@field name string
|
||||
---@field group CraftSystem.CraftGroup
|
||||
---@field nodeDef Node.NodeDefinition
|
||||
local WorkStation = {}
|
||||
|
||||
---Definition table for the `CraftSystem.WorkStation`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class WorkStationDef
|
||||
---@field group CraftSystem.CraftGroup
|
||||
---@field nodeDef Node.NodeDefinition
|
||||
|
||||
---@param name string
|
||||
---@param def WorkStationDef
|
||||
function WorkStation:new(name, def)
|
||||
local nodeDef = def.nodeDef
|
||||
if nodeDef.callbacks == nil then
|
||||
---@type Node.Callbacks
|
||||
nodeDef.callbacks = {}
|
||||
end
|
||||
local settings = nodeDef.settings
|
||||
local callbacks = nodeDef.callbacks
|
||||
|
||||
-- Callback when the work station block is installed in the world
|
||||
-- Ensures initialization of necessary parameters
|
||||
callbacks.on_construct = function(pos)
|
||||
-- Getting node metadata
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
-- Initializing the table of temporary parameters for crafting.
|
||||
Smc.setCraftDataByMeta(meta)
|
||||
end
|
||||
|
||||
-- Callback for interaction with a work station (start of crafting)
|
||||
callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
-- If the workstation is occupied by another craft...
|
||||
if not Smc.workStationIsFree(pos) then
|
||||
-- ...we inform the player about this...
|
||||
core.chat_send_player(clicker:get_player_name(), 'The workbench is occupied by another craft.')
|
||||
-- ...and do nothing.
|
||||
return
|
||||
end
|
||||
|
||||
-- We get a list of crafts that can be produced using the item that the player was holding in his hand.
|
||||
local crafts = ImmersiveCraftHandler:getCraftsByTriggerItem(itemstack:get_name())
|
||||
|
||||
-- If the list is empty...
|
||||
if crafts == nil then
|
||||
-- ..this means there are no crafts for this item,
|
||||
-- so we don't do anything.
|
||||
return
|
||||
else
|
||||
-- ...else we show the player the formspec for choosing a craft.
|
||||
self:showSelectionCraftForm(clicker, crafts, pos)
|
||||
end
|
||||
end
|
||||
|
||||
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if Smc.workStationIsFree(pos) then
|
||||
return
|
||||
end
|
||||
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
local craft = ImmersiveCraftHandler:getCraftByName(craftData.craftName)
|
||||
craft:abortCraft(pos)
|
||||
end
|
||||
|
||||
callbacks.on_dig = function(pos, node, digger)
|
||||
if Smc.workStationIsFree(pos) then
|
||||
return core.node_dig(pos, node, digger)
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
---@type WorkStation
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.group = def.group
|
||||
instance.nodeDef = nodeDef
|
||||
|
||||
-- Registering a node for Luanti.
|
||||
WorkStationNode:new(nodeDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Show the player the initial workstation interface for choosing a craft.
|
||||
---@param player Player
|
||||
---@param crafts CraftSystem.ImmersiveCraft[]
|
||||
---@param pos Position
|
||||
function WorkStation:showSelectionCraftForm(player, crafts, pos)
|
||||
-- Create a table in the format craft result - craft name.
|
||||
local outputs = {}
|
||||
for _, craft in ipairs(crafts) do
|
||||
-- TODO: добавить проверку только на известные игроку рецепты
|
||||
outputs[craft.output] = craft.name
|
||||
end
|
||||
|
||||
-- We get the name of the player who wants to start crafting.
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
-- We set the context for transferring data about the workstation coordinates and the list of crafts.
|
||||
WorkStationUI:setContex(playerName, 'pos', pos)
|
||||
WorkStationUI:setContex(playerName, 'outputs', outputs)
|
||||
|
||||
-- Showing the desktop interface to the player.
|
||||
WorkStationUI:showForm(playerName,false)
|
||||
end
|
||||
|
||||
-- Registering a callback for player choice of craft (this does not start crafting).
|
||||
WorkStationUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, fieldName, fieldValue)
|
||||
-- We get the name of the craft from the name of the button the player pressed.
|
||||
local craftName = string.match(fieldName, '(%S+)::item_button')
|
||||
assert(craftName ~= nil, 'Craft name cannot be empty')
|
||||
|
||||
-- We get a craft object.
|
||||
local craft = ImmersiveCraftHandler:getCraftByName(craftName)
|
||||
-- We get the name of the player who wants to start crafting.
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
-- We enter into the context the craft that the player has chosen.
|
||||
WorkStationUI:setContex(playerName, 'craft', craft)
|
||||
-- We show the player a new interface with a crafting description tab.
|
||||
WorkStationUI:showForm(playerName, true)
|
||||
end)
|
||||
|
||||
-- We register a callback when the player starts crafting.
|
||||
WorkStationUI:registerOnFormFieldAction('work_station:start_craft', function(player, fieldName, fieldValue)
|
||||
-- We get the name of the player who wants to start crafting.
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
-- We get the workstation position and craft from the context.
|
||||
local pos = WorkStationUI:getContex(playerName, 'pos')
|
||||
---@type CraftSystem.ImmersiveCraft
|
||||
local craft = WorkStationUI:getContex(playerName, 'craft')
|
||||
|
||||
|
||||
-- We process the amount of crafting.
|
||||
local isCraftStart = false
|
||||
if fieldValue == 'x1' then
|
||||
-- Single craft
|
||||
isCraftStart = craft:startCraft(pos, player, 1)
|
||||
elseif fieldValue == 'x10' then
|
||||
-- Ten crafts at a time.
|
||||
isCraftStart = craft:startCraft(pos, player, 10)
|
||||
end
|
||||
|
||||
-- If the craft was started...
|
||||
if isCraftStart then
|
||||
-- ...we are closing the formspec.
|
||||
WorkStationUI:closeForm(playerName)
|
||||
end
|
||||
end)
|
||||
|
||||
-- --- DEBUG ---
|
||||
|
||||
WorkStation:new('test_station', {
|
||||
group = 'test',
|
||||
nodeDef = {
|
||||
settings = {
|
||||
name = 'test_station',
|
||||
tiles = {'test_station.png'}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
ImmersiveCraftHandler:registerCraft('bricks', {
|
||||
triggerItem = 'rocks:sylite',
|
||||
output = 'rocks:sylite_bricks',
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'rocks:sylite',
|
||||
type = 'tapping',
|
||||
clicksNeed = 3,
|
||||
nextStage = 'tapping_2',
|
||||
},
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping_2',
|
||||
toolGroup = 'crushing',
|
||||
targetItem = 'rocks:sylite_block',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
nextStage = 'tapping_3',
|
||||
},
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping_3',
|
||||
targetItem = 'rocks:sylite_bricks',
|
||||
type = 'tapping',
|
||||
clicksNeed = 1,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
ImmersiveCraftHandler:registerCraft('block', {
|
||||
triggerItem = 'rocks:sylite',
|
||||
output = 'rocks:sylite_block',
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'rocks:sylite',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
ImmersiveCraftHandler:registerCraft('marentine_planks', {
|
||||
triggerItem = 'wood:marentine_log',
|
||||
output = 'wood:marentine_planks',
|
||||
startStageName = 'tapping',
|
||||
group = 'test',
|
||||
stages = {
|
||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
|
||||
{
|
||||
name = 'tapping',
|
||||
targetItem = 'wood:marentine_log',
|
||||
type = 'tapping',
|
||||
clicksNeed = 5,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return WorkStation
|
||||
BIN
mods/CORE/WorkStation/textures/test_station.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
@@ -1,73 +0,0 @@
|
||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type Formspec
|
||||
local Formspec = require('Formspec')
|
||||
|
||||
local listForm = Formspec:new({
|
||||
size = {x=21, y=12},
|
||||
})
|
||||
|
||||
listForm:list('current_player', 'main', 10.5, 6.5, 8, 4)
|
||||
|
||||
local listFormItems = Formspec:new()
|
||||
|
||||
local items = table.get_keys(core.registered_nodes)
|
||||
table.sort(items)
|
||||
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
|
||||
|
||||
--listFormItems:list('current_player', 'main', 0, 0, 1, 32)
|
||||
|
||||
listForm:
|
||||
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')
|
||||
|
||||
core.register_chatcommand('list', {
|
||||
privs = {server = true},
|
||||
|
||||
func = function(name, param)
|
||||
local player = core.get_player_by_name(name)
|
||||
|
||||
core.show_formspec(name, 'admin_commands:list_form', listForm:toString())
|
||||
|
||||
return true, ''
|
||||
end
|
||||
})
|
||||
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= 'admin_commands:list_form' then
|
||||
return
|
||||
end
|
||||
|
||||
for key, value in pairs(fields) do
|
||||
if string.ends_with(key, '::item_button') then
|
||||
---@type ItemStackString?
|
||||
local stack = string.match(key, '(%S+)::item_button')
|
||||
|
||||
if stack == nil then
|
||||
return
|
||||
end
|
||||
|
||||
core.log(tostring(stack))
|
||||
|
||||
---@type InvRef
|
||||
local inv = player:get_inventory()
|
||||
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -1,2 +0,0 @@
|
||||
name = smc__core__admin_commands
|
||||
depends = smc__system__system_loader, smc__core__formspec, smc__core__item
|
||||
@@ -214,7 +214,7 @@ local rocksNoiseParams ={
|
||||
lacunarity = 4,
|
||||
}
|
||||
|
||||
local function generateRock(biome, mapGenerator, data, index, x, y, z)
|
||||
local function generateRock(biome, mapGenerator, factors, data, index, x, y, z)
|
||||
local ids = mapGenerator.nodeIDs
|
||||
|
||||
if rocksNoise == nil then
|
||||
@@ -249,7 +249,7 @@ local function generateRock(biome, mapGenerator, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---@param biome MapGen.Biome
|
||||
local function generateSoil(biome, mapGenerator, data, index, x, y, z)
|
||||
local function generateSoil(biome, mapGenerator, factors, data, index, x, y, z)
|
||||
local ids = mapGenerator.nodeIDs
|
||||
if rocksNoise == nil then
|
||||
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
||||
@@ -269,7 +269,7 @@ local function generateSoil(biome, mapGenerator, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---@param biome MapGen.Biome
|
||||
local function generateTurf(biome, mapGenerator, data, index, x, y, z)
|
||||
local function generateTurf(biome, mapGenerator, factors, data, index, x, y, z)
|
||||
local ids = mapGenerator.nodeIDs
|
||||
if rocksNoise == nil then
|
||||
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
||||
@@ -288,6 +288,22 @@ local function generateTurf(biome, mapGenerator, data, index, x, y, z)
|
||||
end
|
||||
end
|
||||
|
||||
---@param area VoxelArea
|
||||
local function postProcessing(biome, mapGenerator, factors, data, index, x, y, z, nodeType, area)
|
||||
local trufID = biome.groundNodesIDs.turf
|
||||
local waterID = mapGenerator.nodeIDs.water
|
||||
if data[index] ~= trufID then
|
||||
return
|
||||
end
|
||||
|
||||
if (data[area:index(x+1, y, z)] == trufID or data[area:index(x+1, y, z)] == waterID) and
|
||||
(data[area:index(x-1, y, z)] == trufID or data[area:index(x-1, y, z)] == waterID) and
|
||||
(data[area:index(x, y, z+1)] == trufID or data[area:index(x, y, z+1)] == waterID) and
|
||||
(data[area:index(x, y, z-1)] == trufID or data[area:index(x, y, z-1)] == waterID) then
|
||||
data[index] = mapGenerator.nodeIDs.water
|
||||
end
|
||||
end
|
||||
|
||||
mapGenerator:registerBiome('midgard', 'swamp', {
|
||||
tempPoint = 0,
|
||||
humidityPoint = 80,
|
||||
@@ -303,6 +319,7 @@ mapGenerator:registerBiome('midgard', 'swamp', {
|
||||
generateRock = generateRock,
|
||||
generateTurf = generateTurf,
|
||||
generateSoil = generateSoil,
|
||||
postProcessing = postProcessing
|
||||
})
|
||||
|
||||
return mapGenerator
|
||||
@@ -1,3 +1,3 @@
|
||||
name = smc__game__items__items_loader
|
||||
description = Include this mod in your `depends` to ensure all items are registered
|
||||
depends = smc__game__items__rocks, smc__game__items__wood, smc__game__items__soils, smc__game__items__liquids
|
||||
depends = smc__game__items__rocks, smc__game__items__wood, smc__game__items__soils, smc__game__items__liquids, smc__game__items__plants
|
||||
|
||||
35
mods/GAME/ITEMS/essences/init.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
local Item, TileSheet = Smc.requireItem(), Smc.requireTileSheet()
|
||||
|
||||
---@type Item.ItemDefinition
|
||||
local defaultEssenceDef = {
|
||||
settings = {
|
||||
name = '',
|
||||
_rarity = 'uncommon',
|
||||
stack_max = 32,
|
||||
}
|
||||
}
|
||||
|
||||
local defaultEssence = Item:getExtended(defaultEssenceDef)
|
||||
|
||||
local ts = TileSheet:new('essences_sheet.png', 16, 16)
|
||||
|
||||
defaultEssence:new({
|
||||
settings = {
|
||||
name = 'essence_experience',
|
||||
inventory_image = ts:t(0, 0)
|
||||
}
|
||||
})
|
||||
|
||||
defaultEssence:new({
|
||||
settings = {
|
||||
name = 'essence_spell',
|
||||
inventory_image = ts:t(1, 0)
|
||||
}
|
||||
})
|
||||
|
||||
defaultEssence:new({
|
||||
settings = {
|
||||
name = 'essence_life',
|
||||
inventory_image = ts:t(2, 0)
|
||||
}
|
||||
})
|
||||
10
mods/GAME/ITEMS/essences/locale/essences.ru.tr
Normal file
@@ -0,0 +1,10 @@
|
||||
# textdomain: essences
|
||||
|
||||
essence_experience-title=Эссенция опыта
|
||||
essence_experience-desc=Сгусток желеобразной материи,@nзаключающий в себе ремесленный опыт.
|
||||
|
||||
essence_spell-title=Эссенция заклятия
|
||||
essence_spell-desc=Сгусток желеобразной материи,@nзаключающий в себе мистическую силу.
|
||||
|
||||
essence_life-title=Эссенция жизни
|
||||
essence_life-desc=Сгусток желеобразной материи,@nзаключающий в себе жизненную энергию.
|
||||
2
mods/GAME/ITEMS/essences/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__game__items__essences
|
||||
depends = smc__core__item
|
||||
BIN
mods/GAME/ITEMS/essences/textures/sheets/essences_sheet.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
@@ -1,11 +1,10 @@
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultLiquidDef = {
|
||||
settings = {
|
||||
name = '',
|
||||
addModName = false,
|
||||
_add_mod_name = false,
|
||||
tiles = {},
|
||||
waving = 3,
|
||||
use_texture_alpha = "blend",
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__plant')
|
||||
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
---@type Plant
|
||||
local Plant = modInfo.require('Plant')
|
||||
local Plant, TileSheet = Smc.requirePlant(), Smc.requireTileSheet()
|
||||
|
||||
Plant:new({
|
||||
settings = {
|
||||
@@ -21,7 +15,7 @@ for i=0, 3 do
|
||||
Plant:new({
|
||||
settings = {
|
||||
name = 'plant'..tostring(i),
|
||||
title = 'Plant',
|
||||
_title = 'Plant',
|
||||
tiles = { ts:t(i,0) },
|
||||
place_param2 = 3,
|
||||
},
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,14 +1,9 @@
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultRockDef = {
|
||||
settings = {
|
||||
name = "",
|
||||
description = "A rocks",
|
||||
name = '',
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
@@ -45,84 +40,27 @@ local function registerRocksTypes(postfix, x)
|
||||
})
|
||||
end
|
||||
|
||||
local function registerPilarStaff(rock, y)
|
||||
local columnTop = ts:t(9, y)
|
||||
|
||||
rockFactory:registerNodesByShortDef({
|
||||
{rock..'_fluted_column', {columnTop, columnTop, ts:t(6, y)}},
|
||||
{rock..'_ionic_chapiter', {
|
||||
ts:t(3, y),
|
||||
columnTop,
|
||||
ts:t(7, y),
|
||||
ts:t(7, y),
|
||||
ts:t(8, y),
|
||||
ts:t(8, y)}},
|
||||
})
|
||||
end
|
||||
|
||||
registerPilarStaff('sylite', 0)
|
||||
registerPilarStaff('sylite_gray', 1)
|
||||
registerPilarStaff('sylite_black', 2)
|
||||
|
||||
registerRocksTypes('', 0)
|
||||
registerRocksTypes('_block', 2)
|
||||
registerRocksTypes('_bricks', 5)
|
||||
|
||||
--[[
|
||||
rockFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "sylite",
|
||||
title = "Sylite",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,0"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "tauitite",
|
||||
title = "Tauitite",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,2"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "iyellite",
|
||||
title = "Iyellite",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,4"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "falmyte",
|
||||
title = "Falmyte",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,6"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "hapcoryte",
|
||||
title = "Hapcoryte",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,8"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "burcite",
|
||||
title = "Burcite",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,10"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "felhor",
|
||||
title = "Felhor",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,12"},
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "malachite",
|
||||
title = "Malachite",
|
||||
--description = "",
|
||||
tiles = {"rocks_sheet.png^[sheet:7x15:0,14"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
--]]
|
||||
registerRocksTypes('_chipped', 1)
|
||||
registerRocksTypes('_block', 3)
|
||||
registerRocksTypes('_bricks', 4)
|
||||
registerRocksTypes('_bricks_2', 5)
|
||||
|
||||
6
mods/GAME/ITEMS/rocks/locale/rocks.ru.tr
Normal file
@@ -0,0 +1,6 @@
|
||||
# textdomain: rocks
|
||||
|
||||
sylite_block-title=Силитовый блок
|
||||
sylite_block-desc=Массивный блок из цельного куска силита.
|
||||
sylite_bricks-title=Силитовые кирпичи
|
||||
sylite_bricks-desc=Кладка из силитовых кирпичей.
|
||||
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 151 KiB |
@@ -1,17 +1,14 @@
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultSoilDef = {
|
||||
settings = {
|
||||
name = "",
|
||||
description = "A soil",
|
||||
_description = "A soil",
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
soil = 1,
|
||||
soil_fertiliry = 100, -- Soil fertility for agriculture
|
||||
}
|
||||
},
|
||||
@@ -47,7 +44,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "clay_soil_baren",
|
||||
title = "Barren Clay Soil",
|
||||
_title = "Barren Clay Soil",
|
||||
--description = "",
|
||||
tiles = clayTiles,
|
||||
},
|
||||
@@ -56,7 +53,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "clay_soil_poor",
|
||||
title = "Poor Clay Soil",
|
||||
_title = "Poor Clay Soil",
|
||||
--description = "",
|
||||
tiles = clayTiles,
|
||||
},
|
||||
@@ -65,7 +62,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "clay_soil_moderate",
|
||||
title = "Moderate Clay Soil",
|
||||
_title = "Moderate Clay Soil",
|
||||
--description = "",
|
||||
tiles = clayTiles,
|
||||
},
|
||||
@@ -74,7 +71,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "clay_soil_fertile",
|
||||
title = "Fertile Clay Soil",
|
||||
_title = "Fertile Clay Soil",
|
||||
--description = "",
|
||||
tiles = clayTiles,
|
||||
},
|
||||
@@ -83,7 +80,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "clay_soil_rich",
|
||||
title = "Rich Clay Soil",
|
||||
_title = "Rich Clay Soil",
|
||||
--description = "",
|
||||
tiles = clayTiles,
|
||||
},
|
||||
@@ -96,7 +93,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "sandy_soil_baren",
|
||||
title = "Barren Sandy Soil",
|
||||
_title = "Barren Sandy Soil",
|
||||
--description = "",
|
||||
tiles = sandyTiles,
|
||||
},
|
||||
@@ -105,7 +102,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "sandy_soil_poor",
|
||||
title = "Poor Sandy Soil",
|
||||
_title = "Poor Sandy Soil",
|
||||
--description = "",
|
||||
tiles = sandyTiles,
|
||||
},
|
||||
@@ -114,7 +111,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "sandy_soil_moderate",
|
||||
title = "Moderate Sandy Soil",
|
||||
_title = "Moderate Sandy Soil",
|
||||
--description = "",
|
||||
tiles = sandyTiles,
|
||||
},
|
||||
@@ -123,7 +120,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "sandy_soil_fertile",
|
||||
title = "Fertile Sandy Soil",
|
||||
_title = "Fertile Sandy Soil",
|
||||
--description = "",
|
||||
tiles = sandyTiles,
|
||||
},
|
||||
@@ -132,7 +129,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "sandy_soil_rich",
|
||||
title = "Rich Sandy Soil",
|
||||
_title = "Rich Sandy Soil",
|
||||
--description = "",
|
||||
tiles = sandyTiles,
|
||||
},
|
||||
@@ -145,7 +142,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "mixed_soil_baren",
|
||||
title = "Barren Mixed Soil",
|
||||
_title = "Barren Mixed Soil",
|
||||
--description = "",
|
||||
tiles = mixedTiles,
|
||||
},
|
||||
@@ -154,7 +151,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "mixed_soil_poor",
|
||||
title = "Poor Mixed Soil",
|
||||
_title = "Poor Mixed Soil",
|
||||
--description = "",
|
||||
tiles = mixedTiles,
|
||||
},
|
||||
@@ -163,7 +160,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "mixed_soil_moderate",
|
||||
title = "Moderate Mixed Soil",
|
||||
_title = "Moderate Mixed Soil",
|
||||
--description = "",
|
||||
tiles = mixedTiles,
|
||||
},
|
||||
@@ -172,7 +169,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "mixed_soil_fertile",
|
||||
title = "Fertile Mixed Soil",
|
||||
_title = "Fertile Mixed Soil",
|
||||
--description = "",
|
||||
tiles = mixedTiles,
|
||||
},
|
||||
@@ -181,7 +178,7 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "mixed_soil_rich",
|
||||
title = "Rich Mixed Soil",
|
||||
_title = "Rich Mixed Soil",
|
||||
--description = "",
|
||||
tiles = mixedTiles,
|
||||
},
|
||||
@@ -194,43 +191,47 @@ soilFactory:registerItems({
|
||||
{
|
||||
settings = {
|
||||
name = "rocky_soil_baren",
|
||||
title = "Barren Rocky Soil",
|
||||
_title = "Barren Rocky Soil",
|
||||
--description = "",
|
||||
tiles = rockyTiles,
|
||||
rarity = 'uncommon'
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "rocky_soil_poor",
|
||||
title = "Poor Rocky Soil",
|
||||
_title = "Poor Rocky Soil",
|
||||
--description = "",
|
||||
tiles = rockyTiles,
|
||||
rarity = 'distinguished'
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "rocky_soil_moderate",
|
||||
title = "Moderate Rocky Soil",
|
||||
_title = "Moderate Rocky Soil",
|
||||
--description = "",
|
||||
tiles = rockyTiles,
|
||||
rarity = 'eminent'
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "rocky_soil_fertile",
|
||||
title = "Fertile Rocky Soil",
|
||||
_title = "Fertile Rocky Soil",
|
||||
--description = "",
|
||||
tiles = rockyTiles,
|
||||
rarity = 'prime'
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "rocky_soil_rich",
|
||||
title = "Rich Rocky Soil",
|
||||
_title = "Rich Rocky Soil",
|
||||
--description = "",
|
||||
tiles = rockyTiles,
|
||||
},
|
||||
@@ -241,13 +242,10 @@ soilFactory:registerItems({
|
||||
---@type TileSheet
|
||||
local tsT = TileSheet:new("soils_turfs_sheet.png", 16, 16)
|
||||
|
||||
Node:new({
|
||||
defaultSoil:new({
|
||||
settings = {
|
||||
name = 'turf_swamp',
|
||||
tiles = {tsT:t(0,0), ts:t(6, 0), ts:t(6,0)..'^'..tsT:t(0,1)},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
soil_fertiliry = 100, -- Soil fertility for agriculture
|
||||
}
|
||||
_rarity = 'unique'
|
||||
}
|
||||
})
|
||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
99
mods/GAME/ITEMS/storages/init.lua
Normal file
@@ -0,0 +1,99 @@
|
||||
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
||||
|
||||
local defaultStorage = Node:getExtended({
|
||||
settings = {
|
||||
name = '',
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
storage = 1
|
||||
},
|
||||
paramtype = 'light',
|
||||
paramtype2 = 'facedir',
|
||||
}
|
||||
})
|
||||
|
||||
local storageFactory = defaultStorage:getFactory()
|
||||
|
||||
---@type TileSheet
|
||||
local caseTileSheet = TileSheet:new('cases_sheet.png', 16, 16)
|
||||
|
||||
local function getCaseTiles(x, y)
|
||||
return {
|
||||
caseTileSheet:t(x, y),
|
||||
caseTileSheet:t(x, y),
|
||||
caseTileSheet:t(x, y+1),
|
||||
}
|
||||
end
|
||||
|
||||
local t = getCaseTiles
|
||||
|
||||
storageFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = 'case_closed',
|
||||
_title = 'Case',
|
||||
--description = '',
|
||||
tiles = t(0,0)
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = 'case_open',
|
||||
_title = 'Case',
|
||||
--description = '',
|
||||
tiles = t(1,0);
|
||||
drawtype = 'nodebox';
|
||||
node_box = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5 - 1/16*2, 0.5},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
drawtype = 'mesh',
|
||||
name = 'chest_close',
|
||||
tiles = {'storage_chest.png'},
|
||||
mesh = 'storage_chest_close.obj',
|
||||
node_box = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{-7/16, -0.5, -7/16, 23/16, 6/16, 7/16},
|
||||
}
|
||||
},
|
||||
selection_box = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{-7/16, -0.5, -7/16, 23/16, 6/16, 7/16},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
drawtype = 'mesh',
|
||||
name = 'chest_open',
|
||||
tiles = {'storage_chest.png'},
|
||||
mesh = 'storage_chest_open.obj',
|
||||
node_box = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{-7/16, -0.5, -7/16, 23/16, 6/16, 7/16},
|
||||
}
|
||||
},
|
||||
selection_box = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{-7/16, -0.5, -7/16, 23/16, 6/16, 7/16},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
2
mods/GAME/ITEMS/storages/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__game__items__storages
|
||||
depends = smc__core__node, smc__core__tilesheet
|
||||
49
mods/GAME/ITEMS/storages/models/storage_chest_close.obj
Normal file
@@ -0,0 +1,49 @@
|
||||
# Made in Blockbench 4.12.5
|
||||
mtllib storage_chest_close.mtl
|
||||
|
||||
o chest_close
|
||||
v 0.4375 0.375 0.4375
|
||||
v 0.4375 0.375 -0.4375
|
||||
v 0.4375 -0.5 0.4375
|
||||
v 0.4375 -0.5 -0.4375
|
||||
v -1.4375 0.375 -0.4375
|
||||
v -1.4375 0.375 0.4375
|
||||
v -1.4375 -0.5 -0.4375
|
||||
v -1.4375 -0.5 0.4375
|
||||
vt 0.109375 0.890625
|
||||
vt 0.34375 0.890625
|
||||
vt 0.34375 0.78125
|
||||
vt 0.109375 0.78125
|
||||
vt 0 0.890625
|
||||
vt 0.109375 0.890625
|
||||
vt 0.109375 0.78125
|
||||
vt 0 0.78125
|
||||
vt 0.453125 0.890625
|
||||
vt 0.6875 0.890625
|
||||
vt 0.6875 0.78125
|
||||
vt 0.453125 0.78125
|
||||
vt 0.34375 0.890625
|
||||
vt 0.453125 0.890625
|
||||
vt 0.453125 0.78125
|
||||
vt 0.34375 0.78125
|
||||
vt 0.34375 0.890625
|
||||
vt 0.109375 0.890625
|
||||
vt 0.109375 1
|
||||
vt 0.34375 1
|
||||
vt 0.578125 1
|
||||
vt 0.34375 1
|
||||
vt 0.34375 0.890625
|
||||
vt 0.578125 0.890625
|
||||
vn 0 0 -1
|
||||
vn 1 0 0
|
||||
vn 0 0 1
|
||||
vn -1 0 0
|
||||
vn 0 1 0
|
||||
vn 0 -1 0
|
||||
usemtl m_79b8a0d4-4f5c-1950-bda6-ec259f602f6d
|
||||
f 4/4/1 7/3/1 5/2/1 2/1/1
|
||||
f 3/8/2 4/7/2 2/6/2 1/5/2
|
||||
f 8/12/3 3/11/3 1/10/3 6/9/3
|
||||
f 7/16/4 8/15/4 6/14/4 5/13/4
|
||||
f 6/20/5 1/19/5 2/18/5 5/17/5
|
||||
f 7/24/6 4/23/6 3/22/6 8/21/6
|
||||
95
mods/GAME/ITEMS/storages/models/storage_chest_open.obj
Normal file
@@ -0,0 +1,95 @@
|
||||
# Made in Blockbench 4.12.5
|
||||
mtllib storage_chest_open.mtl
|
||||
|
||||
o сундук
|
||||
v 0.4375 0.25 0.4375
|
||||
v 0.4375 0.25 -0.4375
|
||||
v 0.4375 -0.5 0.4375
|
||||
v 0.4375 -0.5 -0.4375
|
||||
v -1.4375 0.25 -0.4375
|
||||
v -1.4375 0.25 0.4375
|
||||
v -1.4375 -0.5 -0.4375
|
||||
v -1.4375 -0.5 0.4375
|
||||
vt 0.109375 0.875
|
||||
vt 0.34375 0.875
|
||||
vt 0.34375 0.78125
|
||||
vt 0.109375 0.78125
|
||||
vt 0 0.875
|
||||
vt 0.109375 0.875
|
||||
vt 0.109375 0.78125
|
||||
vt 0 0.78125
|
||||
vt 0.453125 0.875
|
||||
vt 0.6875 0.875
|
||||
vt 0.6875 0.78125
|
||||
vt 0.453125 0.78125
|
||||
vt 0.34375 0.875
|
||||
vt 0.453125 0.875
|
||||
vt 0.453125 0.78125
|
||||
vt 0.34375 0.78125
|
||||
vt 0.8125 0.890625
|
||||
vt 0.578125 0.890625
|
||||
vt 0.578125 1
|
||||
vt 0.8125 1
|
||||
vt 0.578125 1
|
||||
vt 0.34375 1
|
||||
vt 0.34375 0.890625
|
||||
vt 0.578125 0.890625
|
||||
vn 0 0 -1
|
||||
vn 1 0 0
|
||||
vn 0 0 1
|
||||
vn -1 0 0
|
||||
vn 0 1 0
|
||||
vn 0 -1 0
|
||||
usemtl m_79b8a0d4-4f5c-1950-bda6-ec259f602f6d
|
||||
f 4/4/1 7/3/1 5/2/1 2/1/1
|
||||
f 3/8/2 4/7/2 2/6/2 1/5/2
|
||||
f 8/12/3 3/11/3 1/10/3 6/9/3
|
||||
f 7/16/4 8/15/4 6/14/4 5/13/4
|
||||
f 6/20/5 1/19/5 2/18/5 5/17/5
|
||||
f 7/24/6 4/23/6 3/22/6 8/21/6
|
||||
o крышка
|
||||
v 0.4375 0.33838834764831843 0.46338834764831843
|
||||
v 0.4375 0.9571067811865475 -0.15533008588991049
|
||||
v 0.4375 0.25 0.375
|
||||
v 0.4375 0.8687184335382291 -0.24371843353822897
|
||||
v -1.4375 0.9571067811865475 -0.15533008588991049
|
||||
v -1.4375 0.33838834764831843 0.46338834764831843
|
||||
v -1.4375 0.8687184335382291 -0.24371843353822897
|
||||
v -1.4375 0.25 0.375
|
||||
vt 0.109375 0.890625
|
||||
vt 0.34375 0.890625
|
||||
vt 0.34375 0.875
|
||||
vt 0.109375 0.875
|
||||
vt 0 0.890625
|
||||
vt 0.109375 0.890625
|
||||
vt 0.109375 0.875
|
||||
vt 0 0.875
|
||||
vt 0.453125 0.890625
|
||||
vt 0.6875 0.890625
|
||||
vt 0.6875 0.875
|
||||
vt 0.453125 0.875
|
||||
vt 0.34375 0.890625
|
||||
vt 0.453125 0.890625
|
||||
vt 0.453125 0.875
|
||||
vt 0.34375 0.875
|
||||
vt 0.34375 0.890625
|
||||
vt 0.109375 0.890625
|
||||
vt 0.109375 1
|
||||
vt 0.34375 1
|
||||
vt 0.578125 1
|
||||
vt 0.34375 1
|
||||
vt 0.34375 0.890625
|
||||
vt 0.578125 0.890625
|
||||
vn 0 0.7071067811865476 -0.7071067811865475
|
||||
vn 1 0 0
|
||||
vn 0 -0.7071067811865476 0.7071067811865475
|
||||
vn -1 0 0
|
||||
vn 0 0.7071067811865475 0.7071067811865476
|
||||
vn 0 -0.7071067811865475 -0.7071067811865476
|
||||
usemtl m_79b8a0d4-4f5c-1950-bda6-ec259f602f6d
|
||||
f 12/28/7 15/27/7 13/26/7 10/25/7
|
||||
f 11/32/8 12/31/8 10/30/8 9/29/8
|
||||
f 16/36/9 11/35/9 9/34/9 14/33/9
|
||||
f 15/40/10 16/39/10 14/38/10 13/37/10
|
||||
f 14/44/11 9/43/11 10/42/11 13/41/11
|
||||
f 15/48/12 12/47/12 11/46/12 16/45/12
|
||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
BIN
mods/GAME/ITEMS/storages/textures/storage_chest.png
Normal file
|
After Width: | Height: | Size: 64 KiB |
@@ -1,43 +1,54 @@
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultRockDef = {
|
||||
local defaultLogDef = {
|
||||
settings = {
|
||||
name = "",
|
||||
description = "A log",
|
||||
name = '',
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
wood = 1
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultPlanksDef = {
|
||||
settings = {
|
||||
name = "",
|
||||
description = "A planks",
|
||||
name = '',
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
}
|
||||
|
||||
local defaultLog = Node:getExtended(defaultRockDef)
|
||||
---@type Node.NodeDefinition
|
||||
local defaultLeafsDef = {
|
||||
settings = {
|
||||
drawtype = 'allfaces_optional',
|
||||
name = '',
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
},
|
||||
--paramtype = 'light',
|
||||
paramtype2 = 'facedir',
|
||||
use_texture_alpha = 'clip',
|
||||
sunlight_propagates = true,
|
||||
},
|
||||
}
|
||||
|
||||
local defaultLog = Node:getExtended(defaultLogDef)
|
||||
local defaultPlanks = Node:getExtended(defaultPlanksDef)
|
||||
local defaultLeafs = Node:getExtended(defaultLeafsDef)
|
||||
|
||||
local logFactory = defaultLog:getFactory()
|
||||
local planksFactory = defaultPlanks:getFactory()
|
||||
|
||||
---@type TileSheet
|
||||
local logTileSheet = TileSheet:new("wood_sheet.png", 16, 16)
|
||||
local logTileSheet = TileSheet:new('wood_sheet.png', 16, 16)
|
||||
|
||||
local function getLogTiles(x, y)
|
||||
return {
|
||||
@@ -47,161 +58,129 @@ local function getLogTiles(x, y)
|
||||
}
|
||||
end
|
||||
|
||||
local t = getLogTiles
|
||||
local t = logTileSheet
|
||||
|
||||
logFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
local function registerWood(name, x)
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = "marentine_log",
|
||||
title = "Marentine Log",
|
||||
--description = "",
|
||||
tiles = t(0, 1),
|
||||
name = name..'_log',
|
||||
tiles = getLogTiles(x, 2),
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "allwhere_log",
|
||||
title = "Allwhere Log",
|
||||
--description = "",
|
||||
tiles = t(2, 1),
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "fis_log",
|
||||
title = "Fis Log",
|
||||
--description = "",
|
||||
tiles = t(4, 1),
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "tammoy_log",
|
||||
title = "Tammoy Log",
|
||||
--description = "",
|
||||
tiles = t(6, 1),
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "dallalia_log",
|
||||
title = "Dallalia Log",
|
||||
--description = "",
|
||||
tiles = t(8, 1),
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "zuph_log",
|
||||
title = "Zuph Log",
|
||||
--description = "",
|
||||
tiles = t(10, 1),
|
||||
},
|
||||
},
|
||||
})
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
planksFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = "marentine_planks",
|
||||
title = "Marentine Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(0, 4) },
|
||||
name = name..'_log_stripped',
|
||||
tiles = getLogTiles(x, 4),
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "allwhere_planks",
|
||||
title = "Allwhere Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(2, 4) },
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "fis_planks",
|
||||
title = "Fis Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(4, 4) },
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "tammoy_planks",
|
||||
title = "Tammoy Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(6, 4) },
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "dallalia_planks",
|
||||
title = "Dallalia Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(8, 4) },
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "zuph_planks",
|
||||
title = "Zuph Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(10, 4) },
|
||||
},
|
||||
},
|
||||
})
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
-- сундучки
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_timber',
|
||||
tiles = {logTileSheet:t(x, 8), logTileSheet:t(x, 8),
|
||||
logTileSheet:t(x, 7), logTileSheet:t(x, 7),
|
||||
logTileSheet:t(x, 8), logTileSheet:t(x, 8),},
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
---@type TileSheet
|
||||
local caseTileSheet = TileSheet:new("cases_sheet.png", 16, 16)
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_trunk',
|
||||
tiles = {logTileSheet:t(x, 3)},
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
local function getCaseTiles(x, y)
|
||||
return {
|
||||
caseTileSheet:t(x, y),
|
||||
caseTileSheet:t(x, y),
|
||||
caseTileSheet:t(x, y+1),
|
||||
}
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_trunk_vertical',
|
||||
tiles = getLogTiles(x, 2),
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype2 = 'facedir',
|
||||
},
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
drawtype = 'nodebox',
|
||||
name = name..'_trunk_branch',
|
||||
tiles = {logTileSheet:t(x, 3)},
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype = 'light',
|
||||
node_box = {
|
||||
type = 'connected',
|
||||
fixed = {-.25,-.25,-.25, .25,.25,.25},
|
||||
connect_top = {-.25,-.25,-.25, .25,.5,.25},
|
||||
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
|
||||
connect_front = {-.25,-.25,-.5, .25,.25,.25},
|
||||
connect_left = {-.5,-.25,-.25, .25,.25,.25},
|
||||
connect_back = {-.25,-.25,-.25, .25,.25,.5},
|
||||
connect_right = {-.25,-.25,-.25, .5,.25,.25},
|
||||
},
|
||||
connects_to = {'group:wood', 'group:soil'}
|
||||
},
|
||||
})
|
||||
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
drawtype = 'nodebox',
|
||||
name = name..'_trunk_branch_vertical',
|
||||
tiles = getLogTiles(x, 2),
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype = 'light',
|
||||
node_box = {
|
||||
type = 'connected',
|
||||
fixed = {-.25,-.25,-.25, .25,.25,.25},
|
||||
connect_top = {-.25,-.25,-.25, .25,.5,.25},
|
||||
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
|
||||
},
|
||||
connects_to = {'group:wood', 'group:soil'}
|
||||
},
|
||||
})
|
||||
|
||||
defaultPlanks:new({
|
||||
settings = {
|
||||
name = name..'_planks',
|
||||
tiles = { logTileSheet:t(x, 6) },
|
||||
},
|
||||
})
|
||||
|
||||
defaultLeafs:new({
|
||||
settings = {
|
||||
name = name..'_leafs',
|
||||
tiles = { logTileSheet:t(x, 1) },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local t = getCaseTiles
|
||||
|
||||
planksFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "case_closed",
|
||||
title = "Case",
|
||||
--description = "",
|
||||
tiles = t(0,0)
|
||||
},
|
||||
},
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "case_open",
|
||||
title = "Case",
|
||||
--description = "",
|
||||
tiles = t(1,0);
|
||||
drawtype = 'nodebox';
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5 - 1/16*2, 0.5},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
registerWood('marentine', 0)
|
||||
registerWood('allwhere', 1)
|
||||
registerWood('fis', 2)
|
||||
registerWood('tammoy', 3)
|
||||
registerWood('gi', 4)
|
||||
registerWood('dallalia', 5)
|
||||
registerWood('zuph', 6)
|
||||
|
||||
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 16 KiB |
BIN
mods/GAME/ITEMS/wood/textures/wood_trunk_overlay.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
68
mods/GAME/adminCommands/init.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type AdminListUI
|
||||
local AdminListUI = Mod.getInfo('smc__ui__admin_list').require('AdminListUI')
|
||||
|
||||
core.register_chatcommand('list', {
|
||||
privs = {server = true},
|
||||
|
||||
func = function(name, param)
|
||||
local player = core.get_player_by_name(name)
|
||||
|
||||
AdminListUI:showForm(name)
|
||||
|
||||
return true, ''
|
||||
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)
|
||||
player:set_sky({
|
||||
sky_color = {
|
||||
day_sky = '#FCF0ED',
|
||||
day_horizon = '#F1D4C3',
|
||||
},
|
||||
type = 'regular',
|
||||
})
|
||||
|
||||
player:set_lighting({
|
||||
shadows = { intensity = 0.33 },
|
||||
volumetric_light = { strength = 0.45 },
|
||||
exposure = {
|
||||
luminance_min = -3.5,
|
||||
luminance_max = -2.5,
|
||||
exposure_correction = 0.35,
|
||||
speed_dark_bright = 1500,
|
||||
speed_bright_dark = 700,
|
||||
},
|
||||
saturation = 1.0,
|
||||
})
|
||||
end)
|
||||
2
mods/GAME/adminCommands/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__game__admin_commands
|
||||
depends = smc__system__system_loader, smc__ui__admin_list
|
||||
@@ -1,13 +1,13 @@
|
||||
local setMetaTable, TableCopy = setmetatable, table.copy_with_metatables
|
||||
local setMetaTable, tableCopy = setmetatable, table.copy_with_metatables
|
||||
|
||||
---@class Class
|
||||
Class = {}
|
||||
|
||||
---Returns a child class with inherited parameters from the parent class.
|
||||
---@param parent table
|
||||
---@param child table
|
||||
function Class.extend(parent ,child)
|
||||
return setmetatable(child or {}, { __index = TableCopy(parent) })
|
||||
---@param child table?
|
||||
function Class.extend(parent, child)
|
||||
return setMetaTable(child or {}, { __index = tableCopy(parent) })
|
||||
end
|
||||
|
||||
---Intended for class constructors.
|
||||
@@ -23,7 +23,7 @@ function Class.getInstance(self, params, metatable)
|
||||
metatable = {}
|
||||
end
|
||||
|
||||
metatable.__index = TableCopy(self)
|
||||
metatable.__index = tableCopy(self)
|
||||
|
||||
local instance = setMetaTable(params, metatable)
|
||||
|
||||
|
||||
@@ -5,20 +5,16 @@ Events = {}
|
||||
---@type table<string, Events.callback[]>
|
||||
local registeredEvents = {}
|
||||
|
||||
---@param eventName string
|
||||
function Events.registerEvent(eventName)
|
||||
assert(registeredEvents[eventName] == nil, ('Event %s is already registered.'):format(eventName))
|
||||
|
||||
registeredEvents[eventName] = {}
|
||||
end
|
||||
|
||||
---@param eventName string
|
||||
---@param callback Events.callback
|
||||
function Events.subscribe(eventName, callback)
|
||||
local callbacks = registeredEvents[eventName]
|
||||
assert(callbacks ~= nil, ('Event %s does not exist'):format(eventName))
|
||||
|
||||
table.insert(callbacks, callback)
|
||||
if callbacks == nil then
|
||||
registeredEvents[eventName] = {callback}
|
||||
else
|
||||
table.insert(callbacks, callback)
|
||||
end
|
||||
end
|
||||
|
||||
---@param eventName string
|
||||
@@ -30,4 +26,4 @@ function Events.call(eventName, ...)
|
||||
for _, func in ipairs(callbacks) do
|
||||
func(eventName, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
BIN
mods/SYSTEM/HelperLib/fonts/Philosopher-Regular.ttf
Normal file
56
mods/SYSTEM/HelperLib/fonts/fonts.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Game fonts
|
||||
Description of the fonts that are pre-installed for the project and passed on to all clients for displaying text.
|
||||
|
||||
## Philosopher
|
||||
Download site: https://fonts-online.ru/fonts/doloto.
|
||||
|
||||
Used in:
|
||||
- `regular.ttf`
|
||||
- `mono.ttf`
|
||||
|
||||
### Info
|
||||
Designed by **Jovanny Lemonad**.
|
||||
|
||||
### Licence
|
||||
Copyright 2011 The Philosopher Project Authors (https://github.com/alexeiva/philosopher)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1 . This license is copied below, and is also available with a FAQ at: https://openfontlicense.org
|
||||
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
|
||||
#### PREAMBLE
|
||||
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
#### DEFINITIONS
|
||||
|
||||
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
||||
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
#### PERMISSION & CONDITIONS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
- Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
- Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
- No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
- The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
- The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
#### TERMINATION
|
||||
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
#### DISCLAIMER
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
---
|
||||
BIN
mods/SYSTEM/HelperLib/fonts/mono.ttf
Normal file
BIN
mods/SYSTEM/HelperLib/fonts/regular.ttf
Normal file
@@ -5,3 +5,7 @@ local require = modInfo.require
|
||||
|
||||
require('Lib.globalStep')
|
||||
require('Lib.color')
|
||||
require('Lib.immersiveCraftData')
|
||||
require('Lib.getObjectByGUID')
|
||||
require('Lib.receiveFields')
|
||||
require('Lib.requires')
|
||||
16
mods/SYSTEM/HelperLib/src/Lib/getObjectByGUID.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
---Returns an active object by unique identifier (GUID).
|
||||
---* For players, this is a player name.
|
||||
---* For Lua entities, this is a uniquely generated string, guaranteed not to collide with player names.
|
||||
---
|
||||
---**Note**: If an object with such an identifier does not exist or is inactive, the value `nil` will be returned.
|
||||
---@param guid string only use printable ASCII characters. Example: `@bGh3p2AbRE29Mb4biqX6OA`.
|
||||
---@return ObjectRef|Player|Entity|nil
|
||||
function Smc.getObjectByGUID(guid)
|
||||
local obj = core.objects_by_guid[guid]
|
||||
|
||||
if obj == nil then
|
||||
return
|
||||
else
|
||||
return obj
|
||||
end
|
||||
end
|
||||
94
mods/SYSTEM/HelperLib/src/Lib/immersiveCraftData.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
local EMPTY_FLAG = 'EMPTY_FLAG'
|
||||
|
||||
---@class ImmersiveStageData
|
||||
|
||||
---@class ImmersiveCraftData
|
||||
---@field playerName string The name of the player who started the craft.
|
||||
---@field craftName string
|
||||
---@field stageName string
|
||||
---@field amount integer
|
||||
---@field stageData ImmersiveStageData?
|
||||
|
||||
---Returns craft data for immersive crafting, which is stored in the desktop metadata.
|
||||
---@param meta NodeMetaRef
|
||||
---@return ImmersiveCraftData?
|
||||
function Smc.getCraftDataByMeta(meta)
|
||||
local dataString = meta:get_string('craft_data')
|
||||
|
||||
if dataString == EMPTY_FLAG then
|
||||
return
|
||||
end
|
||||
|
||||
return core.deserialize(dataString)
|
||||
end
|
||||
|
||||
---Sets craft data for immersive crafting that is stored in the work station metadata.
|
||||
---
|
||||
---If `data` is `nil`, the data is cleared.
|
||||
---@param meta NodeMetaRef
|
||||
---@param craftData ImmersiveCraftData?
|
||||
function Smc.setCraftDataByMeta(meta, craftData)
|
||||
if craftData == nil then
|
||||
meta:set_string('craft_data', EMPTY_FLAG)
|
||||
end
|
||||
|
||||
meta:set_string('craft_data', core.serialize(craftData))
|
||||
end
|
||||
|
||||
---Returns craft data for immersive crafting, which is stored in the work station metadata.
|
||||
---@param pos MapPosition
|
||||
---@return ImmersiveCraftData?
|
||||
function Smc.getCraftDataByPos(pos)
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
return Smc.getCraftDataByMeta(meta)
|
||||
end
|
||||
|
||||
---Sets craft data for immersive crafting that is stored in the work station metadata.
|
||||
---
|
||||
---If `data` is `nil`, the data is cleared.
|
||||
---@param pos MapPosition
|
||||
---@param craftData ImmersiveCraftData?
|
||||
function Smc.setCraftDataByPos(pos, craftData)
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
Smc.setCraftDataByMeta(meta, craftData)
|
||||
end
|
||||
|
||||
---Returns stage data for immersive crafting, which is stored in the work station metadata.
|
||||
---
|
||||
---**Note**: If the workbench does not have crafting data, an error will be thrown.
|
||||
---@param pos MapPosition
|
||||
---@return ImmersiveStageData?
|
||||
function Smc.getStageDataByPos(pos)
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
return craftData.stageData
|
||||
end
|
||||
|
||||
---Sets stage data for immersive crafting that is stored in the work station metadata.
|
||||
---@param pos MapPosition
|
||||
---@param stageData ImmersiveStageData
|
||||
function Smc.setStageDataByPos(pos, stageData)
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
assert(craftData ~= nil, 'Immersive crafting data is empty.')
|
||||
|
||||
craftData.stageData = stageData
|
||||
Smc.setCraftDataByPos(pos, craftData)
|
||||
end
|
||||
|
||||
---Checks if the workstation is busy or free for new crafting.
|
||||
---
|
||||
---The verification is based on `ImmersiveCraftData`.
|
||||
---@param pos MapPosition
|
||||
---@return boolean
|
||||
function Smc.workStationIsFree(pos)
|
||||
local data = Smc.getCraftDataByPos(pos)
|
||||
|
||||
if data == nil then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
67
mods/SYSTEM/HelperLib/src/Lib/receiveFields.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
---Register a callback for a specific player action in FormSpec.
|
||||
---
|
||||
---The callback is guaranteed to be called only for the specified form and the specified field.
|
||||
---@param formName string the name of the formspec for which the callback will be called.
|
||||
---@param fieldName string the name of the field for which the callback will be called.
|
||||
---@param callback fun(player:Player, fieldName:string, fieldValue:any) Callback to handle the action. Parameters:
|
||||
--- * `player` - the player who performed the action.
|
||||
--- * `fieldName` - the name of the field on which the callback is called.
|
||||
--- * `fieldValue` - the field value that is passed in the `fields` table.
|
||||
function Smc.registerOnFormFieldAction(formName, fieldName, callback)
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- If the form name does not match the given...
|
||||
if formName ~= formname then
|
||||
-- ...we do nothing.
|
||||
return
|
||||
end
|
||||
|
||||
local fieldValue = fields[fieldName]
|
||||
-- If the field value is not nil (the player called this field)...
|
||||
if fieldValue ~= nil then
|
||||
-- ...calling a callback.
|
||||
callback(player, fieldName, fieldValue)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---Register a callback function to close the FormSpec.
|
||||
---
|
||||
---The callback is guaranteed to be called only for the specified form.
|
||||
---@param formName string the name of the form that is being closed.
|
||||
---@param callback fun(player:Player) Callback to handle the close. Parameters:
|
||||
--- * `player` - the player who closed the form.
|
||||
function Smc.registerOnFormQuit(formName, callback)
|
||||
Smc.registerOnFormFieldAction(formName, 'quit', callback)
|
||||
end
|
||||
|
||||
---Register a callback for a specific player action in FormSpec.
|
||||
---
|
||||
---The callback function is guaranteed to be called only for the specified form and
|
||||
---for the field whose name matches the pattern.
|
||||
---@param formName string the name of the formspec for which the callback will be called.
|
||||
---@param fieldNamePattern string the name pattern of the field for which the callback will be called.
|
||||
---@param callback fun(player:Player, fieldName:string, fieldValue:any) Callback to handle the action. Parameters:
|
||||
--- * `player` - the player who performed the action.
|
||||
--- * `fieldName` - the name of the field on which the callback is called (will match the pattern).
|
||||
--- * `fieldValue` - the field value that is passed in the `fields` table.
|
||||
function Smc.registerOnFormFieldActionMatch(formName, fieldNamePattern, callback)
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- If the form name does not match the given...
|
||||
if formName ~= formname then
|
||||
-- ...we do nothing.
|
||||
return
|
||||
end
|
||||
|
||||
-- We go through each field in the list of fields.
|
||||
for fieldName, fieldValue in pairs(fields) do
|
||||
-- We check the field name pattern compliance.
|
||||
local capturedName = string.match(fieldName, fieldNamePattern)
|
||||
|
||||
-- If the captured name is not nil...
|
||||
if capturedName ~= nil then
|
||||
-- ...calling a callback.
|
||||
callback(player, fieldName, fieldValue)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
66
mods/SYSTEM/HelperLib/src/Lib/requires.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
-- Global methods for require classes.
|
||||
|
||||
---@return Item
|
||||
function Smc.requireItem()
|
||||
---@type Item
|
||||
local class = Mod.getInfo('smc__core__item').require('Item')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return Node
|
||||
function Smc.requireNode()
|
||||
---@type Node
|
||||
local class = Mod.getInfo('smc__core__node').require('Node')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return Tool
|
||||
function Smc.requireTool()
|
||||
---@type Tool
|
||||
local class = Mod.getInfo('smc__core__tool').require('Tool')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return Plant
|
||||
function Smc.requirePlant()
|
||||
---@type Plant
|
||||
local class = Mod.getInfo('smc__core__plant').require('Plant')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return ItemFactory
|
||||
function Smc.requireItemFactory()
|
||||
---@type ItemFactory
|
||||
local class = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return TileSheet
|
||||
function Smc.requireTileSheet()
|
||||
---@type TileSheet
|
||||
local class = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return BaseUI
|
||||
function Smc.requireBaseUI()
|
||||
---@type BaseUI
|
||||
local class = Mod.getInfo('smc__core__base_ui').require('BaseUI')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return Formspec
|
||||
function Smc.requireFormspec()
|
||||
---@type Formspec
|
||||
local class = Mod.getInfo('smc__core__formspec').require('Formspec')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
@@ -156,10 +156,10 @@ local function mergeInPlace(target, source, recursively)
|
||||
end
|
||||
|
||||
--- Merges entries from `t2` into a deep copy of `t1`, skipping existing keys.
|
||||
--- @param t1 table<string, any> | any[] Target table to merge into
|
||||
--- @param t2 table<string, any> | any[] Source table to merge from
|
||||
--- @param recursively? boolean Enable recursive merging (default: false)
|
||||
--- @return table<string, any> | any[]
|
||||
--- @param t1 table Target table to merge into
|
||||
--- @param t2 table Source table to merge from
|
||||
--- @param recursively? boolean Enable recursive merging (default: false)
|
||||
--- @return table
|
||||
function table.merge(t1, t2, recursively)
|
||||
ensureArgType(t1, 'table', 1, 'table.merge')
|
||||
ensureArgType(t2, 'table', 2, 'table.merge')
|
||||
|
||||
4
mods/UI/AdminListUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__ui__admin_list')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('AdminListUI')
|
||||
2
mods/UI/AdminListUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__ui__admin_list
|
||||
depends = smc__core__formspec
|
||||
78
mods/UI/AdminListUI/src/AdminListUI.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
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 itemDef = core.registered_items[item]
|
||||
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(itemDef.stack_max)):
|
||||
areaLabel(14.5, 0.5, 6, 4,
|
||||
item..'\n\n'..
|
||||
itemDef._title..'\n'..
|
||||
itemDef._description)
|
||||
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
|
||||
4
mods/UI/WorkStationUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__ui__work_station')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('WorkStationUI')
|
||||
2
mods/UI/WorkStationUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__ui__work_station
|
||||
depends = smc__core__formspec
|
||||
57
mods/UI/WorkStationUI/src/WorkStationUI.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
---@param self BaseUI
|
||||
---@param playerName string
|
||||
---@param isSelect boolean
|
||||
---@return string
|
||||
local function getFormSpecString(self, playerName, isSelect)
|
||||
local outputs = self:getContex(playerName, 'outputs')
|
||||
---@type CraftSystem.ImmersiveCraft
|
||||
local craft = self:getContex(playerName, 'craft')
|
||||
|
||||
local listForm = Formspec:new({
|
||||
size = {x=16, y=8},
|
||||
})
|
||||
|
||||
local listFormItems = Formspec:new()
|
||||
table.sort(outputs)
|
||||
local w, h = 0, 0
|
||||
|
||||
for result, craftName in pairs(outputs) do
|
||||
listFormItems:itemImageButton(w, h, 2, 2, result, craftName..'::item_button')
|
||||
|
||||
w = w + 2
|
||||
|
||||
if w > 9 then
|
||||
w = 0
|
||||
h = h + 2
|
||||
end
|
||||
end
|
||||
|
||||
listForm:
|
||||
scrollContainer(listFormItems, 0.5, 0.5, 8, 6, 'work_station:list_items', 'vertical'):
|
||||
scrollbar(8, 0.5, 0.25, 7, 'vertical', 'work_station:list_items')
|
||||
|
||||
if isSelect then
|
||||
local stage = craft.stagesByName[craft.startStageName]
|
||||
local outputDef = core.registered_nodes[craft.output]
|
||||
listForm:
|
||||
itemImage(9, 0.5, 2, 2, craft.output):
|
||||
areaLabel(9, 6, 2, 1, 'Start crafting:'):
|
||||
button(9, 6.5, 3, 1, 'work_station:start_craft', 'x1'):
|
||||
button(12, 6.5,3, 1, 'work_station:start_craft', 'x10'):
|
||||
areaLabel(11.5, 0.5, 4, 4,
|
||||
outputDef._title..'\n'..
|
||||
outputDef._description):
|
||||
areaLabel(9, 2.5, 6, 4, 'Craft description:'..'\n'..craft:toString())
|
||||
end
|
||||
|
||||
return listForm:toString()
|
||||
end
|
||||
|
||||
---@class WorkStationUI : BaseUI
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean):string
|
||||
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean):string
|
||||
local WorkStationUI = BaseUI:new('work_station:selection_craft', getFormSpecString)
|
||||
|
||||
return WorkStationUI
|
||||