mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Changed events to use common format
This commit is contained in:
@@ -92,13 +92,13 @@ Event.add(defines.events.on_player_created,function(event)
|
||||
end)
|
||||
|
||||
--- When a player gets a new role they will have the toolbar updated
|
||||
Event.add(Roles.player_role_assigned,function(event)
|
||||
Event.add(Roles.events.on_role_assigned,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
Toolbar.update(player)
|
||||
end)
|
||||
|
||||
--- When a player loses a role they will have the toolbar updated
|
||||
Event.add(Roles.player_role_unassigned,function(event)
|
||||
Event.add(Roles.events.on_role_unassigned,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
Toolbar.update(player)
|
||||
end)
|
||||
|
||||
@@ -163,6 +163,7 @@ local Colours = require 'resources.color_presets'
|
||||
local write_json = ext_require('expcore.common','write_json')
|
||||
|
||||
local Roles = {
|
||||
_prototype={},
|
||||
config={
|
||||
order={}, -- Contains the order of the roles, lower index is better
|
||||
roles={}, -- Contains the raw info for the roles, indexed by role name
|
||||
@@ -170,9 +171,10 @@ local Roles = {
|
||||
internal={}, -- Contains all internally accessed roles, such as root, default
|
||||
players={}
|
||||
},
|
||||
player_role_assigned=script.generate_event_name(),
|
||||
player_role_unassigned=script.generate_event_name(),
|
||||
_prototype={}
|
||||
events = {
|
||||
on_role_assigned=script.generate_event_name(),
|
||||
on_role_unassigned=script.generate_event_name(),
|
||||
}
|
||||
}
|
||||
|
||||
--- When global is loaded it will have the metatable re-assigned to the roles
|
||||
@@ -195,9 +197,9 @@ local function emit_player_roles_updated(player,type,roles,by_player_name,skip_g
|
||||
local by_player = Game.get_player_from_any(by_player_name)
|
||||
local by_player_index = by_player and by_player.index or 0
|
||||
-- get the event id from the type of emit
|
||||
local event = Roles.player_role_assigned
|
||||
local event = Roles.events.on_role_assigned
|
||||
if type == 'unassign' then
|
||||
event = Roles.player_role_unassigned
|
||||
event = Roles.events.on_role_unassigned
|
||||
end
|
||||
-- convert the roles to objects and get the names of the roles
|
||||
local role_names = {}
|
||||
@@ -775,8 +777,8 @@ local function role_update(event)
|
||||
end
|
||||
|
||||
--- When a player joined or has a role change then the update is triggered
|
||||
Event.add(Roles.player_role_assigned,role_update)
|
||||
Event.add(Roles.player_role_unassigned,role_update)
|
||||
Event.add(Roles.events.on_role_assigned,role_update)
|
||||
Event.add(Roles.events.on_role_unassigned,role_update)
|
||||
Event.add(defines.events.on_player_joined_game,role_update)
|
||||
-- Every 60 seconds the auto promote check is preformed
|
||||
Event.on_nth_tick(3600,function()
|
||||
|
||||
@@ -79,8 +79,11 @@ local Store = {
|
||||
registered={},
|
||||
synced={},
|
||||
callbacks={},
|
||||
on_value_update=script.generate_event_name()
|
||||
events = {
|
||||
on_value_update=script.generate_event_name()
|
||||
}
|
||||
}
|
||||
|
||||
Global.register(Store.data,function(tbl)
|
||||
Store.data = tbl
|
||||
end)
|
||||
@@ -184,7 +187,7 @@ function Store.set(location,child,value,from_sync)
|
||||
data[location] = value
|
||||
end
|
||||
|
||||
script.raise_event(Store.on_value_update,{
|
||||
script.raise_event(Store.events.on_value_update,{
|
||||
tick=game.tick,
|
||||
location=location,
|
||||
child=child,
|
||||
@@ -215,7 +218,7 @@ function Store.clear(location,child,from_sync)
|
||||
data[location] = nil
|
||||
end
|
||||
|
||||
script.raise_event(Store.on_value_update,{
|
||||
script.raise_event(Store.events.on_value_update,{
|
||||
tick=game.tick,
|
||||
location=location,
|
||||
child=child,
|
||||
@@ -235,7 +238,7 @@ function Store.get_children(location)
|
||||
end
|
||||
|
||||
-- Handels syncing
|
||||
Event.add(Store.on_value_update,function(event)
|
||||
Event.add(Store.events.on_value_update,function(event)
|
||||
if Store.callbacks[event.location] then
|
||||
Store.callbacks[event.location](event.value,event.child)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user