forked from Apancore.Studio/simple-makes-complex
Remove GlobalSpace, domains and extends methods in Mod
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
Api = {}
|
||||
|
||||
--[[
|
||||
---@alias Domain table<string,Mod|SubDomain> Global table for accessing public classes provided by mods.
|
||||
---@alias SubDomain table<string,Mod>
|
||||
|
||||
@@ -46,7 +46,7 @@ Api.addModToGlobalSpace = function(mod, location, force)
|
||||
-- TODO: баг: ликвидные имена не определяются шаблоном
|
||||
--[[if not location:match('^[%a_][%w_]*([%.][%a_][%w_]*)*$') then
|
||||
error('bad argument #2 to \'Api.addModToGlobalSpace\' (invalid format)')
|
||||
end--]]
|
||||
end --] ]
|
||||
|
||||
-- Split `location` into fields -- TODO: !!!Make a String function!!!
|
||||
local fields = {}
|
||||
@@ -88,4 +88,4 @@ Api.addModToGlobalSpace = function(mod, location, force)
|
||||
error(string.format('field \'%s\' already exists in \'%s\'', last_field, location))
|
||||
end
|
||||
current[last_field] = mod
|
||||
end
|
||||
end --]]
|
||||
@@ -28,6 +28,7 @@ function Mod.getInfo(modname)
|
||||
return {name = name, shortName = shortName, path = path, require = require}
|
||||
end
|
||||
|
||||
--[[
|
||||
function Mod:new()
|
||||
---@type Mod
|
||||
local instance = setmetatable(Mod.getInfo(), { __index = self })
|
||||
@@ -61,6 +62,6 @@ function Mod:getModClassExtended(ChildClass)
|
||||
local childClass = Mod:getClassExtended(self.Class, ChildClass or {})
|
||||
|
||||
return childClass
|
||||
end
|
||||
end --]]
|
||||
|
||||
return Mod
|
||||
@@ -1,5 +1,5 @@
|
||||
local Enum = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__enum')
|
||||
local require = modInfo.require
|
||||
|
||||
Enum.Class = Enum.require('Enum')
|
||||
return require('Enum')
|
||||
|
||||
Api.addModToGlobalSpace(Enum, 'Core.Enum')
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
---@class Enum
|
||||
local Enum = {}
|
||||
|
||||
---@param enum table[]
|
||||
---@param enum string[]
|
||||
---@return Enum
|
||||
function Enum:new(enum)
|
||||
local metaEnum = {}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local Item = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__item')
|
||||
local require = modInfo.require
|
||||
|
||||
Item.Class = Item.require('Item')
|
||||
|
||||
Api.addModToGlobalSpace(Item, 'Core.Item')
|
||||
return require('Item')
|
||||
@@ -1,8 +1,10 @@
|
||||
local modInfo = Mod.getInfo()
|
||||
local modInfo = Mod.getInfo('smc__core__item')
|
||||
local require = modInfo.require
|
||||
|
||||
local VisualEnum = require('Item.VisualEnum')
|
||||
|
||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
|
||||
---@class Item
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef table
|
||||
@@ -61,7 +63,7 @@ local defMerge = function(...)
|
||||
return table.merge(...)
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition
|
||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||
---@return Item
|
||||
function Item:new(itemDef)
|
||||
---Adding default parameters
|
||||
@@ -103,7 +105,7 @@ end
|
||||
---@return Item
|
||||
function Item:getExtended(defaultDef)
|
||||
---@type Item
|
||||
local ChildClass = Mod:getClassExtended(self, {
|
||||
local ChildClass = Class.extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
@@ -119,7 +121,7 @@ function Item:getFactory(defaultDef)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
local instance = Core.ItemFactory():new(self, defaultDef)
|
||||
local instance = ItemFactory:new(self, defaultDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
---@type Enum
|
||||
local Enum = Mod.getInfo('smc__core__enum').require('Enum')
|
||||
|
||||
---@class Item.VisualEnum : Enum
|
||||
---@field ITEM_2D Enum.EnumKey
|
||||
---@field ITEM_3D Enum.EnumKey
|
||||
local VisualEnum = Core.Enum:getModClassInstance({
|
||||
local VisualEnum = Enum:new({
|
||||
'ITEM_2D',
|
||||
'ITEM_3D',
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local ItemFactory = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__item_factory')
|
||||
local require = modInfo.require
|
||||
|
||||
ItemFactory.Class = ItemFactory.require('ItemFactory')
|
||||
|
||||
Api.addModToGlobalSpace(ItemFactory, 'Core.ItemFactory')
|
||||
return require('ItemFactory')
|
||||
@@ -1,5 +1,4 @@
|
||||
local MapGen = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
MapGen.Class = MapGen.require('MapGen')
|
||||
|
||||
Api.addModToGlobalSpace(MapGen, 'Core.MapGen')
|
||||
return require('MapGen')
|
||||
@@ -664,8 +664,6 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||
-- local param2_data = voxelManip:get_param2_data()
|
||||
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
||||
|
||||
data[area:index(0,50,0)] = core.get_content_id('rocks:malachite')
|
||||
|
||||
local index
|
||||
-- Initial generation: landscape
|
||||
for z = minPos.z, maxPos.z do
|
||||
|
||||
@@ -10,7 +10,7 @@ local Peak = require('MapGen.Peak')
|
||||
---@class MapGen.Triangulation.FakePeak : MapGen.Peak
|
||||
---@field id number
|
||||
---@field getPeakPos fun():vector
|
||||
local FakePeak = Mod:getClassExtended(Peak, {})
|
||||
local FakePeak = Class.extend(Peak, {})
|
||||
|
||||
---Returns a fake `MapGen.Peak` that has no noise parameters.
|
||||
---Note that the initialized peak should not be used in generation.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local Node = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__node')
|
||||
local require = modInfo.require
|
||||
|
||||
Node.Class = Node.require('Node')
|
||||
|
||||
Api.addModToGlobalSpace(Node, 'Core.Node')
|
||||
return require('Node')
|
||||
@@ -1,9 +1,17 @@
|
||||
local itemRequire = Mod.getInfo('smc__core__item').require
|
||||
|
||||
---@type Item
|
||||
local Item = itemRequire('Item')
|
||||
|
||||
---@type Item.VisualEnum
|
||||
local VisualEnum = Core.Item.require('Item.VisualEnum')
|
||||
local VisualEnum = itemRequire('Item.VisualEnum')
|
||||
|
||||
---@type ItemFactory
|
||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||
|
||||
---@class Node : Item
|
||||
---@field defaultDef Node.NodeDefinition
|
||||
local Node = Core.Item:getModClassExtended({})
|
||||
local Node = Class.extend(Item, {})
|
||||
|
||||
---@param nodeDef Node.NodeDefinition
|
||||
---@return Node
|
||||
@@ -11,7 +19,7 @@ function Node:new(nodeDef)
|
||||
nodeDef.settings.visual = VisualEnum.ITEM_3D
|
||||
|
||||
---@type Node
|
||||
local instance = Core.Item:getModClassInstance(nodeDef)
|
||||
local instance = Item:new(nodeDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
@@ -23,7 +31,7 @@ end
|
||||
---@return Node
|
||||
function Node:getExtended(defaultDef)
|
||||
---@type Node
|
||||
local ChildClass = Mod:getClassExtended(self, {
|
||||
local ChildClass = Class.extend(self, {
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
@@ -39,7 +47,7 @@ function Node:getFactory(defaultDef)
|
||||
end
|
||||
|
||||
---@type ItemFactory
|
||||
local instance = Core.ItemFactory:getModClassInstance(self, defaultDef)
|
||||
local instance = ItemFactory:new(self, defaultDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---@type Item.Callbacks
|
||||
local ItemCallbacks = Core.Item.require('Item.Callbacks')
|
||||
local ItemCallbacks = Mod.getInfo('smc__core__item').require('Item.Callbacks')
|
||||
|
||||
---@class Node.Callbacks : Item.Callbacks
|
||||
local Callbacks = Mod:getClassExtended(ItemCallbacks, {})
|
||||
local Callbacks = Class.extend(ItemCallbacks, {})
|
||||
|
||||
---Node constructor; called after adding node.
|
||||
---Can set up metadata and stuff like that.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---@type Item.Settings
|
||||
local ItemSettings = Core.Item.require('Item.Settings')
|
||||
local ItemSettings = Mod.getInfo('smc__core__item').require('Item.Settings')
|
||||
|
||||
---@class Node.Settings : Item.Settings
|
||||
local Settings = Mod:getClassExtended(ItemSettings, {})
|
||||
local Settings = Class.extend(ItemSettings, {})
|
||||
|
||||
---See "Node drawtypes"
|
||||
---@type string?
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local TileSheet = Mod:new()
|
||||
local modInfo = Mod.getInfo('smc__core__tilesheet')
|
||||
local require = modInfo.require
|
||||
|
||||
TileSheet.Class = TileSheet.require('TileSheet')
|
||||
|
||||
Api.addModToGlobalSpace(TileSheet, 'Core.TileSheet')
|
||||
return require('TileSheet')
|
||||
@@ -1,3 +1,6 @@
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultLiquidDef = {
|
||||
settings = {
|
||||
@@ -19,7 +22,7 @@ local defaultLiquidDef = {
|
||||
}
|
||||
|
||||
---@type Node
|
||||
local defaultLiquid = Core.Node.Class:getExtended(defaultLiquidDef)
|
||||
local defaultLiquid = Node:getExtended(defaultLiquidDef)
|
||||
|
||||
local liquidFactory = defaultLiquid:getFactory()
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultRockDef = {
|
||||
settings = {
|
||||
@@ -11,12 +17,12 @@ local defaultRockDef = {
|
||||
}
|
||||
|
||||
---@type Node
|
||||
local defaultRock = Core.Node.Class:getExtended(defaultRockDef)
|
||||
local defaultRock = Node:getExtended(defaultRockDef)
|
||||
|
||||
local rockFactory = defaultRock:getFactory()
|
||||
|
||||
---@type TileSheet
|
||||
local ts = Core.TileSheet:getModClassInstance("rocks_sheet.png", 16, 16)
|
||||
local ts = TileSheet:new("rocks_sheet.png", 16, 16)
|
||||
|
||||
rockFactory:registerNodesByShortDef({
|
||||
{"sylite", "Sylite", nil, {ts:t(0, 0)}},
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
---@type TileSheet
|
||||
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||
|
||||
---@type Node
|
||||
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||
|
||||
---@type Node.NodeDefinition
|
||||
local defaultSoilDef = {
|
||||
settings = {
|
||||
@@ -12,12 +18,12 @@ local defaultSoilDef = {
|
||||
}
|
||||
|
||||
---@type Node
|
||||
local defaultSoil = Core.Node.Class:getExtended(defaultSoilDef)
|
||||
local defaultSoil = Node:getExtended(defaultSoilDef)
|
||||
|
||||
local soilFactory = defaultSoil:getFactory()
|
||||
|
||||
---@type TileSheet
|
||||
local ts = Core.TileSheet:getModClassInstance("soils_sheet.png", 16, 16)
|
||||
local ts = TileSheet:new("soils_sheet.png", 16, 16)
|
||||
|
||||
local clayTiles = {
|
||||
ts:t(0,0)
|
||||
|
||||
Reference in New Issue
Block a user