-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add utility function for adding info for new entities
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local getDefaultFaction = ::Const.EntityType.getDefaultFaction; | ||
::Const.EntityType.getDefaultFaction = function( _id ) | ||
{ | ||
local ret = getDefaultFaction(_id); | ||
if (ret == ::Const.FactionType.Generic && (_id in ::MSU.Entities.EntityTypeToDefaultFactionMap)) | ||
{ | ||
return ::MSU.Entities.EntityTypeToDefaultFactionMap[_id]; | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
::MSU.Entities <- { | ||
EntityTypeToDefaultFactionMap = {}, | ||
HighestIDDiff = -99, | ||
HighestID = -99, | ||
|
||
// Utility function that puts all the required info of an entity in all the right places | ||
function addEntity( _info ) | ||
{ | ||
// _info is a table that must contain the following keys: | ||
// EntityType, EntityIcon, DefaultFaction, EntityName, EntityNamePlural, TroopDef, ActorDef | ||
|
||
// If the Diff is now greater than before, that means some other mod added something to the ::Const.EntityType | ||
// table, so we should update our HighestID again. | ||
if (this.HighestID == -99 || ::Const.EntityType.len() - this.HighestID > this.HighestIDDiff) | ||
{ | ||
foreach (key, value in ::Const.EntityType) | ||
{ | ||
if (typeof value == "integer" && value > this.HighestID) | ||
this.HighestID = value; | ||
} | ||
this.HighestIDDiff = ::Const.EntityType.len() - this.HighestID; | ||
} | ||
|
||
this.EntityTypeToDefaultFactionMap[_info.EntityType] <- _info.DefaultFaction; | ||
::Const.EntityType[_info.EntityType] <- ++this.HighestID; | ||
::Const.EntityIcon.push(_info.EntityIcon); | ||
::Const.Strings.EntityName.push(_info.EntityName); | ||
::Const.Strings.EntityNamePlural.push(_info.EntityNamePlural); | ||
::Const.World.Spawn.Troops[_info.EntityType] <- _info.TroopDef; | ||
::Const.Tactical.Actor[_info.EntityType] <- _info.ActorDef; | ||
} | ||
} |