Changes in class constructors. close #18
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@class Formspec
|
---@class Formspec
|
||||||
---@field params string
|
---@field params string
|
||||||
---@field elements string
|
---@field elements string
|
||||||
@@ -45,7 +47,7 @@ local Formspec = {
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:new(def)
|
function Formspec:new(def)
|
||||||
if def == nil then
|
if def == nil then
|
||||||
local instance = setmetatable({}, {__index = self})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -98,9 +100,9 @@ function Formspec:new(def)
|
|||||||
local allowClose = ('allow_close[%s]'):format(def.allowClose or true)
|
local allowClose = ('allow_close[%s]'):format(def.allowClose or true)
|
||||||
|
|
||||||
---@type Formspec
|
---@type Formspec
|
||||||
local instance = setmetatable({
|
local instance = getInstance(self, {
|
||||||
params = version..size..position..anchor..padding..noPrepend..realCoordinates..allowClose,
|
params = version..size..position..anchor..padding..noPrepend..realCoordinates..allowClose,
|
||||||
}, {__index = self})
|
})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__item')
|
local modInfo = Mod.getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ function Item:new(itemDef)
|
|||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = setmetatable({}, {__index = self})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||||
local visual = itemDef.settings.visual
|
local visual = itemDef.settings.visual
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@class ItemFactory
|
---@class ItemFactory
|
||||||
---@field defaultDef Item.ItemDefinition|Node.NodeDefinition
|
---@field defaultDef Item.ItemDefinition|Node.NodeDefinition
|
||||||
---@field itemClass Item|Node
|
---@field itemClass Item|Node
|
||||||
@@ -8,10 +10,10 @@ local ItemFactory = {}
|
|||||||
---@return ItemFactory
|
---@return ItemFactory
|
||||||
function ItemFactory:new(itemClass, defaultDef)
|
function ItemFactory:new(itemClass, defaultDef)
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
local instance = setmetatable({
|
local instance =getInstance(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
itemClass = itemClass,
|
itemClass = itemClass,
|
||||||
}, {__index = self})
|
})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local mathRound = math.round
|
local mathRound = math.round
|
||||||
|
|
||||||
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@class TileSheet
|
---@class TileSheet
|
||||||
---@field image string Name of texture
|
---@field image string Name of texture
|
||||||
---@field width number Number of tiles in the table horizontally
|
---@field width number Number of tiles in the table horizontally
|
||||||
@@ -70,11 +72,11 @@ function TileSheet:new(image, tileWidth, tileHeight)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@type TileSheet
|
---@type TileSheet
|
||||||
local instance = setmetatable({
|
local instance = getInstance(self, {
|
||||||
image = image,
|
image = image,
|
||||||
width = mathRound(width / tileWidth),
|
width = mathRound(width / tileWidth),
|
||||||
height = mathRound(height / tileHeight),
|
height = mathRound(height / tileHeight),
|
||||||
}, {__index = self})
|
})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user