mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-19 14:53:56 -07:00
Simplify trigger event naming scheme.
Reduces confusion and string manipulation. Refs #52. Differential Revision: https://code.wildfiregames.com/D3913 This was SVN commit r25373.
This commit is contained in:
parent
79118e6716
commit
c0157d613d
5 changed files with 47 additions and 52 deletions
|
|
@ -285,7 +285,7 @@ Foundation.prototype.Commit = function()
|
|||
cmpObstruction.SetDisableBlockMovementPathfinding(false, false, -1);
|
||||
|
||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
cmpTrigger.CallEvent("ConstructionStarted", {
|
||||
cmpTrigger.CallEvent("OnConstructionStarted", {
|
||||
"foundation": this.entity,
|
||||
"template": this.finalTemplateName
|
||||
});
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ ProductionQueue.prototype.AddItem = function(templateName, type, count, metadata
|
|||
});
|
||||
|
||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
cmpTrigger.CallEvent("TrainingQueued", {
|
||||
cmpTrigger.CallEvent("OnTrainingQueued", {
|
||||
"playerid": player,
|
||||
"unitTemplate": templateName,
|
||||
"count": count,
|
||||
|
|
@ -476,7 +476,7 @@ ProductionQueue.prototype.AddItem = function(templateName, type, count, metadata
|
|||
});
|
||||
|
||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
cmpTrigger.CallEvent("ResearchQueued", {
|
||||
cmpTrigger.CallEvent("OnResearchQueued", {
|
||||
"playerid": player,
|
||||
"technologyTemplate": templateName,
|
||||
"researcherEntity": this.entity
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ Treasure.prototype.Reward = function(entity)
|
|||
cmpStatisticsTracker.IncreaseTreasuresCollectedCounter();
|
||||
|
||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
cmpTrigger.CallEvent("TreasureCollected", {
|
||||
cmpTrigger.CallEvent("OnTreasureCollected", {
|
||||
"player": cmpPlayer.GetPlayerID(),
|
||||
"treasure": this.entity
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,25 +8,25 @@ Trigger.prototype.Schema =
|
|||
*/
|
||||
Trigger.prototype.eventNames =
|
||||
[
|
||||
"CinemaPathEnded",
|
||||
"CinemaQueueEnded",
|
||||
"ConstructionStarted",
|
||||
"DiplomacyChanged",
|
||||
"Deserialized",
|
||||
"InitGame",
|
||||
"Interval",
|
||||
"EntityRenamed",
|
||||
"OwnershipChanged",
|
||||
"PlayerCommand",
|
||||
"PlayerDefeated",
|
||||
"PlayerWon",
|
||||
"Range",
|
||||
"ResearchFinished",
|
||||
"ResearchQueued",
|
||||
"StructureBuilt",
|
||||
"TrainingFinished",
|
||||
"TrainingQueued",
|
||||
"TreasureCollected"
|
||||
"OnCinemaPathEnded",
|
||||
"OnCinemaQueueEnded",
|
||||
"OnConstructionStarted",
|
||||
"OnDiplomacyChanged",
|
||||
"OnDeserialized",
|
||||
"OnInitGame",
|
||||
"OnInterval",
|
||||
"OnEntityRenamed",
|
||||
"OnOwnershipChanged",
|
||||
"OnPlayerCommand",
|
||||
"OnPlayerDefeated",
|
||||
"OnPlayerWon",
|
||||
"OnRange",
|
||||
"OnResearchFinished",
|
||||
"OnResearchQueued",
|
||||
"OnStructureBuilt",
|
||||
"OnTrainingFinished",
|
||||
"OnTrainingQueued",
|
||||
"OnTreasureCollected"
|
||||
];
|
||||
|
||||
Trigger.prototype.Init = function()
|
||||
|
|
@ -38,7 +38,7 @@ Trigger.prototype.Init = function()
|
|||
|
||||
// Each event has its own set of actions determined by the map maker.
|
||||
for (let eventName of this.eventNames)
|
||||
this["On" + eventName + "Actions"] = {};
|
||||
this[eventName] = {};
|
||||
};
|
||||
|
||||
Trigger.prototype.RegisterTriggerPoint = function(ref, ent)
|
||||
|
|
@ -89,13 +89,12 @@ Trigger.prototype.GetTriggerPoints = function(ref)
|
|||
*/
|
||||
Trigger.prototype.RegisterTrigger = function(event, action, data)
|
||||
{
|
||||
let eventString = event + "Actions";
|
||||
if (!this[eventString])
|
||||
if (!this[event])
|
||||
{
|
||||
warn("Trigger.js: Invalid trigger event \"" + event + "\".");
|
||||
return;
|
||||
}
|
||||
if (this[eventString][action])
|
||||
if (this[event][action])
|
||||
{
|
||||
warn("Trigger.js: Trigger \"" + action + "\" has been registered before. Aborting...");
|
||||
return;
|
||||
|
|
@ -105,7 +104,7 @@ Trigger.prototype.RegisterTrigger = function(event, action, data)
|
|||
// F.e. getting the wrong timer tag
|
||||
data = clone(data) || { "enabled": false };
|
||||
|
||||
this[eventString][action] = data;
|
||||
this[event][action] = data;
|
||||
|
||||
// setup range query
|
||||
if (event == "OnRange")
|
||||
|
|
@ -134,13 +133,12 @@ Trigger.prototype.RegisterTrigger = function(event, action, data)
|
|||
|
||||
Trigger.prototype.DisableTrigger = function(event, action)
|
||||
{
|
||||
let eventString = event + "Actions";
|
||||
if (!this[eventString][action])
|
||||
if (!this[event][action])
|
||||
{
|
||||
warn("Trigger.js: Disabling unknown trigger");
|
||||
return;
|
||||
}
|
||||
let data = this[eventString][action];
|
||||
let data = this[event][action];
|
||||
// special casing interval and range triggers for performance
|
||||
if (event == "OnInterval")
|
||||
{
|
||||
|
|
@ -167,13 +165,12 @@ Trigger.prototype.DisableTrigger = function(event, action)
|
|||
|
||||
Trigger.prototype.EnableTrigger = function(event, action)
|
||||
{
|
||||
let eventString = event + "Actions";
|
||||
if (!this[eventString][action])
|
||||
if (!this[event][action])
|
||||
{
|
||||
warn("Trigger.js: Enabling unknown trigger");
|
||||
return;
|
||||
}
|
||||
let data = this[eventString][action];
|
||||
let data = this[event][action];
|
||||
// special casing interval and range triggers for performance
|
||||
if (event == "OnInterval")
|
||||
{
|
||||
|
|
@ -213,32 +210,30 @@ Trigger.prototype.EnableTrigger = function(event, action)
|
|||
*/
|
||||
Trigger.prototype.CallEvent = function(event, data)
|
||||
{
|
||||
let eventString = "On" + event + "Actions";
|
||||
|
||||
if (!this[eventString])
|
||||
if (!this[event])
|
||||
{
|
||||
warn("Trigger.js: Unknown trigger event called:\"" + event + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
for (let action in this[eventString])
|
||||
if (this[eventString][action].enabled)
|
||||
for (let action in this[event])
|
||||
if (this[event][action].enabled)
|
||||
this.DoAction({ "action": action, "data": data });
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalInitGame = function(msg)
|
||||
{
|
||||
this.CallEvent("InitGame", {});
|
||||
this.CallEvent("OnInitGame", {});
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalConstructionFinished = function(msg)
|
||||
{
|
||||
this.CallEvent("StructureBuilt", { "building": msg.newentity, "foundation": msg.entity });
|
||||
this.CallEvent("OnStructureBuilt", { "building": msg.newentity, "foundation": msg.entity });
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalTrainingFinished = function(msg)
|
||||
{
|
||||
this.CallEvent("TrainingFinished", msg);
|
||||
this.CallEvent("OnTrainingFinished", msg);
|
||||
// The data for this one is {"entities": createdEnts,
|
||||
// "owner": cmpOwnership.GetOwner(),
|
||||
// "metadata": metadata}
|
||||
|
|
@ -247,49 +242,49 @@ Trigger.prototype.OnGlobalTrainingFinished = function(msg)
|
|||
|
||||
Trigger.prototype.OnGlobalResearchFinished = function(msg)
|
||||
{
|
||||
this.CallEvent("ResearchFinished", msg);
|
||||
this.CallEvent("OnResearchFinished", msg);
|
||||
// The data for this one is { "player": playerID, "tech": tech }
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalCinemaPathEnded = function(msg)
|
||||
{
|
||||
this.CallEvent("CinemaPathEnded", msg);
|
||||
this.CallEvent("OnCinemaPathEnded", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalCinemaQueueEnded = function(msg)
|
||||
{
|
||||
this.CallEvent("CinemaQueueEnded", msg);
|
||||
this.CallEvent("OnCinemaQueueEnded", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalDeserialized = function(msg)
|
||||
{
|
||||
this.CallEvent("Deserialized", msg);
|
||||
this.CallEvent("OnDeserialized", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalEntityRenamed = function(msg)
|
||||
{
|
||||
this.CallEvent("EntityRenamed", msg);
|
||||
this.CallEvent("OnEntityRenamed", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalOwnershipChanged = function(msg)
|
||||
{
|
||||
this.CallEvent("OwnershipChanged", msg);
|
||||
this.CallEvent("OnOwnershipChanged", msg);
|
||||
// data is {"entity": ent, "from": playerId, "to": playerId}
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalPlayerDefeated = function(msg)
|
||||
{
|
||||
this.CallEvent("PlayerDefeated", msg);
|
||||
this.CallEvent("OnPlayerDefeated", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalPlayerWon = function(msg)
|
||||
{
|
||||
this.CallEvent("PlayerWon", msg);
|
||||
this.CallEvent("OnPlayerWon", msg);
|
||||
};
|
||||
|
||||
Trigger.prototype.OnGlobalDiplomacyChanged = function(msg)
|
||||
{
|
||||
this.CallEvent("DiplomacyChanged", msg);
|
||||
this.CallEvent("OnDiplomacyChanged", msg);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ function ProcessCommand(player, cmd)
|
|||
if (g_Commands[cmd.type])
|
||||
{
|
||||
var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
cmpTrigger.CallEvent("PlayerCommand", { "player": player, "cmd": cmd });
|
||||
cmpTrigger.CallEvent("OnPlayerCommand", { "player": player, "cmd": cmd });
|
||||
g_Commands[cmd.type](player, cmd, data);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue