mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Update Type module (#1569)
* Update VolumeObject.cpp
fixed Volume:GetActive() method
* Update CHANGELOG.md
* function description LevelFuncs.OnUseItem
* Revert "function description LevelFuncs.OnUseItem"
This reverts commit 2478afca68
.
* Update Type.lua
This commit is contained in:
parent
909f631c2f
commit
7d18d7506f
1 changed files with 137 additions and 131 deletions
|
@ -26,180 +26,186 @@
|
|||
-- end
|
||||
-- @luautil Type
|
||||
|
||||
local color = TEN.Color(0,0,0)
|
||||
local rotation = TEN.Rotation(0, 0, 0)
|
||||
local time = TEN.Time()
|
||||
local vec2 = TEN.Vec2(0,0)
|
||||
local vec3 = TEN.Vec3(0,0,0)
|
||||
LevelFuncs.TypeControlLevelFunc = function () end
|
||||
|
||||
local Type = {}
|
||||
|
||||
|
||||
--- Check if the variable is a number.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a number, false if it isn't a number
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- local num = 255
|
||||
-- if Type.IsNumber(num) then
|
||||
-- num = num + 1
|
||||
-- end
|
||||
--- Check if the variable is a number.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a number, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- local num = 255
|
||||
-- if Type.IsNumber(num) then
|
||||
-- num = num + 1
|
||||
-- end
|
||||
Type.IsNumber = function (variable)
|
||||
return type(variable) == "number"
|
||||
end
|
||||
|
||||
--- Check if the variable is a string.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a string, false if it isn't a string
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- local str = "Hi"
|
||||
-- if Type.IsString(str) then
|
||||
-- TEN.Util.PrintLog(str .. "everyone!", Util.LogLevel.INFO)
|
||||
-- end
|
||||
--- Check if the variable is a string.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a string, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- local str = "Hi"
|
||||
-- if Type.IsString(str) then
|
||||
-- TEN.Util.PrintLog(str .. "everyone!", Util.LogLevel.INFO)
|
||||
-- end
|
||||
Type.IsString = function (variable)
|
||||
return type(variable) == "string"
|
||||
end
|
||||
|
||||
|
||||
--- Check if the variable is a boolean.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a boolean, false if it isn't a boolean
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.test = function (test)
|
||||
-- if Type.IsBoolean(test) then
|
||||
-- LevelVars.test = test
|
||||
-- else
|
||||
-- TEN.Util.PrintLog("Error!", Util.LogLevel.ERROR)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a boolean.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a boolean, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.test = function (test)
|
||||
-- if Type.IsBoolean(test) then
|
||||
-- LevelVars.test = test
|
||||
-- else
|
||||
-- TEN.Util.PrintLog("Error!", Util.LogLevel.ERROR)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsBoolean = function (variable)
|
||||
return type(variable) == "boolean"
|
||||
end
|
||||
|
||||
--- Check if the variable is a table.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a table, false if it isn't a table
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.PairsTable = function (table)
|
||||
-- if Type.IsTable(table) then
|
||||
-- for k, v in pairs(table) do
|
||||
-- TEN.Util.PrintLog(tostring(k) .. " - " .. tostring(v), Util.LogLevel.INFO)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a table.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a table, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.PairsTable = function (table)
|
||||
-- if Type.IsTable(table) then
|
||||
-- for k, v in pairs(table) do
|
||||
-- TEN.Util.PrintLog(tostring(k) .. " - " .. tostring(v), Util.LogLevel.INFO)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
Type.IsTable = function (variable)
|
||||
return type(variable) == "table"
|
||||
end
|
||||
|
||||
--- Check if the variable has a null value.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a null, false if it isn't a null
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.AddProp = function (prop)
|
||||
-- if Type.IsNull(prop) then
|
||||
-- TEN.Util.PrintLog("Error!", Util.LogLevel.ERROR)
|
||||
-- else
|
||||
-- LevelVars.property = prop
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable has a null value.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a null, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.AddProp = function (prop)
|
||||
-- if Type.IsNull(prop) then
|
||||
-- TEN.Util.PrintLog("Error!", Util.LogLevel.ERROR)
|
||||
-- else
|
||||
-- LevelVars.property = prop
|
||||
-- end
|
||||
-- end
|
||||
Type.IsNull = function (variable)
|
||||
return type(variable) == "nil"
|
||||
end
|
||||
|
||||
--- Check if the variable is a function.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a function, false if it isn't a function
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.RunFunc = function (func)
|
||||
-- if Type.IsFunction(func) then
|
||||
-- func()
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a function.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a function, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.RunFunc = function (func)
|
||||
-- if Type.IsFunction(func) then
|
||||
-- func()
|
||||
-- end
|
||||
-- end
|
||||
Type.IsFunction = function (variable)
|
||||
return type(variable) == "function"
|
||||
end
|
||||
|
||||
--- Check if the variable is a @{Color}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a color, false if it isn't a color
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetColor = function(color)
|
||||
-- if Type.IsColor(color) then
|
||||
-- string:SetColor(color)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a @{Color}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a Color, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetColor = function(color)
|
||||
-- if Type.IsColor(color) then
|
||||
-- string:SetColor(color)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsColor = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "ScriptColor"
|
||||
return getmetatable(variable) == getmetatable(color)
|
||||
end
|
||||
|
||||
--- Check if the variable is a @{Rotation}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a rotation, false if it isn't a rotation
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetRotation = function (rot)
|
||||
-- if Type.IsRotation(rot) then
|
||||
-- Lara:SetRotation(rot)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a @{Rotation}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a Rotation, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetRotation = function (rot)
|
||||
-- if Type.IsRotation(rot) then
|
||||
-- Lara:SetRotation(rot)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsRotation = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "Rotation"
|
||||
return getmetatable(variable) == getmetatable(rotation)
|
||||
end
|
||||
|
||||
--- Check if the variable is a @{Vec2}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a vec2, false if it isn't a vec2
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetSpritePos = function (pos)
|
||||
-- if Type.IsVec2(pos) then
|
||||
-- sprite:SetPosition(pos)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a @{Vec2}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a Vec2, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetSpritePos = function (pos)
|
||||
-- if Type.IsVec2(pos) then
|
||||
-- sprite:SetPosition(pos)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsVec2 = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "Vec2"
|
||||
return getmetatable(variable) == getmetatable(vec2)
|
||||
end
|
||||
|
||||
--- Check if the variable is a @{Vec3}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a vec3, false if it isn't a vec3
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetLaraPos = function (pos)
|
||||
-- if Type.IsVec3(pos) then
|
||||
-- Lara:SetPosition(pos)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a @{Vec3}.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a Vec3, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetLaraPos = function (pos)
|
||||
-- if Type.IsVec3(pos) then
|
||||
-- Lara:SetPosition(pos)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsVec3 = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "Vec3"
|
||||
return getmetatable(variable) == getmetatable(vec3)
|
||||
end
|
||||
|
||||
--- Check if the variable is a @{Time} object.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a Time object, false if it isn't a Time object
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.IncreaseTime = function (time)
|
||||
-- if Type.IsTime(time) then
|
||||
-- time + 1
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a @{Time} object.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a Time object, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.IncreaseTime = function (time)
|
||||
-- if Type.IsTime(time) then
|
||||
-- time + 1
|
||||
-- end
|
||||
-- end
|
||||
Type.IsTime = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "TEN::Scripting::Time"
|
||||
return getmetatable(variable) == getmetatable(time)
|
||||
end
|
||||
|
||||
--- Check if the variable is a LevelFunc.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean true if the variable is a LevelFunc, false if it isn't a IsLevelFunc
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetCallback = function (func)
|
||||
-- if Type.IsFunction(func) then
|
||||
-- TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRELOOP, func)
|
||||
-- end
|
||||
-- end
|
||||
--- Check if the variable is a LevelFunc.
|
||||
-- @tparam variable variable to be check
|
||||
-- @treturn boolean *true* if the variable is a LevelFunc, *false* otherwise
|
||||
-- @usage
|
||||
-- --example of use
|
||||
-- LevelFuncs.SetCallback = function (func)
|
||||
-- if Type.IsFunction(func) then
|
||||
-- TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRELOOP, func)
|
||||
-- end
|
||||
-- end
|
||||
Type.IsLevelFunc = function (variable)
|
||||
return variable ~= nil and type(variable) == "userdata" and variable.__type.name == "LevelFunc"
|
||||
return getmetatable(variable) == getmetatable(LevelFuncs.TypeControlLevelFunc)
|
||||
end
|
||||
|
||||
return Type
|
Loading…
Add table
Add a link
Reference in a new issue