Compare commits
41 Commits
craft-syst
...
e98935cf6f
| Author | SHA1 | Date | |
|---|---|---|---|
| e98935cf6f | |||
| 338cc7a36b | |||
| 18f06d13d3 | |||
| 145f65d4af | |||
| e359c4be09 | |||
| c009493484 | |||
| fab86c0486 | |||
| cb15f25d60 | |||
| 867238e11b | |||
| df247108ef | |||
| e34fd29a4b | |||
| 41cf4710da | |||
| c6573ae308 | |||
| 4ef2476771 | |||
| 2c13e1697f | |||
| 7b4839e63b | |||
| 2813d9d5fe | |||
| 652200f28c | |||
| eeffae6852 | |||
| fe3298d112 | |||
| 7d49bbf535 | |||
| efcbc909e0 | |||
| 17413df9c4 | |||
| 2eede05436 | |||
| b863c88838 | |||
| 692105abfa | |||
| 1a6086190e | |||
| e20c3b4ef4 | |||
| 8b55ccff72 | |||
| c7cfe26335 | |||
| 51e6763457 | |||
| c47ab6ac3c | |||
| 6fd8295500 | |||
| b12f890740 | |||
| 4c90041c68 | |||
| b50d642bcf | |||
| e0b9024458 | |||
| 745eaa8569 | |||
| b6051e5724 | |||
| 5c936025f1 | |||
| 5be847bf58 |
@@ -32,7 +32,8 @@
|
||||
"vector",
|
||||
"Ensure",
|
||||
"string",
|
||||
"string_utf8"
|
||||
"string_utf8",
|
||||
"Profiler"
|
||||
],
|
||||
"globalsRegex": []
|
||||
},
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
Source code licensing:
|
||||
# Source code licensing
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2025 Apancore.Studio, Doloment
|
||||
**The MIT License (MIT)**
|
||||
|
||||
Copyright (c) 2025 Apancore.Studio, Van (varttist), Doloment
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
@@ -11,9 +12,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
------------------------
|
||||
|
||||
Sprites licensing:
|
||||
# Sprites licensing
|
||||
|
||||
CC BY 4.0
|
||||
Copyright (c) 2025 Apancore.Studio, Doloment and others (see list below)
|
||||
**CC BY 4.0**
|
||||
|
||||
Copyright (c) 2025 Apancore.Studio, Van (varttist) and others (see list below)
|
||||
|
||||
All textures except those listed here are copyrighted by Van (varttist) and are distributed under the CC BY 4.0.
|
||||
|
||||
List of all textures and authors:
|
||||
- ...
|
||||
@@ -10,18 +10,26 @@ local BaseUI = {
|
||||
contex = {}
|
||||
}
|
||||
|
||||
---@param name string
|
||||
---@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
|
||||
function BaseUI:new(name, getFormSpecString)
|
||||
---@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
|
||||
|
||||
-- Ensure that when the form is closed, the context is cleared.
|
||||
instance:registerOnFormQuit(function(player)
|
||||
instance:clearContex(player)
|
||||
end)
|
||||
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
|
||||
|
||||
@@ -106,10 +106,10 @@ end
|
||||
function ImmersiveCraft:startCraft(pos, player, amount)
|
||||
-- Adding craft to the counter.
|
||||
-- If crafting has not been added...
|
||||
if not ImmersiveCraftCounter:addCraft(pos, player) then
|
||||
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:'..
|
||||
'The limit of simultaneously active crafts has been reached: '..
|
||||
'complete or cancel active crafts to start a new one')
|
||||
|
||||
return false
|
||||
@@ -142,9 +142,10 @@ function ImmersiveCraft:startCraft(pos, player, amount)
|
||||
-- Create a temporary data table for crafting.
|
||||
---@type ImmersiveCraftData
|
||||
local craftData = {
|
||||
craftName = self.name,
|
||||
stageName = stage.name,
|
||||
amount = amount,
|
||||
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)
|
||||
@@ -157,8 +158,8 @@ end
|
||||
|
||||
---Complete the immersive crafting process.
|
||||
---@param pos MapPosition
|
||||
---@param Player Player
|
||||
function ImmersiveCraft:endCraft(pos, Player)
|
||||
---@param player Player
|
||||
function ImmersiveCraft:endCraft(pos, player)
|
||||
-- We get current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
@@ -170,17 +171,16 @@ function ImmersiveCraft:endCraft(pos, Player)
|
||||
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)
|
||||
|
||||
-- Remove craft from the counter.
|
||||
ImmersiveCraftCounter:removeCraft(pos, Player)
|
||||
end
|
||||
|
||||
---Stop the crafting process and free up the workbench.
|
||||
---@param pos MapPosition
|
||||
---@param Player Player
|
||||
function ImmersiveCraft:abortCraft(pos, Player)
|
||||
function ImmersiveCraft:abortCraft(pos)
|
||||
-- We get current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
@@ -188,13 +188,13 @@ function ImmersiveCraft:abortCraft(pos, Player)
|
||||
|
||||
-- We get the current stage and start the abort process.
|
||||
local stage = self.stagesByName[craftData.stageName]
|
||||
stage:abortHandler(pos, Player)
|
||||
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, Player)
|
||||
ImmersiveCraftCounter:removeCraft(pos, craftData.playerName)
|
||||
end
|
||||
|
||||
---Returns a human-readable description of the crafting process.
|
||||
|
||||
@@ -3,6 +3,20 @@ 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.
|
||||
---
|
||||
@@ -12,18 +26,17 @@ local CRAFT_LIMIT_PER_SERVER = 10
|
||||
---@field craftsCountForPlayers table<string, table<string, boolean>>
|
||||
---@field craftsCountForServer table<string, boolean>
|
||||
local ImmersiveCraftCounter = {
|
||||
craftsCountForPlayers = {},
|
||||
craftsCountForServer = {}
|
||||
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 Player Player
|
||||
---@return boolean
|
||||
function ImmersiveCraftCounter:addCraft(pos, Player)
|
||||
local playerName = Player:get_player_name()
|
||||
---@param pos MapPosition
|
||||
---@param playerName string
|
||||
---@return boolean
|
||||
function ImmersiveCraftCounter:addCraft(pos, playerName)
|
||||
if self.craftsCountForPlayers[playerName] == nil then
|
||||
self.craftsCountForPlayers[playerName] = {}
|
||||
end
|
||||
@@ -44,10 +57,10 @@ function ImmersiveCraftCounter:addCraft(pos, Player)
|
||||
end
|
||||
|
||||
---Remove craft from the counter.
|
||||
---@param pos MapPosition
|
||||
---@param Player Player
|
||||
function ImmersiveCraftCounter:removeCraft(pos, Player)
|
||||
local playerCrafts = self.craftsCountForPlayers[Player:get_player_name()]
|
||||
---@param pos MapPosition
|
||||
---@param playerName string
|
||||
function ImmersiveCraftCounter:removeCraft(pos, playerName)
|
||||
local playerCrafts = self.craftsCountForPlayers[playerName]
|
||||
if playerCrafts == nil then
|
||||
return
|
||||
end
|
||||
@@ -57,6 +70,9 @@ function ImmersiveCraftCounter:removeCraft(pos, Player)
|
||||
self.craftsCountForServer[posString] = nil
|
||||
end
|
||||
|
||||
-- TODO: сделать сохранение данных во время перезагрузки сервера
|
||||
core.register_on_shutdown(function()
|
||||
setStorageTable('crafts_count_for_players', ImmersiveCraftCounter.craftsCountForPlayers)
|
||||
setStorageTable('crafts_count_for_server', ImmersiveCraftCounter.craftsCountForServer)
|
||||
end)
|
||||
|
||||
return ImmersiveCraftCounter
|
||||
|
||||
@@ -22,10 +22,14 @@ local tappingNode = ImmersiveCraftNode:new({
|
||||
_name = 'craft_system:tapping_node',
|
||||
_add_mod_name = false,
|
||||
|
||||
---@type ObjectProperties
|
||||
initial_properties = {
|
||||
visual = 'wielditem',
|
||||
visual_size = {x=0.4, y=0.4, z=0.4},
|
||||
--static_save = false,
|
||||
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 = '',
|
||||
|
||||
@@ -7,10 +7,10 @@ local getInstance = Class.getInstance
|
||||
---@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, Player:Player)
|
||||
---@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[]?
|
||||
|
||||
@@ -11,6 +11,7 @@ local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
||||
---@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)
|
||||
@@ -23,6 +24,7 @@ local TappingStage = extend(ImmersiveCraftStage, {})
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingStageDef : CraftSystem.ImmersiveCraftStageDef
|
||||
---@field targetItem string
|
||||
---@field clicksNeed string
|
||||
---@field toolGroup string?
|
||||
|
||||
---Data table for transferring various time parameters between calls.
|
||||
---
|
||||
@@ -39,11 +41,12 @@ function TappingStage:new(def)
|
||||
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)
|
||||
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.8,0)
|
||||
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
|
||||
@@ -75,7 +78,7 @@ function TappingStage:new(def)
|
||||
|
||||
-- Registering the crafting stage process handler.
|
||||
-- Called when a player clicks on a crafting node (entity).
|
||||
instance.processHandler = function(tappingStage, pos, Player)
|
||||
instance.processHandler = function(tappingStage, pos, player)
|
||||
-- Obtaining stage time data from work station metadata.
|
||||
---@type ImmersiveStageData.TappingStageData?
|
||||
local stageData = getStageDataByPos(pos)
|
||||
@@ -88,7 +91,7 @@ function TappingStage:new(def)
|
||||
-- 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)
|
||||
tappingStage:endHandler(pos, player)
|
||||
else
|
||||
-- ...else we save the number of clicks in the temporary data table.
|
||||
stageData.clickCount = clickCount
|
||||
@@ -97,7 +100,7 @@ function TappingStage:new(def)
|
||||
end
|
||||
|
||||
-- Registering the crafting stage end handler.
|
||||
instance.endHandler = function(tappingStage, pos, Player)
|
||||
instance.endHandler = function(tappingStage, pos, player)
|
||||
-- Obtaining stage time data from work station metadata.
|
||||
---@type ImmersiveStageData.TappingStageData?
|
||||
local stageData = getStageDataByPos(pos)
|
||||
@@ -111,12 +114,12 @@ function TappingStage:new(def)
|
||||
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)
|
||||
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, Player)
|
||||
instance.abortHandler = function(tappingStage, pos)
|
||||
-- We receive current data on crafting.
|
||||
---@type ImmersiveCraftData?
|
||||
local craftData = Smc.getCraftDataByPos(pos)
|
||||
@@ -143,7 +146,12 @@ function TappingStage:new(def)
|
||||
|
||||
-- Returns a human-readable description of the crafting stage.
|
||||
instance.toString = function(tappingStage)
|
||||
local stageDesc = ('Tapping x%s'):format(tappingStage.clicksNeed)
|
||||
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
|
||||
@@ -151,7 +159,17 @@ function TappingStage:new(def)
|
||||
-- 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
|
||||
function(eventName, pos, Player, craftNode)
|
||||
---@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
|
||||
@@ -172,7 +190,7 @@ function TappingStage:new(def)
|
||||
-- DRAFT END
|
||||
|
||||
-- Calling the crafting stage process handler.
|
||||
instance:processHandler(pos, Player)
|
||||
instance:processHandler(pos, player)
|
||||
end)
|
||||
|
||||
return instance
|
||||
|
||||
@@ -296,7 +296,7 @@ end
|
||||
---@param w number
|
||||
---@param h number
|
||||
---@param textureName string
|
||||
---@param middle boolean? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||
---@param middle string? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||
---@return Formspec
|
||||
function Formspec:image(x, y, w, h, textureName, middle)
|
||||
local element = ('image[%s,%s;%s,%s;%s;%s]'):format(
|
||||
@@ -441,7 +441,7 @@ end
|
||||
--- * All numbers in middle are integers.
|
||||
---@return Formspec
|
||||
function Formspec:background9(x, y, w, h, textureName, autoClip, middle)
|
||||
local element = ('background9[%s,%s;%s,%s;%s;%s]'):format(
|
||||
local element = ('background9[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||
x, y, w, h, textureName, autoClip, middle)
|
||||
|
||||
self:addElement(element)
|
||||
|
||||
@@ -2,10 +2,7 @@ local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__item')
|
||||
local require = modInfo.require
|
||||
|
||||
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
|
||||
@@ -37,7 +34,7 @@ local RARITY_INDEX = {
|
||||
---@class Item
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef ItemDefinition
|
||||
---@field getVisual fun(): string
|
||||
---@field getType fun():string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
local Item = {
|
||||
defaultDef = {
|
||||
@@ -46,9 +43,10 @@ local Item = {
|
||||
_title = '',
|
||||
_description = '',
|
||||
_title_color = '#FFFFFF',
|
||||
_description_color = '#C0C0C0',
|
||||
_description_color = '#838383',
|
||||
_rarity = 'common',
|
||||
_add_mod_name = true,
|
||||
stack_max = 128,
|
||||
},
|
||||
callbacks = {}
|
||||
}
|
||||
@@ -87,12 +85,10 @@ local function itemDefToLuantiDef(itemDef)
|
||||
local modName = Mod.getInfo().shortName
|
||||
local S = core.get_translator(modName)
|
||||
|
||||
itemDef = tableCopy(itemDef)
|
||||
local s = itemDef.settings
|
||||
local c = itemDef.callbacks
|
||||
|
||||
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'
|
||||
@@ -103,7 +99,7 @@ local function itemDefToLuantiDef(itemDef)
|
||||
end
|
||||
|
||||
if s._title_color ~= nil and s._description_color ~= nil then
|
||||
title = colorize(s._title_color ,S(title))
|
||||
title = colorize(s._title_color , S(title))
|
||||
description = colorize(s._description_color, S(description))
|
||||
else
|
||||
error('Item description color parameters cannot be empty.')
|
||||
@@ -111,7 +107,7 @@ local function itemDefToLuantiDef(itemDef)
|
||||
|
||||
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||
|
||||
local luantiDescription = addRarityToDesc(s._rarity, title..'\n'..description)
|
||||
local luantiDescription = addRarityToDesc(s._rarity, title..'\n '..description)
|
||||
|
||||
s._title = title
|
||||
s._description = description
|
||||
@@ -123,7 +119,7 @@ local function itemDefToLuantiDef(itemDef)
|
||||
end
|
||||
|
||||
---@param luantiDef NodeDefinition
|
||||
local function register3dItem(luantiDef)
|
||||
local function registerNode(luantiDef)
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
@@ -131,13 +127,21 @@ local function register3dItem(luantiDef)
|
||||
end
|
||||
|
||||
---@param luantiDef ItemDefinition
|
||||
local function registerFlatItem(luantiDef)
|
||||
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(...)
|
||||
@@ -152,40 +156,48 @@ function Item:new(itemDef)
|
||||
'Please note that the `description` field should not be used when registering an item. '..
|
||||
'Use `_title` and `_description` instead.')
|
||||
|
||||
itemDef = tableCopy(itemDef)
|
||||
|
||||
-- Adding default parameters
|
||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||
local s = itemDef.settings
|
||||
|
||||
local shortModName = Mod.getInfo().shortName
|
||||
|
||||
if s._add_mod_name then
|
||||
s.name = Mod.getInfo().shortName .. ':' .. s.name
|
||||
s.name = shortModName .. ':' .. 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
|
||||
instance.luantiDef = luantiDef
|
||||
|
||||
Smc.addRegisteredItem(shortModName, instance)
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -195,7 +207,7 @@ end
|
||||
---@param defaultDef Item.ItemDefinition
|
||||
---@return Item
|
||||
function Item:getExtended(defaultDef)
|
||||
defaultDef = defMerge(defaultDef, self.defaultDef)
|
||||
defaultDef = defMerge(defaultDef, self.defaultDef, true)
|
||||
|
||||
---@type Item
|
||||
local ChildClass = extend(self, {
|
||||
@@ -212,7 +224,7 @@ function Item:getFactory(defaultDef)
|
||||
if defaultDef == nil then
|
||||
defaultDef = self.defaultDef
|
||||
else
|
||||
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||
defaultDef = defMerge(self.defaultDef, defaultDef, true)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
|
||||
@@ -33,8 +33,8 @@ Settings._title_color = nil
|
||||
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?
|
||||
|
||||
1
mods/CORE/Item/src/Item/Type.lua
Normal file
@@ -0,0 +1 @@
|
||||
---@alias Item.Type 'craftitem'|'node'|'tool'
|
||||
@@ -1 +0,0 @@
|
||||
---@alias Item.Visual 'item_2d'|'item_3d'
|
||||
@@ -1,11 +1,28 @@
|
||||
local mathAbs, mathRound, mathMin, mathMax, id
|
||||
= math.abs, math.round, math.min, math.max, core.get_content_id
|
||||
local mathAbs, mathRound, mathMin, mathMax, id, posToString
|
||||
= math.abs, math.round, math.min, math.max, core.get_content_id, core.pos_to_string
|
||||
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
local LOG_PROFILE = false
|
||||
|
||||
local function calculateAverage(t)
|
||||
if #t == 0 then return 0 end -- Защита от деления на ноль
|
||||
local sum = 0
|
||||
for i = 1, #t do
|
||||
sum = sum + t[i]
|
||||
end
|
||||
return sum / #t
|
||||
end
|
||||
|
||||
local function mglog(text, ...)
|
||||
core.log((text):format(...))
|
||||
end
|
||||
|
||||
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>
|
||||
@@ -21,15 +38,9 @@ local Layer = require('MapGen.Layer')
|
||||
---@type MapGen.StaticLayer
|
||||
local StaticLayer = require('MapGen.StaticLayer')
|
||||
|
||||
---@type MapGen.Peak
|
||||
local Peak = require('MapGen.Peak')
|
||||
|
||||
---@type MapGen.Biome
|
||||
local Biome = require('MapGen.Biome')
|
||||
|
||||
---@type MapGen.Triangulation
|
||||
local Triangulation = require('MapGen.Triangulation')
|
||||
|
||||
---@type MapGen.Cavern
|
||||
local Cavern = require('MapGen.Cavern')
|
||||
|
||||
@@ -201,7 +212,7 @@ end
|
||||
function MapGen:pointInRegion2D(layer, regionName, point)
|
||||
local region = layer.regionsByName[regionName]
|
||||
|
||||
assert(layer ~= nil, ('There is no region named `%s` registered.'):format(regionName))
|
||||
assert(region ~= nil, ('There is no region named `%s` registered.'):format(regionName))
|
||||
|
||||
return region:pointInRegion(point)
|
||||
end
|
||||
@@ -416,121 +427,6 @@ function MapGen:registerStaticLayer(name, def)
|
||||
end)
|
||||
end
|
||||
|
||||
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
||||
---
|
||||
---Note: The peaks shouldn't overlap.
|
||||
---@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 def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
||||
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))
|
||||
|
||||
---@type MapGen.Peak
|
||||
local peak = Peak:new(def)
|
||||
|
||||
layer:addPeak(category, peak)
|
||||
end
|
||||
|
||||
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||
---
|
||||
---Note: The peaks shouldn't overlap.
|
||||
---@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 def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
||||
function MapGen:register2DPeak(layerName, category, def)
|
||||
def = table.copy_with_metatables(def)
|
||||
|
||||
def.pos.y = 0
|
||||
|
||||
if def.groups == nil then
|
||||
def.groups = {is2d = 1}
|
||||
else
|
||||
def.groups.is2d = 1
|
||||
end
|
||||
|
||||
self:registerPeak(layerName, category, def)
|
||||
end
|
||||
|
||||
---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect generation.
|
||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||
---
|
||||
---Note: The peaks shouldn't overlap.
|
||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
||||
---@param defs MapGen.PeakDef[] Peaks description table, see details `MapGen.PeakDef`.
|
||||
function MapGen:register2DPeaks(layerName,category, defs)
|
||||
for _, def in ipairs(defs) do
|
||||
self:register2DPeak(layerName, category, def)
|
||||
end
|
||||
end
|
||||
|
||||
---Extract the `MapGen.Peak` from the image and assign them all a specific color that will affect the generation.
|
||||
---@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 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)
|
||||
if scale < 2 then
|
||||
error('The map scale should not be less than 2.')
|
||||
end
|
||||
|
||||
local modPath = core.get_modpath(core.get_current_modname())
|
||||
local peaks = ff2luat(modPath .. '/textures/maps/' .. map)
|
||||
|
||||
---@type {h:integer, w:integer}
|
||||
local mapSize = peaks.size
|
||||
peaks.size = nil
|
||||
|
||||
zeroPos.x = zeroPos.x + mathRound(mapSize.w/2)
|
||||
zeroPos.y = zeroPos.y + mathRound(mapSize.h/2)
|
||||
|
||||
local x, z
|
||||
|
||||
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 = mathRound(x + (scale/2))
|
||||
end
|
||||
|
||||
---@type MapGen.PeakDef
|
||||
local def = {
|
||||
pos = {x=x, y=0, z=z},
|
||||
color = color,
|
||||
groups = groups,
|
||||
}
|
||||
|
||||
self:register2DPeak(layerName, category, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Adds groups to the already registered groups in the peak by coordinate.
|
||||
---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 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)
|
||||
|
||||
local peak = self:getPeakByPos(layer, category, pos)
|
||||
assert( peak ~= nil, ('In the `%s` layer in the `%s` category there is no peak with coordinates: %s, %s, %s.'):format(
|
||||
layerName, category, pos.x, pos.y, pos.z))
|
||||
|
||||
peak:addGroups(groups)
|
||||
end
|
||||
|
||||
---Mark a point on the biomes diagram and constrain the world area by height to mark it as `MapGen.Biome`.
|
||||
---@param layerName string The name of the layer in which the new biome will be included.
|
||||
---@param biomeName string The name to be assigned to the biome. The name must be unique for each biome.
|
||||
@@ -586,11 +482,11 @@ end
|
||||
|
||||
-- --- INITIALIZATION METHODS ---
|
||||
|
||||
---Initialize the boundary region for a triangulated area.
|
||||
---Initialize the boundary region for a layer and category.
|
||||
---@param layer MapGen.Layer
|
||||
---@param category MapGen.Layer.Category
|
||||
---@param triangles MapGen.Triangle[]
|
||||
function MapGen:initTriangultaionBoundaryRegion(layer, category, triangles)
|
||||
function MapGen:initTriangultaionBoundaryRegion(layer, category)
|
||||
local triangles = layer.trianglesList[category]
|
||||
local regionVertices = self:getTriangulateBoundaryVertices(triangles)
|
||||
|
||||
local regionName = category..'_boundary'
|
||||
@@ -600,17 +496,13 @@ function MapGen:initTriangultaionBoundaryRegion(layer, category, triangles)
|
||||
layer:addRegion(regionName, region)
|
||||
end
|
||||
|
||||
---Divide all layers into triangles whose vertices are the `Mapgen.Peak` belonging to these layers.
|
||||
function MapGen:initLayersTriangultaion()
|
||||
---Initialize border regions for all layers and all categories.
|
||||
function MapGen:initLayersBoundaryRegions()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
for category, peaks in pairs(layer.peaksList) do
|
||||
local triangles = Triangulation.triangulate(peaks)
|
||||
|
||||
layer.trianglesList[category] = triangles
|
||||
self:initTriangultaionBoundaryRegion(layer, category, triangles)
|
||||
-- layer.tetrahedronsList = Triangulation.tetrahedralize(layer.peaksList) -- 3D not supported
|
||||
end
|
||||
self:initTriangultaionBoundaryRegion(layer, 'landscape')
|
||||
self:initTriangultaionBoundaryRegion(layer, 'temp')
|
||||
self:initTriangultaionBoundaryRegion(layer, 'humidity')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -649,26 +541,59 @@ 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
|
||||
@@ -695,33 +620,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...
|
||||
@@ -729,10 +660,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
|
||||
@@ -839,14 +772,14 @@ function MapGen:getNoises2dValue(category, layer, x, y, z)
|
||||
|
||||
local triangles = {
|
||||
pastCalc.triangle,
|
||||
pastCalc.triangle.neighbours.t1,
|
||||
pastCalc.triangle.neighbours.t2,
|
||||
pastCalc.triangle.neighbours.t3,
|
||||
pastCalc.triangle.neighbours[1],
|
||||
pastCalc.triangle.neighbours[2],
|
||||
pastCalc.triangle.neighbours[3],
|
||||
}
|
||||
|
||||
---@param t MapGen.Triangle
|
||||
for _, t in ipairs(triangles) do
|
||||
if pointInTriangle2D(x, z, t) then
|
||||
if pointInTriangle2D(x, z, t) then
|
||||
noiseValue = calcNoise2dValue(category, layer, t, x, y, z)
|
||||
|
||||
pastCalc.x = x
|
||||
@@ -881,96 +814,6 @@ function MapGen:getNoises2dValue(category, layer, x, y, z)
|
||||
--core.log('warning', string.format('The point %s %s %s does not fall within any triangle, calculating the noise value is impossible.', tostring(x), tostring(y), tostring(z)))
|
||||
end
|
||||
|
||||
--[[
|
||||
3D noise smoothing is too slow, so it was decided to stop using it.
|
||||
|
||||
---@param P vector
|
||||
---@param A vector
|
||||
---@param B vector
|
||||
---@param C vector
|
||||
local function pointInTetrahedron(P, A, B, C, D)
|
||||
local function det3(a, b, c)
|
||||
return a.x * (b.y * c.z - b.z * c.y)
|
||||
- a.y * (b.x * c.z - b.z * c.x)
|
||||
+ a.z * (b.x * c.y - b.y * c.x)
|
||||
end
|
||||
|
||||
local v0 = B - A
|
||||
local v1 = C - A
|
||||
local v2 = D - A
|
||||
local v3 = P - A
|
||||
|
||||
local d = det3(v0, v1, v2)
|
||||
|
||||
local u = det3(v3, v1, v2) / d
|
||||
local v = det3(v0, v3, v2) / d
|
||||
local w = det3(v0, v1, v3) / d
|
||||
|
||||
return (u >= 0 and v >= 0 and w >= 0 and (u + v + w) <= 1)
|
||||
end
|
||||
|
||||
---Calculates a smoothed 3D noise value based on a preliminary space partitioning.
|
||||
---
|
||||
---Returns `nil` if the point is not included in any tetrahedron.
|
||||
---
|
||||
---@param layer MapGen.Layer
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
---@return number?
|
||||
function MapGen:getNoises3dValues(layer, x, y, z)
|
||||
---@param triangle MapGen.Tetrahedron
|
||||
for _, tetrahedron in ipairs(layer.tetrahedronsList) do
|
||||
local peak1 = tetrahedron.p1
|
||||
local peak2 = tetrahedron.p2
|
||||
local peak3 = tetrahedron.p3
|
||||
local peak4 = tetrahedron.p4
|
||||
|
||||
local pos1 = peak1:getPeakPos()
|
||||
local pos2 = peak2:getPeakPos()
|
||||
local pos3 = peak3:getPeakPos()
|
||||
local pos4 = peak4:getPeakPos()
|
||||
|
||||
-- If the point is in the tetrahedron defined by the `MapGen.Peak`...
|
||||
if pointInTetrahedron(
|
||||
vector.new(x, y, z),
|
||||
pos1,
|
||||
pos2,
|
||||
pos3,
|
||||
pos4
|
||||
)
|
||||
then
|
||||
local noiseValue = 0.0
|
||||
|
||||
local totalWeight = 0.0
|
||||
|
||||
-- ... we calculate the height for this point using smoothing.
|
||||
local weight = calcWeight(tetrahedron.h1, x, y, z)
|
||||
noiseValue = noiseValue + peak1:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
||||
totalWeight = totalWeight + weight
|
||||
|
||||
weight = calcWeight(tetrahedron.h2, x, y, z)
|
||||
noiseValue = noiseValue + peak1:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
||||
totalWeight = totalWeight + weight
|
||||
|
||||
weight = calcWeight(tetrahedron.h3, x, y, z)
|
||||
noiseValue = noiseValue + peak2:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
||||
totalWeight = totalWeight + weight
|
||||
|
||||
weight = calcWeight(tetrahedron.h4, x, y, z)
|
||||
noiseValue = noiseValue + peak3:getMultinoise().someNoise:get_2d({x = x, y = y, z = z}) * weight
|
||||
totalWeight = totalWeight + weight
|
||||
|
||||
return mathRound(noiseValue / totalWeight)
|
||||
end
|
||||
end
|
||||
|
||||
-- If the point does not fall within the tetrahedron, it is impossible to calculate the height.
|
||||
-- For debugging purposes only, may slow down generation:
|
||||
-- core.log('warning', string.format('The point %s %s %s does not fall within any tetrahedron, calculating the noise value is impossible.', tostring(x), tostring(y), tostring(z)))
|
||||
end
|
||||
--]]
|
||||
|
||||
---Generator handler for specific coordinates.
|
||||
---@param mapGenerator MapGen
|
||||
---@param data number[]
|
||||
@@ -978,13 +821,15 @@ end
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@param z integer
|
||||
---@return number, number, number
|
||||
local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||
local startGetLayerTime = core.get_us_time()
|
||||
-- If the node belongs to a static layer, then a static node is generated.
|
||||
local static = mapGenerator:getStaticByHeight(y)
|
||||
if static ~= nil then
|
||||
static:generateStaticNode(mapGenerator, data, index, x, y, z)
|
||||
|
||||
return
|
||||
return core.get_us_time() - startGetLayerTime, 0, 0
|
||||
end
|
||||
|
||||
-- If generation occurs outside the layers, then a void is generated.
|
||||
@@ -992,34 +837,53 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||
if layer == nil then
|
||||
data[index] = mapGenerator.nodeIDs.air
|
||||
|
||||
return
|
||||
return core.get_us_time() - startGetLayerTime, 0, 0
|
||||
end
|
||||
|
||||
local endGetLayerTime = core.get_us_time()
|
||||
local startNoiseCalcTime = endGetLayerTime
|
||||
-- If the value of the noise is `nil`,
|
||||
-- then the point does not fall within any of the triangles.
|
||||
local noiseHeightValue = mapGenerator:getNoises2dValue('landscape', layer, x, y, z)
|
||||
if noiseHeightValue == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
return
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
local noiseTempValue = mapGenerator:getNoises2dValue('temp', layer, x, y, z)
|
||||
if noiseTempValue == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
return
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
local noiseHumidityValue = mapGenerator:getNoises2dValue('humidity', layer, x, y, z)
|
||||
if noiseHumidityValue == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
return
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
-- We recalculate the climate based on altitude.
|
||||
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,
|
||||
}
|
||||
|
||||
local endNoiseCalcTime = core.get_us_time()
|
||||
local startGenNodeTime = endNoiseCalcTime
|
||||
|
||||
generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
||||
|
||||
local endGenNodeTime = core.get_us_time()
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, endNoiseCalcTime - startNoiseCalcTime, endGenNodeTime - startGenNodeTime
|
||||
end
|
||||
|
||||
---Chunk generation handler.
|
||||
@@ -1028,8 +892,16 @@ end
|
||||
---@param maxPos MapPosition
|
||||
---@param blockseed number
|
||||
function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
-- We obtain a generation area for further manipulations
|
||||
--local voxelManip, eMin, eMax = core.get_mapgen_object('voxelmanip')
|
||||
local minPosStr, maxPosStr = posToString(minPos), posToString(maxPos)
|
||||
local getLayerTime, NoiseCalcTime, GenNodeTime = {}, {}, {}
|
||||
|
||||
if LOG_PROFILE then
|
||||
mglog('Chunk run:\n'..
|
||||
'min_pos: %s\n'..
|
||||
'max_pos: %s\n',
|
||||
minPosStr, maxPosStr)
|
||||
end
|
||||
local startTime = core.get_us_time()
|
||||
|
||||
local eMin, eMax = voxelManip:get_emerged_area()
|
||||
|
||||
@@ -1053,12 +925,32 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
index = area:index(x, y, z)
|
||||
|
||||
if data[index] == core.CONTENT_AIR then
|
||||
generatorHandler(self, data, index, x, y, z)
|
||||
local t1, t2, t3 = generatorHandler(self, data, index, x, y, z)
|
||||
|
||||
table.insert(getLayerTime, t1)
|
||||
table.insert(NoiseCalcTime, t2)
|
||||
table.insert(GenNodeTime, t3)
|
||||
end
|
||||
end
|
||||
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)
|
||||
|
||||
@@ -1070,7 +962,20 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
voxelManip:calc_lighting()
|
||||
voxelManip:update_liquids()
|
||||
|
||||
--voxelManip:write_to_map() -- Async edit
|
||||
local endTime = core.get_us_time()
|
||||
if LOG_PROFILE then
|
||||
mglog('Chunk end:\n'..
|
||||
'min_pos: %s\n'..
|
||||
'max_pos: %s\n'..
|
||||
'time (sec): %.3f\n'..
|
||||
'GenerateHandler time (us): %.3f %.3f %.3f\n'..
|
||||
'---------------',
|
||||
minPosStr, maxPosStr,
|
||||
(endTime - startTime)/1000000,
|
||||
calculateAverage(getLayerTime),
|
||||
calculateAverage(NoiseCalcTime),
|
||||
calculateAverage(GenNodeTime))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1093,9 +998,10 @@ function MapGen:run()
|
||||
end)
|
||||
|
||||
self:initBiomesDiagram()
|
||||
self:initLayersTriangultaion()
|
||||
self:initLayersBoundaryRegions()
|
||||
|
||||
MapGen.isRunning = true
|
||||
core.log('MapGen run')
|
||||
end
|
||||
|
||||
return MapGen
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type MapGen.Peak
|
||||
local Peak = require('MapGen.Peak')
|
||||
---@type MapGen.Triangle
|
||||
local Triangle = require('MapGen.Triangle')
|
||||
|
||||
---@class MapGen.Layer
|
||||
---@field name string
|
||||
---@field minY integer
|
||||
@@ -11,9 +19,10 @@ local getInstance = Class.getInstance
|
||||
---@field waterLevel integer
|
||||
---@field calcTemp fun(self:MapGen.Layer, value:number, height:number):number
|
||||
---@field calcHumidity fun(self:MapGen.Layer, value:number, height:number):number
|
||||
---@field peaksList {['landscape']:MapGen.Peak[],['temp']:MapGen.Peak[],['humidity']:MapGen.Peak[]}
|
||||
---@field noisesByColor {['landscape']:table<ColorString, ValueNoise>,['temp']:table<ColorString, ValueNoise>,['humidity']:table<ColorString, ValueNoise>}
|
||||
---@field noisesParamsByColor {['landscape']:table<ColorString, NoiseParams>,['temp']:table<ColorString, NoiseParams>,['humidity']:table<ColorString, NoiseParams>}
|
||||
---@field peaksList table<MapGen.Layer.Category, MapGen.Peak[]>
|
||||
---@field peaksByPos table<MapGen.Layer.Category, table<string, MapGen.Peak>>
|
||||
---@field noisesByColor table<MapGen.Layer.Category, table<ColorString, ValueNoise>>
|
||||
---@field noisesParamsByColor table<MapGen.Layer.Category, table<ColorString, NoiseParams>>
|
||||
---@field biomesByName table<string, MapGen.Biome>
|
||||
---@field biomesList MapGen.Biome[]
|
||||
---@field biomesDiagram table
|
||||
@@ -22,10 +31,14 @@ local getInstance = Class.getInstance
|
||||
---@field cavernsByName table<string, MapGen.Cavern>
|
||||
---@field cavernsList MapGen.Cavern[]
|
||||
---@field regionsByName table<string, MapGen.Region>
|
||||
---@field trianglesList {['landscape']:MapGen.Triangle[],['temp']:MapGen.Triangle[],['humidity']:MapGen.Triangle[]}
|
||||
---@field tetrahedronsList MapGen.Tetrahedron[] **Not supported**
|
||||
---@field trianglesList table<MapGen.Layer.Category, MapGen.Triangle[]>
|
||||
local Layer = {
|
||||
peaksList = {
|
||||
peaksList = {
|
||||
landscape = {},
|
||||
temp = {},
|
||||
humidity = {},
|
||||
},
|
||||
peaksByPos = {
|
||||
landscape = {},
|
||||
temp = {},
|
||||
humidity = {},
|
||||
@@ -58,17 +71,23 @@ local Layer = {
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGen.LayerDef
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field minTemp number
|
||||
---@field maxTemp number
|
||||
---@field minHumidity number
|
||||
---@field maxHumidity number
|
||||
---@field waterLevel? number
|
||||
---@field minY integer
|
||||
---@field maxY integer
|
||||
---@field minTemp integer
|
||||
---@field maxTemp integer
|
||||
---@field minHumidity integer
|
||||
---@field maxHumidity integer
|
||||
---@field waterLevel? integer
|
||||
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||
---@field biomesGorizontalScattering number?
|
||||
---@field biomesVerticalScattering number?
|
||||
---@field biomesGorizontalScattering integer?
|
||||
---@field biomesVerticalScattering integer?
|
||||
---@field triangulationLandscapeFile string
|
||||
---@field triangulationTempFile string
|
||||
---@field triangulationHumidityFile string
|
||||
---@field landscapeMapScale number
|
||||
---@field tempMapScale number
|
||||
---@field humidityMapScale number
|
||||
|
||||
---@param self MapGen.Layer
|
||||
---@param value number
|
||||
@@ -78,6 +97,74 @@ local function defaultCalcFunc(self, value, height)
|
||||
return value
|
||||
end
|
||||
|
||||
---Checks `def` for compliance with `MapGen.PeakDef` and creates a new peak
|
||||
---if a peak with such coordinates has not yet been registered or returns an existing one.
|
||||
---
|
||||
---**Note:** If the colors of the new peak and the existing one at the same coordinates
|
||||
---are different, an error will be called.
|
||||
---@param def MapGen.PeakDef
|
||||
---@param category MapGen.Layer.Category
|
||||
---@param scale number
|
||||
---@return MapGen.Peak
|
||||
function Layer:registerPeak(def, category, scale)
|
||||
assert(def.pos ~= nil)
|
||||
assert(def.pos.x ~= nil)
|
||||
assert(def.pos.z ~= nil)
|
||||
assert(def.color ~= nil)
|
||||
assert(type(def.color) == 'string')
|
||||
|
||||
def.pos.x = def.pos.x * scale
|
||||
def.pos.z = def.pos.z * scale
|
||||
def.pos.y = 0
|
||||
|
||||
local positionStr = core.pos_to_string(def.pos)
|
||||
|
||||
local peak = self.peaksByPos[category][positionStr]
|
||||
|
||||
if peak == nil then
|
||||
peak = Peak:new(def)
|
||||
self.peaksByPos[category][positionStr] = peak
|
||||
elseif peak.getColor() ~= def.color then
|
||||
error('There cannot be two peaks with the same coordinates but different colors.')
|
||||
end
|
||||
|
||||
return peak
|
||||
end
|
||||
|
||||
function Layer:initTrianglesNeighbours()
|
||||
for _, triangles in pairs(self.trianglesList) do
|
||||
for _, triangle in ipairs(triangles) do
|
||||
for _, id in ipairs(triangle.neighboursIDs) do
|
||||
table.insert(triangle.neighbours, triangles[id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param fileName string
|
||||
---@param category MapGen.Layer.Category
|
||||
---@param scale number
|
||||
function Layer:getTriaglesFromFile(fileName, category, scale)
|
||||
local file = io.open(core.get_modpath(core.get_current_modname())..'/maps/'..fileName, 'r')
|
||||
assert(file ~= nil)
|
||||
|
||||
local json = core.parse_json(file:read('*a')) or {}
|
||||
file:close()
|
||||
|
||||
local triangles = json.triangles
|
||||
assert(triangles ~= nil)
|
||||
|
||||
for _, tr in ipairs(triangles) do
|
||||
local p1 = self:registerPeak( tr.vertices[1], category, scale)
|
||||
local p2 = self:registerPeak( tr.vertices[2], category, scale)
|
||||
local p3 = self:registerPeak( tr.vertices[3], category, scale)
|
||||
|
||||
local triangle = Triangle:new(tr.id,p1, p2, p3, tr.adjacent_triangle_ids)
|
||||
|
||||
self:addTriangle(category, triangle)
|
||||
end
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param def MapGen.LayerDef
|
||||
---@return MapGen.Layer
|
||||
@@ -93,20 +180,34 @@ function Layer:new(name, def)
|
||||
end
|
||||
|
||||
---@type MapGen.Layer
|
||||
local instance = getInstance(self, {
|
||||
name = name,
|
||||
minY = def.minY,
|
||||
maxY = def.maxY,
|
||||
minTemp = def.minTemp,
|
||||
maxTemp = def.maxTemp,
|
||||
minHumidity = def.minHumidity,
|
||||
maxHumidity = def.maxHumidity,
|
||||
waterLevel = def.waterLevel or 0,
|
||||
calcTemp = def.calcTemp,
|
||||
calcHumidity = def.calcHumidity,
|
||||
biomesGorizontalScattering = def.biomesGorizontalScattering or 0,
|
||||
biomesVerticalScattering = def.biomesVerticalScattering or 0,
|
||||
})
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.minY = def.minY
|
||||
instance.maxY = def.maxY
|
||||
instance.minTemp = def.minTemp
|
||||
instance.maxTemp = def.maxTemp
|
||||
instance.minHumidity = def.minHumidity
|
||||
instance.maxHumidity = def.maxHumidity
|
||||
instance.waterLevel = def.waterLevel or 0
|
||||
instance.calcTemp = def.calcTemp
|
||||
instance.calcHumidity = def.calcHumidity
|
||||
instance.biomesGorizontalScattering = def.biomesGorizontalScattering or 0
|
||||
instance.biomesVerticalScattering = def.biomesVerticalScattering or 0
|
||||
|
||||
instance:getTriaglesFromFile(
|
||||
def.triangulationLandscapeFile,
|
||||
'landscape',
|
||||
def.landscapeMapScale)
|
||||
instance:getTriaglesFromFile(
|
||||
def.triangulationTempFile,
|
||||
'temp',
|
||||
def.tempMapScale)
|
||||
instance:getTriaglesFromFile(
|
||||
def.triangulationHumidityFile,
|
||||
'humidity',
|
||||
def.humidityMapScale)
|
||||
|
||||
instance:initTrianglesNeighbours()
|
||||
|
||||
return instance
|
||||
end
|
||||
@@ -114,6 +215,18 @@ end
|
||||
---A category of noise that affects specific map generation objects.
|
||||
---@alias MapGen.Layer.Category 'landscape'|'temp'|'humidity'
|
||||
|
||||
---Adds a triangle to the `Layer.trianglesList`
|
||||
---@param category MapGen.Layer.Category
|
||||
---@param triangle MapGen.Triangle
|
||||
function Layer:addTriangle(category, triangle)
|
||||
local triangles = self.trianglesList[category]
|
||||
if triangles ~= nil then
|
||||
triangles[triangle.id] = triangle
|
||||
else
|
||||
error(('There is no peak category named %s.'):format(category))
|
||||
end
|
||||
end
|
||||
|
||||
---Adds a peak to the `Layer.peaksList`
|
||||
---@param category MapGen.Layer.Category
|
||||
---@param peak MapGen.Peak
|
||||
@@ -134,14 +247,11 @@ end
|
||||
---@param pos Position Coordinate of the desired peak.
|
||||
---@return MapGen.Peak?
|
||||
function Layer:getPeakByPos(category, pos)
|
||||
pos = vector.new(pos)
|
||||
local positionStr = core.pos_to_string(pos)
|
||||
|
||||
---@param peak MapGen.Peak
|
||||
for _, peak in ipairs(self.peaksList[category]) do
|
||||
if peak:getPeakPos() == pos then
|
||||
return peak
|
||||
end
|
||||
end
|
||||
local peak = self.peaksByPos[category][positionStr]
|
||||
|
||||
return peak
|
||||
end
|
||||
|
||||
---Adds a NoiseParams color to the `Layer.noisesParamsByColor`
|
||||
|
||||
@@ -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,155 +0,0 @@
|
||||
---@diagnostic disable: param-type-not-match
|
||||
local mathAbs = math.abs
|
||||
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type MapGen.Triangle
|
||||
local Triangle = require('MapGen.Triangle')
|
||||
---@type MapGen.Triangulation.Edge
|
||||
local Edge = require('MapGen.Triangulation.Edge')
|
||||
---@type MapGen.Triangulation.FakePeak
|
||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
||||
|
||||
---@class MapGen.Tetrahedron
|
||||
---@field p1 MapGen.Peak
|
||||
---@field p2 MapGen.Peak
|
||||
---@field p3 MapGen.Peak
|
||||
---@field p4 MapGen.Peak
|
||||
---@field h1 MapGen.Triangulation.Edge
|
||||
---@field h2 MapGen.Triangulation.Edge
|
||||
---@field h3 MapGen.Triangulation.Edge
|
||||
---@field h4 MapGen.Triangulation.Edge
|
||||
---@field f1 MapGen.Triangle
|
||||
---@field f2 MapGen.Triangle
|
||||
---@field f3 MapGen.Triangle
|
||||
---@field f4 MapGen.Triangle
|
||||
local Tetrahedron = {}
|
||||
|
||||
---@param p1 MapGen.Peak
|
||||
---@param p2 MapGen.Peak
|
||||
---@param p3 MapGen.Peak
|
||||
---@param p4 MapGen.Peak
|
||||
---@return MapGen.Tetrahedron
|
||||
function Tetrahedron:new(p1, p2, p3, p4)
|
||||
local instance = getInstance(self, {
|
||||
p1 = p1,
|
||||
p2 = p2,
|
||||
p3 = p3,
|
||||
p4 = p4,
|
||||
h1 = self:getHeight(p1, p2, p3, p4),
|
||||
h2 = self:getHeight(p2, p3, p4, p1),
|
||||
h3 = self:getHeight(p3, p4, p1, p2),
|
||||
h4 = self:getHeight(p4, p1, p2, p3),
|
||||
f1 = Triangle:new(p1, p2, p3),
|
||||
f2 = Triangle:new(p1, p2, p4),
|
||||
f3 = Triangle:new(p1, p3, p4),
|
||||
f4 = Triangle:new(p2, p3, p4),
|
||||
},
|
||||
{
|
||||
__tostring = self.toString
|
||||
})
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Returns a string describing the object in a readable form.
|
||||
---@return string
|
||||
function Tetrahedron:toString()
|
||||
return ('Tetrahedron: \n %s\n %s\n %s\n %s'):format(
|
||||
tostring(self.p1.getPeakPos()),
|
||||
tostring(self.p2.getPeakPos()),
|
||||
tostring(self.p3.getPeakPos()),
|
||||
tostring(self.p4.getPeakPos())
|
||||
)
|
||||
end
|
||||
|
||||
---@param p1 MapGen.Peak
|
||||
---@param p2 MapGen.Peak
|
||||
---@param p3 MapGen.Peak
|
||||
---@param p4 MapGen.Peak
|
||||
function Tetrahedron:getHeight(p1, p2, p3, p4)
|
||||
local pos1 = p1:getPeakPos()
|
||||
local pos2 = p2:getPeakPos()
|
||||
local pos3 = p3:getPeakPos()
|
||||
local pos4 = p4:getPeakPos()
|
||||
|
||||
-- Векторы, лежащие в плоскости
|
||||
local AB = pos3 - pos2
|
||||
local AC = pos4 - pos2
|
||||
|
||||
-- Нормаль к плоскости
|
||||
local normal = AB:cross(AC)
|
||||
local normal_length = normal:length()
|
||||
|
||||
-- Если плоскость вырождена (точки на одной прямой)
|
||||
if normal_length < 1e-10 then
|
||||
return nil -- или другая обработка ошибки
|
||||
end
|
||||
|
||||
-- Вектор от точки на плоскости к нашей точке
|
||||
local AP = pos1 - pos2
|
||||
|
||||
-- Расстояние от точки до плоскости
|
||||
local distance = AP:dot(normal) / normal_length
|
||||
|
||||
-- Проекция точки на плоскость (вектор!)
|
||||
local projection = pos1 - (normal * (distance / normal_length))
|
||||
|
||||
return Edge:new(p1, FakePeak:new(projection))
|
||||
end
|
||||
|
||||
---Returns the center of the circumscribed sphere.
|
||||
---@return vector
|
||||
function Tetrahedron:getCircumSphereCenter()
|
||||
local pos1 = self.p1.getPeakPos()
|
||||
local pos2 = self.p2.getPeakPos()
|
||||
local pos3 = self.p3.getPeakPos()
|
||||
local pos4 = self.p4.getPeakPos()
|
||||
|
||||
local a = pos2 - pos1
|
||||
local b = pos3 - pos1
|
||||
local c = pos4 - pos1
|
||||
|
||||
local a2 = a:dot(a)
|
||||
local b2 = b:dot(b)
|
||||
local c2 = c:dot(c)
|
||||
|
||||
local cross_bc = b:cross(c)
|
||||
local cross_ca = c:cross(a)
|
||||
local cross_ab = a:cross(b)
|
||||
|
||||
local det = a:dot(b:cross(c)) * 2
|
||||
|
||||
if mathAbs(det) < 0 then
|
||||
return (pos1 + pos2 + pos3 + pos4) / 4
|
||||
end
|
||||
|
||||
local center = pos1 + (cross_bc * a2 + cross_ca * b2 + cross_ab * c2) / det
|
||||
|
||||
return center
|
||||
end
|
||||
|
||||
---Returns the radius of the circumscribed sphere.
|
||||
---@return number
|
||||
function Tetrahedron:getCircumSphereRadius()
|
||||
local center = self:getCircumSphereCenter()
|
||||
local pos1 = self.p1.getPeakPos()
|
||||
return (pos1 - center):length()
|
||||
end
|
||||
|
||||
---Checks whether a given point lies within the circumscribed sphere of a tetrahedron.
|
||||
---@param p MapGen.Peak
|
||||
function Tetrahedron:inCircumSphere(p)
|
||||
local pos = p.getPeakPos()
|
||||
local c = self:getCircumSphereCenter()
|
||||
local r = self:getCircumSphereRadius()
|
||||
|
||||
local distance = (pos - c):length()
|
||||
|
||||
return distance <= r
|
||||
end
|
||||
|
||||
return Tetrahedron
|
||||
@@ -63,6 +63,7 @@ end
|
||||
---@alias MapGen.Triangle.Neighbours {t1:MapGen.Triangle?,t2:MapGen.Triangle?,t3:MapGen.Triangle?}
|
||||
|
||||
---@class MapGen.Triangle
|
||||
---@field id integer
|
||||
---@field p1 MapGen.Peak
|
||||
---@field p2 MapGen.Peak
|
||||
---@field p3 MapGen.Peak
|
||||
@@ -72,8 +73,9 @@ end
|
||||
---@field h1 MapGen.Triangulation.Edge
|
||||
---@field h2 MapGen.Triangulation.Edge
|
||||
---@field h3 MapGen.Triangulation.Edge
|
||||
---@field neighbours MapGen.Triangle.Neighbours
|
||||
---@field color ColorString?
|
||||
---@field neighboursIDs integer[]
|
||||
---@field neighbours MapGen.Triangle[]
|
||||
---@field color ColorString?
|
||||
local Triangle = {
|
||||
neighbours = {}
|
||||
}
|
||||
@@ -82,7 +84,7 @@ local Triangle = {
|
||||
---@param p2 MapGen.Peak
|
||||
---@param p3 MapGen.Peak
|
||||
---@return MapGen.Triangle
|
||||
function Triangle:new(p1, p2, p3)
|
||||
function Triangle:new(id, p1, p2, p3, neighboursIDs)
|
||||
assert(not isFlatAngle(p1, p2, p3), ("angle (p1, p2, p3) is flat:\n %s\n %s\n %s")
|
||||
:format(tostring(p1), tostring(p2), tostring(p3)))
|
||||
|
||||
@@ -96,6 +98,7 @@ function Triangle:new(p1, p2, p3)
|
||||
end
|
||||
|
||||
local instance = getInstance(self, {
|
||||
id = id,
|
||||
p1 = p1,
|
||||
p2 = p2,
|
||||
p3 = p3,
|
||||
@@ -105,7 +108,8 @@ function Triangle:new(p1, p2, p3)
|
||||
e1 = Edge:new(p1, p2),
|
||||
e2 = Edge:new(p2, p3),
|
||||
e3 = Edge:new(p3, p1),
|
||||
color = color
|
||||
neighboursIDs = neighboursIDs,
|
||||
color = color,
|
||||
},
|
||||
{
|
||||
__tostring = self.toString,
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
---@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
|
||||
-- Commit: e8d26241767cd6af377b5eda0c1e27122b6afe8a
|
||||
|
||||
-- Main changes:
|
||||
-- * refactoring code to our standard;
|
||||
-- * splitting code into different files (classes);
|
||||
-- * Adapting the code to the mapgen concept;
|
||||
-- * Adding tetrahedralization;
|
||||
-- * Fixed non-determinism by sorting vertices before processing;
|
||||
|
||||
local assert, mathMax, tableRemove, tableSort
|
||||
= assert, math.max, table.remove, table.sort
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type MapGen.Triangle
|
||||
local Triangle = require('MapGen.Triangle')
|
||||
---@type MapGen.Tetrahedron
|
||||
local Tetrahedron = require('MapGen.Tetrahedron')
|
||||
---@type MapGen.Triangulation.FakePeak
|
||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
||||
|
||||
---@class MapGen.Triangulation
|
||||
---@field convexMultiplier number
|
||||
local Triangulation = {
|
||||
convexMultiplier = 1e3,
|
||||
}
|
||||
|
||||
---Finds and writes adjacent triangles into triangles.
|
||||
---@param triangles MapGen.Triangle[]
|
||||
local function findTrianglesNeighbours(triangles)
|
||||
for _, triangle in ipairs(triangles) do
|
||||
for _, t in ipairs(triangles) do
|
||||
if triangle.e1 == t.e1 and triangle.p3 ~= t.p3 then
|
||||
triangle.neighbours.t1 = t
|
||||
elseif triangle.e2 == t.e2 and triangle.p3 ~= t.p1 then
|
||||
triangle.neighbours.t2 = t
|
||||
elseif triangle.e3 == t.e3 and triangle.p3 ~= t.p2 then
|
||||
triangle.neighbours.t3 = t
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Filter vertices by group and return a new table
|
||||
---@param vertices table<integer, MapGen.Peak>
|
||||
---@param groupKey string
|
||||
---@return table<integer, MapGen.Peak>
|
||||
local function filterVerticesByGroup(vertices, groupKey)
|
||||
local result = {}
|
||||
for i = 1, #vertices do
|
||||
local vertex = vertices[i]
|
||||
if vertex:getGroups()[groupKey] ~= nil then
|
||||
result[#result + 1] = vertex
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
---Sort vertices deterministically by position to ensure consistent triangulation
|
||||
---@param vertices table<integer, MapGen.Peak>
|
||||
local function sortVerticesDeterministically(vertices)
|
||||
tableSort(vertices, function(a, b)
|
||||
local posA = a:getPeakPos()
|
||||
local posB = b:getPeakPos()
|
||||
|
||||
-- Sort by X first
|
||||
if posA.x ~= posB.x then
|
||||
return posA.x < posB.x
|
||||
end
|
||||
|
||||
-- Then by Z
|
||||
if posA.z ~= posB.z then
|
||||
return posA.z < posB.z
|
||||
end
|
||||
|
||||
-- Then by Y
|
||||
if posA.y ~= posB.y then
|
||||
return posA.y < posB.y
|
||||
end
|
||||
|
||||
-- Fallback to unique identifier if positions are identical
|
||||
-- This handles potential duplicate positions
|
||||
local nameA = a.getName and a:getName() or ""
|
||||
local nameB = b.getName and b:getName() or ""
|
||||
return nameA < nameB
|
||||
end)
|
||||
end
|
||||
|
||||
---The Delaunay method divides a plane into triangles based on a list of their vertices.
|
||||
---
|
||||
---Doesn't take into account the Y coordinate of the vertices.
|
||||
---That is, all triangles that don't lie in the XZ plane will be projected onto it.
|
||||
---
|
||||
---Vertices that do not have a `is2d` group will not participate in the triangulation.
|
||||
---@param vertices table<integer, MapGen.Peak>
|
||||
function Triangulation.triangulate(vertices)
|
||||
-- Filter vertices with is2d group (creates a new table)
|
||||
vertices = filterVerticesByGroup(vertices, "is2d")
|
||||
|
||||
-- Sort deterministically to ensure consistent results across sessions
|
||||
sortVerticesDeterministically(vertices)
|
||||
|
||||
local nvertices = #vertices
|
||||
|
||||
assert(nvertices > 2, "Cannot triangulate, needs more than 3 vertices")
|
||||
|
||||
if nvertices == 3 then
|
||||
return {Triangle:new(vertices[1], vertices[2], vertices[3])}
|
||||
end
|
||||
|
||||
local minPos = vertices[1]:getPeakPos()
|
||||
local minX, minY = minPos.x, minPos.z
|
||||
local maxX, maxY = minX, minY
|
||||
|
||||
for i = 1, nvertices do
|
||||
local vertex = vertices[i]
|
||||
local vertexPos = vertex:getPeakPos()
|
||||
vertex.id = i
|
||||
|
||||
if vertexPos.x < minX then
|
||||
minX = vertexPos.x
|
||||
end
|
||||
|
||||
if vertexPos.z < minY then
|
||||
minY = vertexPos.z
|
||||
end
|
||||
|
||||
if vertexPos.x > maxX then
|
||||
maxX = vertexPos.x
|
||||
end
|
||||
|
||||
if vertexPos.z > maxY then
|
||||
maxY = vertexPos.z
|
||||
end
|
||||
end
|
||||
|
||||
-- Finding the vertices of a supertriangle
|
||||
local convex_mult = Triangulation.convexMultiplier
|
||||
local dx, dy = (maxX - minX) * convex_mult, (maxY - minY) * convex_mult
|
||||
local deltaMax = mathMax(dx, dy)
|
||||
local midx, midy = (minX + maxX) * 0.5, (minY + maxY) * 0.5
|
||||
|
||||
local p1 = FakePeak:new(vector.new(midx - 2 * deltaMax, 0, midy - deltaMax))
|
||||
local p2 = FakePeak:new(vector.new(midx, 0, midy + 2 * deltaMax))
|
||||
local p3 = FakePeak:new(vector.new(midx + 2 * deltaMax, 0, midy - deltaMax))
|
||||
|
||||
p1.id, p2.id, p3.id = nvertices + 1, nvertices + 2, nvertices + 3
|
||||
vertices[p1.id], vertices[p2.id], vertices[p3.id] = p1, p2, p3
|
||||
|
||||
---@type MapGen.Triangle[]
|
||||
local triangles = {Triangle:new(vertices[nvertices + 1], vertices[nvertices + 2], vertices[nvertices + 3])}
|
||||
|
||||
for i = 1, nvertices do
|
||||
---@type MapGen.Triangulation.Edge[]
|
||||
local edges = {}
|
||||
|
||||
-- Finding bad triangles.
|
||||
for j = #triangles, 1, -1 do
|
||||
local curTriangle = triangles[j]
|
||||
|
||||
if curTriangle:inCircumCircle2D(vertices[i]) then
|
||||
edges[#edges + 1] = curTriangle.e1
|
||||
edges[#edges + 1] = curTriangle.e2
|
||||
edges[#edges + 1] = curTriangle.e3
|
||||
tableRemove(triangles, j)
|
||||
end
|
||||
end
|
||||
|
||||
-- Removing duplicate edges.
|
||||
for j = #edges - 1, 1, -1 do
|
||||
for k = #edges, j + 1, -1 do
|
||||
if edges[j] and edges[k] and edges[j]:same(edges[k]) then
|
||||
tableRemove(edges, j)
|
||||
tableRemove(edges, k - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Create new triangles.
|
||||
for j = 1, #edges do
|
||||
triangles[#triangles + 1] = Triangle:new(edges[j].p1, edges[j].p2, vertices[i])
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove triangles associated with the vertices of a supertriangle.
|
||||
for i = #triangles, 1, -1 do
|
||||
local triangle = triangles[i]
|
||||
if triangle.p1.id > nvertices or triangle.p2.id > nvertices or triangle.p3.id > nvertices then
|
||||
tableRemove(triangles, i)
|
||||
end
|
||||
end
|
||||
|
||||
-- Removing the vertices of a supertriangle.
|
||||
for _ = 1, 3 do
|
||||
tableRemove(vertices)
|
||||
end
|
||||
|
||||
findTrianglesNeighbours(triangles)
|
||||
|
||||
return triangles
|
||||
end
|
||||
|
||||
---The Delaunay method divides space into tetrahedra based on a list of their vertices.
|
||||
---
|
||||
---Vertices that do not have a `is3d` group will not participate in the triangulation.
|
||||
---@param vertices table<integer, MapGen.Peak>
|
||||
function Triangulation.tetrahedralize(vertices)
|
||||
-- Filter vertices with is3d group (creates a new table)
|
||||
vertices = filterVerticesByGroup(vertices, "is3d")
|
||||
|
||||
-- Sort deterministically to ensure consistent results across sessions
|
||||
sortVerticesDeterministically(vertices)
|
||||
|
||||
local nvertices = #vertices
|
||||
|
||||
assert(nvertices > 3, "Cannot tetrahedralize, needs more than 4 vertices")
|
||||
|
||||
if nvertices == 4 then
|
||||
return {Tetrahedron:new(vertices[1], vertices[2], vertices[3], vertices[4])}
|
||||
end
|
||||
|
||||
local minPos = vertices[1]:getPeakPos()
|
||||
local minX, minY, minZ = minPos.x, minPos.y, minPos.z
|
||||
local maxX, maxY, maxZ = minX, minY, minZ
|
||||
|
||||
for i = 1, nvertices do
|
||||
local vertex = vertices[i]
|
||||
local vertexPos = vertex:getPeakPos()
|
||||
vertex.id = i
|
||||
|
||||
if vertexPos.x < minX then
|
||||
minX = vertexPos.x
|
||||
end
|
||||
|
||||
if vertexPos.y < minY then
|
||||
minY = vertexPos.y
|
||||
end
|
||||
|
||||
if vertexPos.z < minZ then
|
||||
minZ = vertexPos.z
|
||||
end
|
||||
|
||||
if vertexPos.x > maxX then
|
||||
maxX = vertexPos.x
|
||||
end
|
||||
|
||||
if vertexPos.y > maxY then
|
||||
maxY = vertexPos.y
|
||||
end
|
||||
|
||||
if vertexPos.z > maxZ then
|
||||
maxZ = vertexPos.z
|
||||
end
|
||||
end
|
||||
|
||||
-- Finding the vertices of a supertetrahedron
|
||||
local convex_mult = Triangulation.convexMultiplier
|
||||
local dx, dy, dz = (maxX - minX) * convex_mult, (maxY - minY) * convex_mult, (maxZ - minZ) * convex_mult
|
||||
local deltaMax = mathMax(dx, dy, dz)
|
||||
local midx, midy, midz = (minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5
|
||||
|
||||
local p1 = FakePeak:new(vector.new(midx - 2 * deltaMax, midy - deltaMax, midz - deltaMax))
|
||||
local p2 = FakePeak:new(vector.new(midx + 2 * deltaMax, midy - deltaMax, midz - deltaMax))
|
||||
local p3 = FakePeak:new(vector.new(midx, midy + 2 * deltaMax, midz - deltaMax))
|
||||
local p4 = FakePeak:new(vector.new(midx, midy, midz + 2 * deltaMax))
|
||||
|
||||
p1.id, p2.id, p3.id, p4.id = nvertices + 1, nvertices + 2, nvertices + 3, nvertices + 4
|
||||
vertices[p1.id], vertices[p2.id], vertices[p3.id], vertices[p4.id] = p1, p2, p3, p4
|
||||
|
||||
---@type MapGen.Tetrahedron[]
|
||||
local tetrahedrons = {Tetrahedron:new(p1, p2, p3, p4)}
|
||||
|
||||
for i = 1, nvertices do
|
||||
---@type MapGen.Triangle[]
|
||||
local faces = {}
|
||||
|
||||
-- Finding bad tetrahedrons.
|
||||
for j = #tetrahedrons, 1, -1 do
|
||||
local curTetrahedron = tetrahedrons[j]
|
||||
|
||||
if curTetrahedron:inCircumSphere(vertices[i]) then
|
||||
faces[#faces + 1] = curTetrahedron.f1
|
||||
faces[#faces + 1] = curTetrahedron.f2
|
||||
faces[#faces + 1] = curTetrahedron.f3
|
||||
faces[#faces + 1] = curTetrahedron.f4
|
||||
tableRemove(tetrahedrons, j)
|
||||
end
|
||||
end
|
||||
|
||||
-- Removing duplicate faces.
|
||||
for j = #faces - 1, 1, -1 do
|
||||
for k = #faces, j + 1, -1 do
|
||||
if faces[j] and faces[k] and faces[j]:same(faces[k]) then
|
||||
tableRemove(faces, j)
|
||||
tableRemove(faces, k - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Create new tetrahedrons.
|
||||
for j = 1, #faces do
|
||||
tetrahedrons[#tetrahedrons + 1] = Tetrahedron:new(faces[j].p1, faces[j].p2, faces[j].p3, vertices[i])
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove tetrahedra associated with the vertices of a supertetrahedron.
|
||||
for i = #tetrahedrons, 1, -1 do
|
||||
local tetrahedron = tetrahedrons[i]
|
||||
if tetrahedron.p1.id > nvertices or tetrahedron.p2.id > nvertices or tetrahedron.p3.id > nvertices or tetrahedron.p4.id > nvertices then
|
||||
tableRemove(tetrahedrons, i)
|
||||
end
|
||||
end
|
||||
|
||||
-- Removing the vertices of a supertetrahedron.
|
||||
for _ = 1, 4 do
|
||||
tableRemove(vertices)
|
||||
end
|
||||
|
||||
return tetrahedrons
|
||||
end
|
||||
|
||||
return Triangulation
|
||||
@@ -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)
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -1,4 +1,23 @@
|
||||
---@class Player
|
||||
local Player = {}
|
||||
|
||||
---@type PlayerInventoryUI
|
||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
||||
player:hud_set_hotbar_itemcount(9)
|
||||
local inv = player:get_inventory()
|
||||
inv:set_size('main', 18)
|
||||
end)
|
||||
|
||||
core.register_chatcommand('show_inv',
|
||||
{
|
||||
func = function(name, param)
|
||||
PlayerInventoryUI:showForm(name)
|
||||
return true
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
return Player
|
||||
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
|
||||
@@ -6,8 +6,7 @@ local ImmersiveCraftHandler = Mod.getInfo('smc__core__craft_system').require('Cr
|
||||
---@type WorkStationUI
|
||||
local WorkStationUI = Mod.getInfo('smc__ui__work_station').require('WorkStationUI')
|
||||
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
-- Default settings that a work station node should have.
|
||||
local WorkStationNode = Node:getExtended({
|
||||
@@ -79,6 +78,18 @@ function WorkStation:new(name, def)
|
||||
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)
|
||||
@@ -107,6 +118,7 @@ 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
|
||||
|
||||
@@ -190,6 +202,23 @@ ImmersiveCraftHandler:registerCraft('bricks', {
|
||||
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,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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
|
||||
@@ -1,6 +1,8 @@
|
||||
-- World generation occurs in a separate thread (MapGen Environment).
|
||||
-- But for the main thread, the mapgenerator object is also initialized.
|
||||
|
||||
core.set_mapgen_setting('chunksize', '{x=1,y=5,z=1}', true)
|
||||
|
||||
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
||||
|
||||
-- Main env init
|
||||
|
||||
10171
mods/ENVIRONMENT/mapGenerator/maps/tarion.json
Normal file
@@ -17,6 +17,9 @@ dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
||||
-- Math
|
||||
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
||||
|
||||
-- Profile
|
||||
dofile(core.get_modpath('smc__system__profiler')..'/init.lua')
|
||||
|
||||
-- Require
|
||||
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
||||
|
||||
|
||||
@@ -49,9 +49,396 @@ mapGenerator:registerLayer('midgard', {
|
||||
calcTemp = calcTemp,
|
||||
calcHumidity = calcHumidity,
|
||||
biomesVerticalScattering = 5,
|
||||
biomesGorizontalScattering = 5
|
||||
biomesGorizontalScattering = 5,
|
||||
triangulationLandscapeFile = 'tarion.json',
|
||||
triangulationTempFile = 'tarion.json',
|
||||
triangulationHumidityFile = 'tarion.json',
|
||||
landscapeMapScale = 100,
|
||||
tempMapScale = 100,
|
||||
humidityMapScale = 100,
|
||||
})
|
||||
|
||||
-- TODO: Config should be imported from .json file in the world's folder
|
||||
local ocean = {
|
||||
['landscape'] = {
|
||||
offset = -10,
|
||||
scale = 3,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 420,
|
||||
octaves = 2,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = -10,
|
||||
scale = 5,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 47,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = -10,
|
||||
scale = 5,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 47,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local common_lands = {
|
||||
['landscape'] = {
|
||||
offset = 0,
|
||||
scale = 5,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 88005553535,
|
||||
octaves = 2,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = -10,
|
||||
scale = 5,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 47,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = -10,
|
||||
scale = 5,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
seed = 47,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local foresty_lands = {
|
||||
['landscape'] = {
|
||||
offset = 5,
|
||||
scale = 8,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 12345,
|
||||
octaves = 3,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 20,
|
||||
scale = 10,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 48,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 60,
|
||||
scale = 15,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 49,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local hilly_lands = {
|
||||
['landscape'] = {
|
||||
offset = 15,
|
||||
scale = 12,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 54321,
|
||||
octaves = 3,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 15,
|
||||
scale = 10,
|
||||
spread = {x = 25, y = 25, z = 25},
|
||||
seed = 50,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 40,
|
||||
scale = 15,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 51,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local low_mountains = {
|
||||
['landscape'] = {
|
||||
offset = 30,
|
||||
scale = 20,
|
||||
spread = {x = 25, y = 25, z = 25},
|
||||
seed = 11111,
|
||||
octaves = 4,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 5,
|
||||
scale = 15,
|
||||
spread = {x = 30, y = 30, z = 30},
|
||||
seed = 52,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 30,
|
||||
scale = 15,
|
||||
spread = {x = 25, y = 25, z = 25},
|
||||
seed = 53,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local high_mountains = {
|
||||
['landscape'] = {
|
||||
offset = 60,
|
||||
scale = 35,
|
||||
spread = {x = 30, y = 30, z = 30},
|
||||
seed = 22222,
|
||||
octaves = 4,
|
||||
persistence = 0.55,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = -10,
|
||||
scale = 15,
|
||||
spread = {x = 35, y = 35, z = 35},
|
||||
seed = 54,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 20,
|
||||
scale = 10,
|
||||
spread = {x = 30, y = 30, z = 30},
|
||||
seed = 55,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local highest_peaks = {
|
||||
['landscape'] = {
|
||||
offset = 100,
|
||||
scale = 50,
|
||||
spread = {x = 40, y = 40, z = 40},
|
||||
seed = 33333,
|
||||
octaves = 5,
|
||||
persistence = 0.6,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = -30,
|
||||
scale = 10,
|
||||
spread = {x = 50, y = 50, z = 50},
|
||||
seed = 56,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 10,
|
||||
scale = 10,
|
||||
spread = {x = 40, y = 40, z = 40},
|
||||
seed = 57,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local rivers = {
|
||||
['landscape'] = {
|
||||
offset = -5,
|
||||
scale = 2,
|
||||
spread = {x = 5, y = 5, z = 100},
|
||||
seed = 44444,
|
||||
octaves = 2,
|
||||
persistence = 0.3,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 10,
|
||||
scale = 5,
|
||||
spread = {x = 50, y = 50, z = 50},
|
||||
seed = 58,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 80,
|
||||
scale = 10,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 59,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local lakes = {
|
||||
['landscape'] = {
|
||||
offset = -8,
|
||||
scale = 2,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 55555,
|
||||
octaves = 2,
|
||||
persistence = 0.3,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 10,
|
||||
scale = 5,
|
||||
spread = {x = 30, y = 30, z = 30},
|
||||
seed = 60,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 90,
|
||||
scale = 5,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 61,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local rocky_shores = {
|
||||
['landscape'] = {
|
||||
offset = 2,
|
||||
scale = 4,
|
||||
spread = {x = 8, y = 8, z = 8},
|
||||
seed = 66666,
|
||||
octaves = 3,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 15,
|
||||
scale = 8,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 62,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 70,
|
||||
scale = 10,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 63,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local rocky_islands = {
|
||||
['landscape'] = {
|
||||
offset = 8,
|
||||
scale = 10,
|
||||
spread = {x = 12, y = 12, z = 12},
|
||||
seed = 77777,
|
||||
octaves = 3,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 20,
|
||||
scale = 8,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 64,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 60,
|
||||
scale = 15,
|
||||
spread = {x = 20, y = 20, z = 20},
|
||||
seed = 65,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
local swamp_land = {
|
||||
['landscape'] = {
|
||||
offset = 1,
|
||||
scale = 2,
|
||||
spread = {x = 12, y = 12, z = 12},
|
||||
seed = 88888,
|
||||
octaves = 2,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['temp'] = {
|
||||
offset = 25,
|
||||
scale = 5,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 66,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
['humidity'] = {
|
||||
offset = 85,
|
||||
scale = 10,
|
||||
spread = {x = 15, y = 15, z = 15},
|
||||
seed = 67,
|
||||
octaves = 3,
|
||||
persistence = 0.4,
|
||||
lacunarity = 2,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
local v = vector.new
|
||||
|
||||
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', ocean[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#81c948', common_lands[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#187726', foresty_lands[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#357a60', hilly_lands[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#5a7269', low_mountains[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#773b18', high_mountains[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#a3a3a3', highest_peaks[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#182077', rivers[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#06f5ff', lakes[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#677a48', rocky_shores[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#e4dc36', rocky_islands[c])
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#3b7718', swamp_land[c])
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
local land1 = {
|
||||
offset = -10,
|
||||
scale = 5,
|
||||
@@ -145,7 +532,7 @@ mapGenerator:register2DPeaks('midgard',
|
||||
v(200, 0, 100),
|
||||
v(-300, 0, -200),
|
||||
})--]]
|
||||
|
||||
--[[
|
||||
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', land1)
|
||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#77ea72', land2)
|
||||
@@ -168,13 +555,9 @@ for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||
color = '#4978c6',
|
||||
pos = vector.new(-512, 0, 512)
|
||||
},
|
||||
})--]]
|
||||
})
|
||||
end
|
||||
|
||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 100,{x=0, y=0}, 'landscape')
|
||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 150,{x=0, y=0}, 'temp')
|
||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 200,{x=0, y=0}, 'humidity')
|
||||
|
||||
--]]
|
||||
-- [[
|
||||
mapGenerator:registerCavern('midgard', 'cavern1', {
|
||||
minY = -48,
|
||||
@@ -214,7 +597,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 +632,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 +652,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 +671,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 +702,7 @@ mapGenerator:registerBiome('midgard', 'swamp', {
|
||||
generateRock = generateRock,
|
||||
generateTurf = generateTurf,
|
||||
generateSoil = generateSoil,
|
||||
postProcessing = postProcessing
|
||||
})
|
||||
|
||||
return mapGenerator
|
||||
BIN
mods/ENVIRONMENT/mapGenerator/textures/maps/map.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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,5 +1,4 @@
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultLiquidDef = {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,8 +1,4 @@
|
||||
---@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 = {
|
||||
@@ -59,6 +55,8 @@ local function registerPilarStaff(rock, y)
|
||||
})
|
||||
end
|
||||
|
||||
registerPilarStaff('sylite', 0)
|
||||
registerPilarStaff('sylite_gray', 1)
|
||||
registerPilarStaff('sylite_black', 2)
|
||||
|
||||
registerRocksTypes('', 0)
|
||||
@@ -66,81 +64,3 @@ registerRocksTypes('_chipped', 1)
|
||||
registerRocksTypes('_block', 3)
|
||||
registerRocksTypes('_bricks', 4)
|
||||
registerRocksTypes('_bricks_2', 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"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
--]]
|
||||
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 151 KiB |
@@ -1,8 +1,4 @@
|
||||
---@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 = {
|
||||
@@ -12,6 +8,7 @@ local defaultSoilDef = {
|
||||
tiles = {},
|
||||
groups = {
|
||||
dig_immediate = 2,
|
||||
soil = 1,
|
||||
soil_fertiliry = 100, -- Soil fertility for agriculture
|
||||
}
|
||||
},
|
||||
@@ -245,14 +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,149 @@ local function getLogTiles(x, y)
|
||||
}
|
||||
end
|
||||
|
||||
local t = getLogTiles
|
||||
local t = logTileSheet
|
||||
|
||||
logFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "marentine_log",
|
||||
_title = "Marentine Log",
|
||||
--description = "",
|
||||
tiles = t(0, 1),
|
||||
},
|
||||
},
|
||||
---@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),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
planksFactory:registerItems({
|
||||
---@type Node.NodeDefinition
|
||||
{
|
||||
settings = {
|
||||
name = "marentine_planks",
|
||||
_title = "Marentine Planks",
|
||||
--description = "",
|
||||
tiles = { logTileSheet:t(0, 4) },
|
||||
},
|
||||
},
|
||||
---@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) },
|
||||
},
|
||||
},
|
||||
})
|
||||
---@class WoodDef
|
||||
---@field rarity Item.Rarity?
|
||||
|
||||
-- сундучки
|
||||
---@param name string
|
||||
---@param x number
|
||||
---@param def WoodDef?
|
||||
local function registerWood(name, x, def)
|
||||
if def == nil then
|
||||
def = {}
|
||||
end
|
||||
|
||||
---@type TileSheet
|
||||
local caseTileSheet = TileSheet:new("cases_sheet.png", 16, 16)
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_log',
|
||||
tiles = getLogTiles(x, 2),
|
||||
paramtype2 = 'facedir',
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
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..'_log_stripped',
|
||||
tiles = getLogTiles(x, 4),
|
||||
paramtype2 = 'facedir',
|
||||
_rarity = def.rarity
|
||||
},
|
||||
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',
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_trunk',
|
||||
tiles = {logTileSheet:t(x, 3)},
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype2 = 'facedir',
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
callbacks = {
|
||||
on_place = core.rotate_node
|
||||
}
|
||||
})
|
||||
|
||||
defaultLog:new({
|
||||
settings = {
|
||||
name = name..'_trunk_vertical',
|
||||
tiles = getLogTiles(x, 2),
|
||||
inventory_overlay = 'wood_trunk_overlay.png',
|
||||
drop = 'wood:'..name..'_log',
|
||||
paramtype2 = 'facedir',
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
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'},
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
})
|
||||
|
||||
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'},
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
})
|
||||
|
||||
defaultPlanks:new({
|
||||
settings = {
|
||||
name = name..'_planks',
|
||||
tiles = { logTileSheet:t(x, 6) },
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
})
|
||||
|
||||
defaultLeafs:new({
|
||||
settings = {
|
||||
name = name..'_leafs',
|
||||
tiles = { logTileSheet:t(x, 1) },
|
||||
_rarity = def.rarity,
|
||||
},
|
||||
})
|
||||
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, {rarity = 'uncommon'})
|
||||
registerWood('dallalia', 5)
|
||||
registerWood('zuph', 6, {rarity = 'uncommon'})
|
||||
|
||||
133
mods/GAME/ITEMS/wood/locale/wood.ru.tr
Normal file
@@ -0,0 +1,133 @@
|
||||
# textdomain: wood
|
||||
marentine_log-title=Бревно марентина
|
||||
marentine_log-desc=Темная древесина, отдающая синевой.@n Часто встречается вблизи крупных водоёмов.
|
||||
marentine_log_stripped-title=Обтёсанное бревно марентина
|
||||
marentine_log_stripped-desc=Освобождённое от тёмно-синей коры@n более светлая древесная сердцевина.
|
||||
marentine_timber-title=
|
||||
marentine_timber-desc=
|
||||
marentine_trunk-title=
|
||||
marentine_trunk-desc=
|
||||
marentine_trunk_vertical-title=
|
||||
marentine_trunk_vertical-desc=
|
||||
marentine_trunk_branch-title=
|
||||
marentine_trunk_branch-desc=
|
||||
marentine_trunk_branch_vertical-title=
|
||||
marentine_trunk_branch_vertical-desc=
|
||||
marentine_planks-title=Марентиновые доски
|
||||
marentine_planks-desc=Темные плотно скрепленные между собой@n доски из марентиновой древесины.
|
||||
marentine_leafs-title=
|
||||
marentine_leafs-desc=
|
||||
|
||||
allwhere_log-title=Бревно всемира
|
||||
allwhere_log-desc=Распростроенный древесный материал,@n встречающийся почти во всех местах Тариона.@n Эта древесина не обладает особыми свойствами,@n но за счёт своей распространённости широко@n применяется во многих базовых изделиях.
|
||||
allwhere_log_stripped-title=Обтёсанное бревно всемира.
|
||||
allwhere_log_stripped-desc=Светлая мягкая сердцевина,@n лишённая своей коры.
|
||||
allwhere_timber-title=
|
||||
allwhere_timber-desc=
|
||||
allwhere_trunk-title=
|
||||
allwhere_trunk-desc=
|
||||
allwhere_trunk_vertical-title=
|
||||
allwhere_trunk_vertical-desc=
|
||||
allwhere_trunk_branch-title=
|
||||
allwhere_trunk_branch-desc=
|
||||
allwhere_trunk_branch_vertical-title=
|
||||
allwhere_trunk_branch_vertical-desc=
|
||||
allwhere_planks-title=Всемировые доски
|
||||
allwhere_planks-desc=Светлые доски, плотно@n состыкованные между собой.
|
||||
allwhere_leafs-title=
|
||||
allwhere_leafs-desc=
|
||||
|
||||
fis_log-title=Бревно фиса
|
||||
fis_log-desc=Необычное бревно с кроваво-красной@n сердцевиной и коры цвета белой кости.
|
||||
fis_log_stripped-title=Обтёсанное бревно фиса
|
||||
fis_log_stripped-desc=Кроваво-красная сердцевина,@n лишенная оболочки из светлой коры.
|
||||
fis_timber-title=
|
||||
fis_timber-desc=
|
||||
fis_trunk-title=
|
||||
fis_trunk-desc=
|
||||
fis_trunk_vertical-title=
|
||||
fis_trunk_vertical-desc=
|
||||
fis_trunk_branch-title=
|
||||
fis_trunk_branch-desc=
|
||||
fis_trunk_branch_vertical-title=
|
||||
fis_trunk_branch_vertical-desc=
|
||||
fis_planks-title=Фисовые доски
|
||||
fis_planks-desc=Красные подогнанные друг к другу и@n доски из фисовой древесины.
|
||||
fis_leafs-title=
|
||||
fis_leafs-desc=
|
||||
|
||||
tammoy_log-title=Бревно таммоя
|
||||
tammoy_log-desc=Светлая хвойная древесина, покрытая@n легкоотдираемой чешуйчатой корой.
|
||||
tammoy_log_stripped-title=Обтёсанное бревно таммоя
|
||||
tammoy_log_stripped-desc=Светлая хвойная древесина,@n сочащаяся смолой взамен удалённой коры.
|
||||
tammoy_timber-title=
|
||||
tammoy_timber-desc=
|
||||
tammoy_trunk-title=
|
||||
tammoy_trunk-desc=
|
||||
tammoy_trunk_vertical-title=
|
||||
tammoy_trunk_vertical-desc=
|
||||
tammoy_trunk_branch-title=
|
||||
tammoy_trunk_branch-desc=
|
||||
tammoy_trunk_branch_vertical-title=
|
||||
tammoy_trunk_branch_vertical-desc=
|
||||
tammoy_planks-title=Таммоевые доски
|
||||
tammoy_planks-desc=Смолянистые плотно прилегающие друг к другу светлые доски.
|
||||
tammoy_leafs-title=
|
||||
tammoy_leafs-desc=
|
||||
|
||||
gi_log-title=Бревно ги
|
||||
gi_log-desc=Благодорно-тёмная хвойная древесина,@n относящаяся к высококачественным древесным породам.@n Эта древесина особенно славится своими прочностными@n свойствами и фактурой волокон.
|
||||
gi_log_stripped-title=Обтёсанное бревно ги
|
||||
gi_log_stripped-desc=Плотная хвойная сердцевина, являющаяся идеальным@n материалом для изготовления различных предметов.@n В руках умелого мастера фактура этого дерева@n приобретает особенно красивый узор.
|
||||
gi_timber-title=
|
||||
gi_timber-desc=
|
||||
gi_trunk-title=
|
||||
gi_trunk-desc=
|
||||
gi_trunk_vertical-title=
|
||||
gi_trunk_vertical-desc=
|
||||
gi_trunk_branch-title=
|
||||
gi_trunk_branch-desc=
|
||||
gi_trunk_branch_vertical-title=
|
||||
gi_trunk_branch_vertical-desc=
|
||||
gi_planks-title=Гиевые доски
|
||||
gi_planks-desc=Прочные хорошо сложенные@n доски из благодорного дерева ги.
|
||||
gi_leafs-title=
|
||||
gi_leafs-desc=
|
||||
|
||||
dallalia_log-title=Бревно даллалии
|
||||
dallalia_log-desc=Сладко-жёлтоватая древесина, покрытая пепельно-серой корой.@n Плотность и прочность этого вида дерева@n позволяет дереву устремляться в небо на несколько десятков метров.
|
||||
dallalia_log_stripped-title=Обтёсанное бревно даллалии
|
||||
dallalia_log_stripped-desc=Освобожденная от своей бледной коры жёлтовая древесина,@n сочащаяся сладким соком.
|
||||
dallalia_timber-title=
|
||||
dallalia_timber-desc=
|
||||
dallalia_trunk-title=
|
||||
dallalia_trunk-desc=
|
||||
dallalia_trunk_vertical-title=
|
||||
dallalia_trunk_vertical-desc=
|
||||
dallalia_trunk_branch-title=
|
||||
dallalia_trunk_branch-desc=
|
||||
dallalia_trunk_branch_vertical-title=
|
||||
dallalia_trunk_branch_vertical-desc=
|
||||
dallalia_planks-title=Даллалиевые доски
|
||||
dallalia_planks-desc=Жёлтые плотно сложенные доски,@n покрытие застывшим соком дерева.
|
||||
dallalia_leafs-title=
|
||||
dallalia_leafs-desc=
|
||||
|
||||
zuph_log-title=Бревно зуфа
|
||||
zuph_log-desc=Светлая древесина с корой из мелких волокон.@n Из-за толстой плотной оболочки плохо поддается рубке.
|
||||
zuph_log_stripped-title=Обтёсанное бревно зуфа
|
||||
zuph_log_stripped-desc=Жёлтая древесина,@n лишённая трудноразрубаемой коры.
|
||||
zuph_timber-title=
|
||||
zuph_timber-desc=
|
||||
zuph_trunk-title=
|
||||
zuph_trunk-desc=
|
||||
zuph_trunk_vertical-title=
|
||||
zuph_trunk_vertical-desc=
|
||||
zuph_trunk_branch-title=
|
||||
zuph_trunk_branch-desc=
|
||||
zuph_trunk_branch_vertical-title=
|
||||
zuph_trunk_branch_vertical-desc=
|
||||
zuph_planks-title=Зуфовые доски
|
||||
zuph_planks-desc=Хорошо скрепленные между собой жёлтые древестные изделия.
|
||||
zuph_leafs-title=
|
||||
zuph_leafs-desc=
|
||||
|
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 |
132
mods/GAME/adminCommands/init.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
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)
|
||||
|
||||
-- Keys indicating the languages for which localization presence is checked.
|
||||
local LANG_CODES = {'en', 'ru'}
|
||||
|
||||
-- Number of missed localizations.
|
||||
local missedLocaleCount = 0
|
||||
|
||||
local function checkLocale(strTranslate, langCodes)
|
||||
local str = core.strip_escapes(strTranslate)
|
||||
|
||||
for _, langCode in ipairs(langCodes or LANG_CODES) do
|
||||
if core.strip_escapes(core.get_translated_string(langCode, strTranslate)) == str then
|
||||
missedLocaleCount = missedLocaleCount + 1
|
||||
Logger.warningLog('Localization missing[%s][%s]. String: `%s`.', missedLocaleCount, langCode, str)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
core.register_chatcommand('get_missing_locale', {
|
||||
privs = {server = true},
|
||||
description = '{short_mod_name:string?, lang_codes:string[]?}',
|
||||
func = function(name, paramsStr)
|
||||
local params = core.deserialize('return '..paramsStr or '{}')
|
||||
|
||||
if params == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local shortModName = params.short_mod_name
|
||||
local langCodes = params.lang_codes
|
||||
|
||||
if shortModName ~= nil and type(shortModName) ~= 'string' then
|
||||
return false
|
||||
end
|
||||
|
||||
if langCodes ~= nil and type(langCodes) ~= 'table' then
|
||||
return false
|
||||
end
|
||||
|
||||
local items
|
||||
if shortModName == '' or shortModName == nil then
|
||||
items = Smc.getRegisteredItems()
|
||||
else
|
||||
items = Smc.getRegisteredItemsByMod(shortModName)
|
||||
end
|
||||
|
||||
if items == nil then
|
||||
return false, 'There are no items registered for this mod (or the entire game)'
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param item Item
|
||||
for name, item in pairs(items) do
|
||||
local itemSettings = item.itemDef.settings
|
||||
local title, desc = itemSettings._title, itemSettings._description
|
||||
|
||||
checkLocale(title, langCodes)
|
||||
checkLocale(desc, langCodes)
|
||||
end
|
||||
|
||||
return true, ''
|
||||
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
|
||||
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
@@ -8,3 +8,5 @@ require('Lib.color')
|
||||
require('Lib.immersiveCraftData')
|
||||
require('Lib.getObjectByGUID')
|
||||
require('Lib.receiveFields')
|
||||
require('Lib.registeredItems')
|
||||
require('Lib.requires')
|
||||
@@ -3,10 +3,11 @@ local EMPTY_FLAG = 'EMPTY_FLAG'
|
||||
---@class ImmersiveStageData
|
||||
|
||||
---@class ImmersiveCraftData
|
||||
---@field craftName string
|
||||
---@field stageName string
|
||||
---@field amount integer
|
||||
---@field stageData ImmersiveStageData?
|
||||
---@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
|
||||
|
||||
33
mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
---@type table<string, Item>
|
||||
local registeredItems = {}
|
||||
|
||||
---@type table<string, table<string, Item>>
|
||||
local registeredItemsByMod = {}
|
||||
|
||||
---@param shortModName string
|
||||
---@param item Item
|
||||
function Smc.addRegisteredItem(shortModName, item)
|
||||
local itemName = item.itemDef.settings.name
|
||||
local modItems = registeredItemsByMod[shortModName]
|
||||
|
||||
if modItems == nil then
|
||||
registeredItemsByMod[shortModName] = {[itemName]=item}
|
||||
return
|
||||
end
|
||||
|
||||
assert(modItems[itemName] == nil)
|
||||
|
||||
registeredItems[itemName] = item
|
||||
modItems[itemName] = item
|
||||
end
|
||||
|
||||
---@param shortModName string
|
||||
---@return table<string, Item>?
|
||||
function Smc.getRegisteredItemsByMod(shortModName)
|
||||
return table.copy_with_metatables(registeredItemsByMod[shortModName])
|
||||
end
|
||||
|
||||
---@return table<string, Item>?
|
||||
function Smc.getRegisteredItems()
|
||||
return table.copy_with_metatables(registeredItems)
|
||||
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
|
||||
|
||||
55
mods/SYSTEM/Profiler/init.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
local getInstance = Class.getInstance
|
||||
local getUsTime = core.get_us_time
|
||||
|
||||
---@alias Profiler.TimeUnits 'sec'|'us'
|
||||
|
||||
---@class Profiler
|
||||
---@field name string
|
||||
---@field startTime number
|
||||
---@field endTime number
|
||||
---@field deltaTime number
|
||||
Profiler = {
|
||||
timers = {}
|
||||
}
|
||||
|
||||
---@param name string?
|
||||
---@return Profiler
|
||||
function Profiler:new(name)
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name or 'NoName'
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
---Marks the time when the timer starts.
|
||||
function Profiler:startTimer()
|
||||
self.startTime = getUsTime()
|
||||
self.deltaTime = nil
|
||||
self.endTime = nil
|
||||
end
|
||||
|
||||
---Marks the end time of the timer.
|
||||
function Profiler:endTimer()
|
||||
self.endTime = getUsTime()
|
||||
|
||||
self.deltaTime = self.endTime - self.startTime
|
||||
end
|
||||
|
||||
---Returns the time difference between the start and stop of the timer in seconds (`sec`) or microseconds (`us`).
|
||||
---@param units Profiler.TimeUnits? Units of time measurement. Default 'us'.
|
||||
function Profiler:getDeltaTime(units)
|
||||
if units == nil then
|
||||
units = 'us'
|
||||
end
|
||||
|
||||
if units == 'us' then
|
||||
return self.deltaTime
|
||||
elseif units == 'sec' then
|
||||
return self.deltaTime/1000000
|
||||
end
|
||||
end
|
||||
|
||||
---Displays the time difference in the chat using `core.log`.
|
||||
function Profiler:logDeltaTime()
|
||||
core.log(('DeltaTime[%s]: %.3f'):format(self:getDeltaTime()))
|
||||
end
|
||||
2
mods/SYSTEM/Profiler/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__system__profiler
|
||||
depends = smc__system__class, smc__system__table
|
||||
@@ -1,3 +1,3 @@
|
||||
name = smc__system__system_loader
|
||||
description = Include this mod in your `depends` to ensure all necessary Libs are loaded for your mod
|
||||
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib
|
||||
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib, smc__system__profiler
|
||||
|
||||
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/PlayerInventoryUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__ui__player_inventory')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('PlayerInventoryUI')
|
||||
2
mods/UI/PlayerInventoryUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = smc__ui__player_inventory
|
||||
depends = smc__core__formspec
|
||||
137
mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
||||
|
||||
---@alias PlayerInventoryUI.PaneType 'left'|'right'
|
||||
---@alias PlayerInventoryUI.getPaneFunc fun(self:PlayerInventoryUI,playerName:string,paneType:PlayerInventoryUI.PaneType):Formspec
|
||||
|
||||
---@alias PlayerInventoryUI.PaneName 'select_pane_menu'|'bag_pane'|'craft_pane'|'equip_pane'|'ref_pane'
|
||||
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getSelectPaneMenu = require('PlayerInventoryUI.getSelectPaneMenu')
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getBagPane = require('PlayerInventoryUI.getBagPane')
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getCraftPane = require('PlayerInventoryUI.getCraftPane')
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getEquipPane = require('PlayerInventoryUI.getEquipPane')
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getRefPane = require('PlayerInventoryUI.getRefPane')
|
||||
|
||||
---@type table<PlayerInventoryUI.PaneName, PlayerInventoryUI.getPaneFunc>
|
||||
local panes = {
|
||||
['select_pane_menu'] = getSelectPaneMenu,
|
||||
['bag_pane'] = getBagPane,
|
||||
['craft_pane'] = getCraftPane,
|
||||
['equip_pane'] = getEquipPane,
|
||||
['ref_pane'] = getRefPane,
|
||||
}
|
||||
|
||||
---@param paneName PlayerInventoryUI.PaneName
|
||||
local function getPane(paneName)
|
||||
if paneName == nil then
|
||||
---@type PlayerInventoryUI.PaneName
|
||||
paneName = 'select_pane_menu'
|
||||
end
|
||||
|
||||
local pane = panes[paneName]
|
||||
assert(pane ~= nil, ('The pane with the `%s` does not exist.'):format(paneName))
|
||||
|
||||
return pane
|
||||
end
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@return string
|
||||
local function getFormSpecString(self, playerName)
|
||||
---@type PlayerInventoryUI.PaneName
|
||||
local leftPaneName = self:getContex(playerName, 'left_pane_name') or 'select_pane_menu'
|
||||
---@type PlayerInventoryUI.PaneName
|
||||
local rightPaneName = self:getContex(playerName, 'right_pane_name') or 'select_pane_menu'
|
||||
|
||||
local leftPaneIsBlock = self:getContex(playerName, 'left_pane_is_block')
|
||||
local rightPaneIsBlock = self:getContex(playerName, 'right_pane_is_block')
|
||||
|
||||
local InventoryForm = Formspec:new({
|
||||
size = {x=22, y=12},
|
||||
position = {x=0.5, y=0.5},
|
||||
noPrepend = true,
|
||||
})
|
||||
|
||||
|
||||
InventoryForm:
|
||||
--bgcolor('#00000000'):
|
||||
listColors('#00000000', '#C4C4C433'):
|
||||
list('current_player', 'main', 5.5,9.5, 9,2):
|
||||
background(0, 9, 22, 3.5, 'player_inventory_middle_background.png', false):
|
||||
container(panes[leftPaneName](self, playerName, 'left'), 0, 0):
|
||||
container(panes[rightPaneName](self, playerName, 'right'), 11, 0):
|
||||
button(10.5, 0, .5, .5, 'close_left_pane', 'x'):
|
||||
button(21.5, 0, .5, .5, 'close_right_pane', 'x')
|
||||
|
||||
return InventoryForm:toString()
|
||||
end
|
||||
|
||||
---@alias PlayerInventoryUI.ContexKey 'left_pane_name'|'right_pane_name'|'left_pane_is_block'|'right_pane_is_block'
|
||||
|
||||
---@class PlayerInventoryUI : BaseUI
|
||||
---@field getFormSpecString fun(self:PlayerInventoryUI,playerName:string):string
|
||||
---@field showForm fun(self:PlayerInventoryUI,playerName:string):string
|
||||
---@field getContex fun(self:PlayerInventoryUI,player:string|Player,key:PlayerInventoryUI.ContexKey):any
|
||||
local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false)
|
||||
|
||||
--[[
|
||||
---Shows the player their inventory.
|
||||
---@param playerName string
|
||||
function PlayerInventoryUI:showForm(playerName)
|
||||
local player = core.get_player_by_name(playerName)
|
||||
assert(player ~= nil)
|
||||
|
||||
player:set_inventory_formspec(self:getFormSpecString(playerName))
|
||||
core.show_formspec(playerName, '', '')
|
||||
end
|
||||
|
||||
---Closes the player's inventory.
|
||||
---@param playerName string
|
||||
function PlayerInventoryUI:closeForm(playerName)
|
||||
core.close_formspec(playerName, '')
|
||||
end--]]
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldAction('close_left_pane', function(player, fieldName, fieldValue)
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'left_pane_name', 'select_pane_menu')
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('select_left_%S+', function(player, fieldName, fieldValue)
|
||||
local paneName = string.match(fieldName, 'select_%S+_(%S+_%S+)')
|
||||
assert(paneName ~= nil)
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'left_pane_name', paneName)
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldAction('close_right_pane', function(player, fieldName, fieldValue)
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'right_pane_name', 'select_pane_menu')
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('select_right_%S+', function(player, fieldName, fieldValue)
|
||||
local paneName = string.match(fieldName, 'select_%S+_(%S+_%S+)')
|
||||
assert(paneName ~= nil)
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'right_pane_name', paneName)
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
return PlayerInventoryUI
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local BagPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getBagPane(self, playerName, paneType)
|
||||
BagPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#BF59EE:120'):
|
||||
label(2,2, 'BAG PANE')
|
||||
|
||||
return BagPane
|
||||
end
|
||||
|
||||
return getBagPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local CraftPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getCraftPane(self, playerName, paneType)
|
||||
CraftPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#E7CC35:120'):
|
||||
label(2,2, 'CRAFTING PANE')
|
||||
|
||||
return CraftPane
|
||||
end
|
||||
|
||||
return getCraftPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local EquipPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getEquipPane(self, playerName, paneType)
|
||||
EquipPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#72FAC6:120'):
|
||||
label(2,2, 'EQUIPMENT PANE')
|
||||
|
||||
return EquipPane
|
||||
end
|
||||
|
||||
return getEquipPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local RefPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getRefPane(self, playerName, paneType)
|
||||
RefPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#8072FA:120'):
|
||||
label(2,2, 'REFERENCE PANE')
|
||||
|
||||
return RefPane
|
||||
end
|
||||
|
||||
return getRefPane
|
||||
@@ -0,0 +1,21 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local selectPaneMenu = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getSelectPaneMenu(self, playerName, paneType)
|
||||
|
||||
selectPaneMenu:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#FA8072:120'):
|
||||
button(3.5,2.5,2,2,'select_'..paneType..'_bag_pane', 'bag'):
|
||||
button(5.5,2.5,2,2,'select_'..paneType..'_craft_pane', 'craft'):
|
||||
button(3.5,4.5,2,2,'select_'..paneType..'_equip_pane', 'equip'):
|
||||
button(5.5,4.5,2,2,'select_'..paneType..'_ref_pane', 'ref')
|
||||
|
||||
return selectPaneMenu
|
||||
end
|
||||
|
||||
return getSelectPaneMenu
|
||||
|
After Width: | Height: | Size: 266 KiB |
|
After Width: | Height: | Size: 199 B |
|
After Width: | Height: | Size: 77 KiB |
@@ -1,11 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type Formspec
|
||||
local Formspec = require('Formspec')
|
||||
|
||||
---@type BaseUI
|
||||
local BaseUI = Mod.getInfo('smc__core__base_ui').require('BaseUI')
|
||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
---@param self BaseUI
|
||||
---@param playerName string
|
||||
|
||||