Class: add getInstance(). MapGen: fixes :new() methods. #18
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
local mathAbs, mathRound, mathMin, mathMax, id
|
||||
= math.abs, math.round, math.min, math.max, core.get_content_id
|
||||
|
||||
local getInstance = Class.getInstance
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
@@ -34,14 +36,14 @@ local Cavern = require('MapGen.Cavern')
|
||||
local ff2luat = require('MapGen.ff2luat')
|
||||
|
||||
---@class MapGen
|
||||
---@field layersByName table<string, MapGen.Layer>
|
||||
---@field layersList MapGen.Layer[]
|
||||
---@field staticsByName table<string, MapGen.StaticLayer>
|
||||
---@field staticsList MapGen.StaticLayer[]
|
||||
---@field isLayersNoisesInitialized boolean Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
|
||||
---@field isCavernsNoiseInitialized boolean Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
|
||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||
---@field nodeIDs table<string, number>
|
||||
---@field layersByName table<string, MapGen.Layer>
|
||||
---@field layersList MapGen.Layer[]
|
||||
---@field staticsByName table<string, MapGen.StaticLayer>
|
||||
---@field staticsList MapGen.StaticLayer[]
|
||||
---@field isLayersNoisesInitialized boolean Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
|
||||
---@field isCavernsNoiseInitialized boolean Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
|
||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||
---@field nodeIDs table<string, number>
|
||||
local MapGen = {
|
||||
layersByName = {},
|
||||
layersList = {},
|
||||
@@ -56,7 +58,7 @@ local MapGen = {
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGenDef
|
||||
---@field nodes table<string, string>
|
||||
---@field nodes table<string, string>
|
||||
|
||||
---@param def MapGenDef
|
||||
---@return MapGen
|
||||
@@ -68,10 +70,10 @@ function MapGen:new(def)
|
||||
end
|
||||
|
||||
---@type MapGen
|
||||
local instance = setmetatable({
|
||||
nodes = def.nodes,
|
||||
nodeIDs = nodesIDs,
|
||||
}, {__index = self})
|
||||
local instance = getInstance(self, {
|
||||
nodes = def.nodes,
|
||||
nodeIDs = nodesIDs,
|
||||
})
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user