Changeset View
Standalone View
binaries/data/mods/public/simulation/components/BuildRestrictions.js
function BuildRestrictions() {} | function BuildRestrictions() {} | ||||
BuildRestrictions.prototype.Schema = | BuildRestrictions.prototype.Schema = | ||||
"<a:help>Specifies building placement restrictions as they relate to terrain, territories, and distance.</a:help>" + | "<a:help>Specifies building placement restrictions as they relate to terrain, territories, and distance.</a:help>" + | ||||
"<a:example>" + | "<a:example>" + | ||||
"<BuildRestrictions>" + | "<BuildRestrictions>" + | ||||
"<PlacementType>land</PlacementType>" + | "<PlacementType>land</PlacementType>" + | ||||
"<Territory>own</Territory>" + | "<Territory>own</Territory>" + | ||||
"<Category>Special</Category>" + | "<Category>Structure</Category>" + | ||||
Freagarach: Why this? | |||||
Done Inline Actions"<Category>Special</Category>" is actually unused, keeping it only for this example is rather unnecessary. Nescio: "<Category>Special</Category>" is actually unused, keeping it only for this example is rather… | |||||
Not Done Inline ActionsUsing the same as below kind of implies that they ought to be the same. I'd say just leave this file. Freagarach: Using the same as below kind of implies that they ought to be the same. I'd say just leave this… | |||||
Done Inline ActionsIt could also be changed to e.g. Structure. Keeping Special suggests it exists and is used elsewhere. Nescio: It could also be changed to e.g. `Structure`. Keeping `Special` suggests it exists and is used… | |||||
Not Done Inline ActionsWe have more bogus examples in the codebase? (Reason I nag about this is if this is unneeded we don't need to touch the file at all ^^ This my last one on this -- if you still don't agree we can just make this Structure and be done with it xD) Freagarach: We have more bogus examples in the codebase? (Reason I nag about this is if this is unneeded we… | |||||
Done Inline ActionsNescio: It's an example and thus shouldn't be misleading.
For comparison, the entries in line 35 were… | |||||
Done Inline ActionsDifferent, but okay. Freagarach: Different, but okay. | |||||
"<Distance>" + | "<Distance>" + | ||||
"<FromClass>CivilCentre</FromClass>" + | "<FromClass>CivilCentre</FromClass>" + | ||||
"<MaxDistance>40</MaxDistance>" + | "<MaxDistance>40</MaxDistance>" + | ||||
"</Distance>" + | "</Distance>" + | ||||
"</BuildRestrictions>" + | "</BuildRestrictions>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='PlacementType' a:help='Specifies the terrain type restriction for this building.'>" + | "<element name='PlacementType' a:help='Specifies the terrain type restriction for this building.'>" + | ||||
"<choice>" + | "<choice>" + | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | BuildRestrictions.prototype.CheckPlacement = function() | ||||
if (this.template.Category == "Wall") | if (this.template.Category == "Wall") | ||||
{ | { | ||||
// for walls, only test the center point | // for walls, only test the center point | ||||
var ret = cmpObstruction.CheckFoundation(passClassName, true); | var ret = cmpObstruction.CheckFoundation(passClassName, true); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
var ret = cmpObstruction.CheckFoundation(passClassName, false); | var ret = cmpObstruction.CheckFoundation(passClassName, false); | ||||
Lint: JSHintBear 'ret' is already defined. Lint: JSHintBear: `'ret' is already defined.` | |||||
} | } | ||||
if (ret != "success") | if (ret != "success") | ||||
Lint: JSHintBear 'ret' used out of scope. Lint: JSHintBear: `'ret' used out of scope.` | |||||
{ | { | ||||
switch (ret) | switch (ret) | ||||
Lint: JSHintBear 'ret' used out of scope. Lint: JSHintBear: `'ret' used out of scope.` | |||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "fail_error": | case "fail_error": | ||||
case "fail_no_obstruction": | case "fail_no_obstruction": | ||||
error("CheckPlacement: Error returned from CheckFoundation"); | error("CheckPlacement: Error returned from CheckFoundation"); | ||||
break; | break; | ||||
case "fail_obstructs_foundation": | case "fail_obstructs_foundation": | ||||
result.message = markForTranslation("%(name)s cannot be built on another building or resource"); | result.message = markForTranslation("%(name)s cannot be built on another building or resource"); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (!this.HasTerritory("enemy")) | ||||
invalidTerritory = markForTranslationWithContext("Territory type", "enemy"); | invalidTerritory = markForTranslationWithContext("Territory type", "enemy"); | ||||
} | } | ||||
if (invalidTerritory) | if (invalidTerritory) | ||||
{ | { | ||||
result.message = markForTranslation("%(name)s cannot be built in %(territoryType)s territory. Valid territories: %(validTerritories)s"); | result.message = markForTranslation("%(name)s cannot be built in %(territoryType)s territory. Valid territories: %(validTerritories)s"); | ||||
result.translateParameters.push("territoryType"); | result.translateParameters.push("territoryType"); | ||||
result.translateParameters.push("validTerritories"); | result.translateParameters.push("validTerritories"); | ||||
result.parameters.territoryType = {"context": "Territory type", "message": invalidTerritory}; | result.parameters.territoryType = {"context": "Territory type", "message": invalidTerritory}; | ||||
Lint: ESLintBear (object-curly-spacing) A space is required before '}'. Lint: ESLintBear (object-curly-spacing): `A space is required before '}'.` | |||||
Lint: ESLintBear (object-curly-spacing) A space is required after '{'. Lint: ESLintBear (object-curly-spacing): `A space is required after '{'.` | |||||
// gui code will join this array to a string | // gui code will join this array to a string | ||||
result.parameters.validTerritories = {"context": "Territory type list", "list": this.GetTerritories()}; | result.parameters.validTerritories = {"context": "Territory type list", "list": this.GetTerritories()}; | ||||
Lint: ESLintBear (object-curly-spacing) A space is required after '{'. Lint: ESLintBear (object-curly-spacing): `A space is required after '{'.` | |||||
Lint: ESLintBear (object-curly-spacing) A space is required before '}'. Lint: ESLintBear (object-curly-spacing): `A space is required before '}'.` | |||||
Not Done Inline ActionsUnrelated and not close to changed code. Freagarach: Unrelated and not close to changed code. | |||||
return result; // Fail | return result; // Fail | ||||
} | } | ||||
// Check special requirements | // Check special requirements | ||||
if (this.template.PlacementType == "shore") | if (this.template.PlacementType == "shore") | ||||
{ | { | ||||
if (!cmpObstruction.CheckShorePlacement()) | if (!cmpObstruction.CheckShorePlacement()) | ||||
{ | { | ||||
result.message = markForTranslation("%(name)s must be built on a valid shoreline"); | result.message = markForTranslation("%(name)s must be built on a valid shoreline"); | ||||
return result; // Fail | return result; // Fail | ||||
} | } | ||||
} | } | ||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
let templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | let templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | ||||
let template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); | let template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); | ||||
// Check distance restriction | // Check distance restriction | ||||
if (this.template.Distance) | if (this.template.Distance) | ||||
{ | { | ||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
Lint: JSHintBear 'cmpRangeManager' is already defined. Lint: JSHintBear: `'cmpRangeManager' is already defined.` | |||||
var cat = this.template.Distance.FromClass; | var cat = this.template.Distance.FromClass; | ||||
var filter = function(id) | var filter = function(id) | ||||
{ | { | ||||
var cmpIdentity = Engine.QueryInterface(id, IID_Identity); | var cmpIdentity = Engine.QueryInterface(id, IID_Identity); | ||||
Lint: ESLintBear (no-shadow) 'cmpIdentity' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'cmpIdentity' is already declared in the upper scope.` | |||||
return cmpIdentity.GetClassesList().indexOf(cat) > -1; | return cmpIdentity.GetClassesList().indexOf(cat) > -1; | ||||
}; | }; | ||||
if (this.template.Distance.MinDistance !== undefined) | if (this.template.Distance.MinDistance !== undefined) | ||||
{ | { | ||||
let minDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MinDistance", +this.template.Distance.MinDistance, cmpPlayer.GetPlayerID(), template); | let minDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MinDistance", +this.template.Distance.MinDistance, cmpPlayer.GetPlayerID(), template); | ||||
if (cmpRangeManager.ExecuteQuery(this.entity, 0, minDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).some(filter)) | if (cmpRangeManager.ExecuteQuery(this.entity, 0, minDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).some(filter)) | ||||
{ | { | ||||
let result = markForPluralTranslation( | let result = markForPluralTranslation( | ||||
Lint: ESLintBear (no-shadow) 'result' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'result' is already declared in the upper scope.` | |||||
"%(name)s too close to a %(category)s, must be at least %(distance)s meter away", | "%(name)s too close to a %(category)s, must be at least %(distance)s meter away", | ||||
"%(name)s too close to a %(category)s, must be at least %(distance)s meters away", | "%(name)s too close to a %(category)s, must be at least %(distance)s meters away", | ||||
minDistance); | minDistance); | ||||
result.success = false; | result.success = false; | ||||
result.translateMessage = true; | result.translateMessage = true; | ||||
result.parameters = { | result.parameters = { | ||||
"name": name, | "name": name, | ||||
"category": cat, | "category": cat, | ||||
"distance": minDistance | "distance": minDistance | ||||
}; | }; | ||||
result.translateParameters = ["name", "category"]; | result.translateParameters = ["name", "category"]; | ||||
return result; // Fail | return result; // Fail | ||||
} | } | ||||
} | } | ||||
if (this.template.Distance.MaxDistance !== undefined) | if (this.template.Distance.MaxDistance !== undefined) | ||||
{ | { | ||||
let maxDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MaxDistance", +this.template.Distance.MaxDistance, cmpPlayer.GetPlayerID(), template); | let maxDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MaxDistance", +this.template.Distance.MaxDistance, cmpPlayer.GetPlayerID(), template); | ||||
if (!cmpRangeManager.ExecuteQuery(this.entity, 0, maxDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).some(filter)) | if (!cmpRangeManager.ExecuteQuery(this.entity, 0, maxDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).some(filter)) | ||||
{ | { | ||||
let result = markForPluralTranslation( | let result = markForPluralTranslation( | ||||
Lint: ESLintBear (no-shadow) 'result' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'result' is already declared in the upper scope.` | |||||
"%(name)s too far from a %(category)s, must be within %(distance)s meter", | "%(name)s too far from a %(category)s, must be within %(distance)s meter", | ||||
"%(name)s too far from a %(category)s, must be within %(distance)s meters", | "%(name)s too far from a %(category)s, must be within %(distance)s meters", | ||||
maxDistance); | maxDistance); | ||||
result.success = false; | result.success = false; | ||||
result.translateMessage = true; | result.translateMessage = true; | ||||
result.parameters = { | result.parameters = { | ||||
"name": name, | "name": name, | ||||
Show All 40 Lines |
Why this?