Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | "<optional>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<element name='UnitSeparationWidthMultiplier' a:help='Place the units in the formation closer or further to each other. The standard separation is the footprint size.'>" + | "<element name='UnitSeparationWidthMultiplier' a:help='Place the units in the formation closer or further to each other. The standard separation is the footprint size.'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='UnitSeparationDepthMultiplier' a:help='Place the units in the formation closer or further to each other. The standard separation is the footprint size.'>" + | "<element name='UnitSeparationDepthMultiplier' a:help='Place the units in the formation closer or further to each other. The standard separation is the footprint size.'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Animations' a:help='Give a list of animations to use for the particular formation members, based on their positions'>" + | "<element name='Animations' a:help='Give a list of animation variants to use for the particular formation members, based on their positions'>" + | ||||
"<zeroOrMore>" + | |||||
"<element a:help='The name of the default animation (walk, idle, attack_ranged...) that will be transformed in the formation-specific ResetMoveAnimation'>" + | |||||
"<anyName/>" + | |||||
"<text a:help='example text: \"1..1,1..-1:animation1;2..2,1..-1;animation2\", this will set animation1 for the first row, and animation2 for the second row. The first part of the numbers (1..1 and 2..2) means the row range. Every row between (and including) those values will switch animations. The second part of the numbers (1..-1) denote the columns inside those rows that will be affected. Note that in both cases, you can use -1 for the last row/column, -2 for the second to last, etc.'/>" + | "<text a:help='example text: \"1..1,1..-1:animation1;2..2,1..-1;animation2\", this will set animation1 for the first row, and animation2 for the second row. The first part of the numbers (1..1 and 2..2) means the row range. Every row between (and including) those values will switch animations. The second part of the numbers (1..-1) denote the columns inside those rows that will be affected. Note that in both cases, you can use -1 for the last row/column, -2 for the second to last, etc.'/>" + | ||||
"</element>" + | |||||
"</zeroOrMore>" + | |||||
"</element>"; | "</element>"; | ||||
var g_ColumnDistanceThreshold = 128; // distance at which we'll switch between column/box formations | var g_ColumnDistanceThreshold = 128; // distance at which we'll switch between column/box formations | ||||
Formation.prototype.Init = function() | Formation.prototype.Init = function() | ||||
{ | { | ||||
this.formationShape = this.template.FormationShape; | this.formationShape = this.template.FormationShape; | ||||
this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | ||||
this.sortingOrder = this.template.SortingOrder; | this.sortingOrder = this.template.SortingOrder; | ||||
this.shiftRows = this.template.ShiftRows == "true"; | this.shiftRows = this.template.ShiftRows == "true"; | ||||
this.separationMultiplier = { | this.separationMultiplier = { | ||||
"width": +this.template.UnitSeparationWidthMultiplier, | "width": +this.template.UnitSeparationWidthMultiplier, | ||||
"depth": +this.template.UnitSeparationDepthMultiplier | "depth": +this.template.UnitSeparationDepthMultiplier | ||||
}; | }; | ||||
this.sloppyness = +this.template.Sloppyness; | this.sloppyness = +this.template.Sloppyness; | ||||
this.widthDepthRatio = +this.template.WidthDepthRatio; | this.widthDepthRatio = +this.template.WidthDepthRatio; | ||||
this.minColumns = +(this.template.MinColumns || 0); | this.minColumns = +(this.template.MinColumns || 0); | ||||
this.maxColumns = +(this.template.MaxColumns || 0); | this.maxColumns = +(this.template.MaxColumns || 0); | ||||
this.maxRows = +(this.template.MaxRows || 0); | this.maxRows = +(this.template.MaxRows || 0); | ||||
this.centerGap = +(this.template.CenterGap || 0); | this.centerGap = +(this.template.CenterGap || 0); | ||||
var animations = this.template.Animations; | this.animations = []; | ||||
this.animations = {}; | if (this.template.Animations) | ||||
for (var animationName in animations) | |||||
{ | { | ||||
var differentAnimations = animations[animationName].split(/\s*;\s*/); | let differentAnimations = this.template.Animations.split(/\s*;\s*/); | ||||
this.animations[animationName] = []; | |||||
// loop over the different rectangulars that will map to different animations | // loop over the different rectangulars that will map to different animations | ||||
for (var rectAnimation of differentAnimations) | for (var rectAnimation of differentAnimations) | ||||
{ | { | ||||
var rect, replacementAnimationName; | var rect, replacementAnimationName; | ||||
[rect, replacementAnimationName] = rectAnimation.split(/\s*:\s*/); | [rect, replacementAnimationName] = rectAnimation.split(/\s*:\s*/); | ||||
var rows, columns; | var rows, columns; | ||||
[rows, columns] = rect.split(/\s*,\s*/); | [rows, columns] = rect.split(/\s*,\s*/); | ||||
var minRow, maxRow, minColumn, maxColumn; | var minRow, maxRow, minColumn, maxColumn; | ||||
[minRow, maxRow] = rows.split(/\s*\.\.\s*/); | [minRow, maxRow] = rows.split(/\s*\.\.\s*/); | ||||
[minColumn, maxColumn] = columns.split(/\s*\.\.\s*/); | [minColumn, maxColumn] = columns.split(/\s*\.\.\s*/); | ||||
this.animations[animationName].push({ | this.animations.push({ | ||||
"minRow": +minRow, | "minRow": +minRow, | ||||
"maxRow": +maxRow, | "maxRow": +maxRow, | ||||
"minColumn": +minColumn, | "minColumn": +minColumn, | ||||
"maxColumn": +maxColumn, | "maxColumn": +maxColumn, | ||||
"animation": replacementAnimationName | "animation": replacementAnimationName | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
Formation.prototype.GetPrimaryMember = function() | Formation.prototype.GetPrimaryMember = function() | ||||
{ | { | ||||
return this.members[0]; | return this.members[0]; | ||||
}; | }; | ||||
/** | /** | ||||
* Get the formation animation for a certain member of this formation | * Get the formation animation for a certain member of this formation | ||||
* @param entity The entity ID to get the animation for | * @param entity The entity ID to get the animation for | ||||
* @param defaultAnimation The name of the default wanted animation for the entity | |||||
* E.g. "walk", "idle" ... | |||||
* @return The name of the transformed animation as defined in the template | * @return The name of the transformed animation as defined in the template | ||||
* E.g. "walk_testudo_row1" | * E.g. "testudo_row1" | ||||
*/ | */ | ||||
Formation.prototype.GetFormationAnimation = function(entity, defaultAnimation) | Formation.prototype.GetFormationAnimation = function(entity) | ||||
{ | { | ||||
var animationGroup = this.animations[defaultAnimation]; | var animationGroup = this.animations; | ||||
if (!animationGroup || this.columnar || !this.memberPositions[entity]) | if (!animationGroup.length || this.columnar || !this.memberPositions[entity]) | ||||
return defaultAnimation; | return "formation"; | ||||
var row = this.memberPositions[entity].row; | var row = this.memberPositions[entity].row; | ||||
var column = this.memberPositions[entity].column; | var column = this.memberPositions[entity].column; | ||||
for (var i = 0; i < animationGroup.length; ++i) | for (var i = 0; i < animationGroup.length; ++i) | ||||
{ | { | ||||
var minRow = animationGroup[i].minRow; | var minRow = animationGroup[i].minRow; | ||||
if (minRow < 0) | if (minRow < 0) | ||||
minRow += this.maxRowsUsed + 1; | minRow += this.maxRowsUsed + 1; | ||||
if (row < minRow) | if (row < minRow) | ||||
Show All 14 Lines | for (var i = 0; i < animationGroup.length; ++i) | ||||
var maxColumn = animationGroup[i].maxColumn; | var maxColumn = animationGroup[i].maxColumn; | ||||
if (maxColumn < 0) | if (maxColumn < 0) | ||||
maxColumn += this.maxColumnsUsed[row] + 1; | maxColumn += this.maxColumnsUsed[row] + 1; | ||||
if (column > maxColumn) | if (column > maxColumn) | ||||
continue; | continue; | ||||
return animationGroup[i].animation; | return animationGroup[i].animation; | ||||
} | } | ||||
return defaultAnimation; | return "formation"; | ||||
}; | }; | ||||
/** | /** | ||||
* Permits formation members to register that they've reached their destination. | * Permits formation members to register that they've reached their destination. | ||||
*/ | */ | ||||
Formation.prototype.SetInPosition = function(ent) | Formation.prototype.SetInPosition = function(ent) | ||||
{ | { | ||||
if (this.inPosition.indexOf(ent) != -1) | if (this.inPosition.indexOf(ent) != -1) | ||||
▲ Show 20 Lines • Show All 747 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator