mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Added some runtime checks to role
This commit is contained in:
@@ -95,6 +95,24 @@ function Common.validate_argument_multi_type(value, test_types, param_name, para
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Will raise an error if called during runtime
|
||||||
|
-- @usage error_if_runtime()
|
||||||
|
function Common.error_if_runtime()
|
||||||
|
if _LIFECYCLE == 8 then
|
||||||
|
local function_name = debug.getinfo(2,'n').name or '<anon>'
|
||||||
|
error(function_name..' can not be called during runtime',3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Will raise an error if the function is a closure
|
||||||
|
-- @usage error_if_runetime_closure(func)
|
||||||
|
function Common.error_if_runetime_closure(func)
|
||||||
|
if _LIFECYCLE == 8 and Debug.is_closure(func) then
|
||||||
|
local function_name = debug.getinfo(2,'n').name or '<anon>'
|
||||||
|
error(function_name..' can not be called during runtime with a closure',3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Value Returns.
|
--- Value Returns.
|
||||||
-- @section valueReturns
|
-- @section valueReturns
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ local Roles = {
|
|||||||
roles={}, -- Contains the raw info for the roles, indexed by role name
|
roles={}, -- Contains the raw info for the roles, indexed by role name
|
||||||
flags={}, -- Contains functions that run when a flag is added/removed from a player
|
flags={}, -- Contains functions that run when a flag is added/removed from a player
|
||||||
internal={}, -- Contains all internally accessed roles, such as root, default
|
internal={}, -- Contains all internally accessed roles, such as root, default
|
||||||
players={}
|
players={} -- Contains the roles that players have
|
||||||
},
|
},
|
||||||
events = {
|
events = {
|
||||||
on_role_assigned=script.generate_event_name(),
|
on_role_assigned=script.generate_event_name(),
|
||||||
@@ -425,6 +425,7 @@ end
|
|||||||
-- @tparam table order table a which is keyed only by numbers (start 1) and values are roles in order with highest first
|
-- @tparam table order table a which is keyed only by numbers (start 1) and values are roles in order with highest first
|
||||||
function Roles.define_role_order(order)
|
function Roles.define_role_order(order)
|
||||||
-- Clears and then rebuilds the order table
|
-- Clears and then rebuilds the order table
|
||||||
|
_C.error_if_runtime()
|
||||||
Roles.config.order = {}
|
Roles.config.order = {}
|
||||||
local done = {}
|
local done = {}
|
||||||
for _,role in ipairs(order) do
|
for _,role in ipairs(order) do
|
||||||
@@ -462,6 +463,7 @@ end
|
|||||||
-- flag param - player - the player that has had they roles changed
|
-- flag param - player - the player that has had they roles changed
|
||||||
-- flag param - state - the state of the flag, aka if the flag is present
|
-- flag param - state - the state of the flag, aka if the flag is present
|
||||||
function Roles.define_flag_trigger(name,callback)
|
function Roles.define_flag_trigger(name,callback)
|
||||||
|
_C.error_if_runtime()
|
||||||
Roles.config.flags[name] = Async.register(callback)
|
Roles.config.flags[name] = Async.register(callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -487,6 +489,7 @@ end
|
|||||||
-- @tparam[opt=name] string short_hand the shortened version of the name
|
-- @tparam[opt=name] string short_hand the shortened version of the name
|
||||||
-- @treturn Roles._prototype the start of the config chain for this role
|
-- @treturn Roles._prototype the start of the config chain for this role
|
||||||
function Roles.new_role(name,short_hand)
|
function Roles.new_role(name,short_hand)
|
||||||
|
_C.error_if_runtime()
|
||||||
if Roles.config.roles[name] then return error('Role name is non unique') end
|
if Roles.config.roles[name] then return error('Role name is non unique') end
|
||||||
local role = setmetatable({
|
local role = setmetatable({
|
||||||
name=name,
|
name=name,
|
||||||
@@ -602,6 +605,7 @@ end
|
|||||||
-- @tparam[opt=false] boolean use_factorio_api when true the custom permission group module is ignored
|
-- @tparam[opt=false] boolean use_factorio_api when true the custom permission group module is ignored
|
||||||
-- @treturn Roles._prototype allows chaining
|
-- @treturn Roles._prototype allows chaining
|
||||||
function Roles._prototype:set_permission_group(name,use_factorio_api)
|
function Roles._prototype:set_permission_group(name,use_factorio_api)
|
||||||
|
_C.error_if_runtime()
|
||||||
if use_factorio_api then
|
if use_factorio_api then
|
||||||
self.permission_group = {true,name}
|
self.permission_group = {true,name}
|
||||||
else
|
else
|
||||||
@@ -617,6 +621,7 @@ end
|
|||||||
-- @tparam string role the name of the role that will be the parent; has imminent effect if role is already defined
|
-- @tparam string role the name of the role that will be the parent; has imminent effect if role is already defined
|
||||||
-- @treturn Roles._prototype allows chaining
|
-- @treturn Roles._prototype allows chaining
|
||||||
function Roles._prototype:set_parent(role)
|
function Roles._prototype:set_parent(role)
|
||||||
|
_C.error_if_runtime()
|
||||||
self.parent = role
|
self.parent = role
|
||||||
role = Roles.get_role_from_any(role)
|
role = Roles.get_role_from_any(role)
|
||||||
if not role then return self end
|
if not role then return self end
|
||||||
@@ -629,6 +634,7 @@ end
|
|||||||
-- @tparam function callback receives only one param which is player to promote, return true to promote the player
|
-- @tparam function callback receives only one param which is player to promote, return true to promote the player
|
||||||
-- @treturn Roles._prototype allows chaining
|
-- @treturn Roles._prototype allows chaining
|
||||||
function Roles._prototype:set_auto_promote_condition(callback)
|
function Roles._prototype:set_auto_promote_condition(callback)
|
||||||
|
_C.error_if_runetime_closure(callback)
|
||||||
self.auto_promote_condition = callback
|
self.auto_promote_condition = callback
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user