Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GuiInterface.js
Show First 20 Lines • Show All 1,035 Lines • ▼ Show 20 Lines | GuiInterface.prototype.SetBuildingPlacementPreview = function(player, cmd) | ||||
let result = { | let result = { | ||||
"success": false, | "success": false, | ||||
"message": "", | "message": "", | ||||
"parameters": {}, | "parameters": {}, | ||||
"translateMessage": false, | "translateMessage": false, | ||||
"translateParameters": [], | "translateParameters": [], | ||||
}; | }; | ||||
let snapData; | |||||
if (cmd.snapEntities) | |||||
{ | |||||
let snapRadius = 10; // ToDo: Adapt. | |||||
Silier: half of foundation size ? | |||||
snapData = this.GetFoundationSnapData(player, { | |||||
"x": cmd.x, | |||||
"z": cmd.z, | |||||
"template": cmd.template, | |||||
"snapEntities": cmd.snapEntities, | |||||
"snapRadius": snapRadius, | |||||
}); | |||||
if (snapData) | |||||
{ | |||||
cmd.x = snapData.x; | |||||
cmd.z = snapData.z; | |||||
cmd.angle = snapData.angle; | |||||
cmd.snapped = true; | |||||
if (snapData.ent) | |||||
cmd.snappedEnt = snapData.ent; | |||||
} | |||||
} | |||||
// See if we're changing template | // See if we're changing template | ||||
if (!this.placementEntity || this.placementEntity[0] != cmd.template) | if (!this.placementEntity || this.placementEntity[0] != cmd.template) | ||||
{ | { | ||||
// Destroy the old preview if there was one | // Destroy the old preview if there was one | ||||
if (this.placementEntity) | if (this.placementEntity) | ||||
Engine.DestroyEntity(this.placementEntity[1]); | Engine.DestroyEntity(this.placementEntity[1]); | ||||
// Load the new template | // Load the new template | ||||
Show All 20 Lines | if (this.placementEntity) | ||||
// Check whether building placement is valid | // Check whether building placement is valid | ||||
let cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); | let cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); | ||||
if (!cmpBuildRestrictions) | if (!cmpBuildRestrictions) | ||||
error("cmpBuildRestrictions not defined"); | error("cmpBuildRestrictions not defined"); | ||||
else | else | ||||
result = cmpBuildRestrictions.CheckPlacement(); | result = cmpBuildRestrictions.CheckPlacement(); | ||||
result.x = cmd.x; | |||||
result.z = cmd.z; | |||||
if (snapData) | |||||
{ | |||||
result.x = snapData.x; | |||||
result.z = snapData.z; | |||||
if (snapData.ent) | |||||
result.snappedEnt = snapData.ent | |||||
} | |||||
let cmpRangeOverlayManager = Engine.QueryInterface(ent, IID_RangeOverlayManager); | let cmpRangeOverlayManager = Engine.QueryInterface(ent, IID_RangeOverlayManager); | ||||
if (cmpRangeOverlayManager) | if (cmpRangeOverlayManager) | ||||
cmpRangeOverlayManager.SetEnabled(true, this.enabledVisualRangeOverlayTypes); | cmpRangeOverlayManager.SetEnabled(true, this.enabledVisualRangeOverlayTypes); | ||||
// Set it to a red shade if this is an invalid location | // Set it to a red shade if this is an invalid location | ||||
let cmpVisual = Engine.QueryInterface(ent, IID_Visual); | let cmpVisual = Engine.QueryInterface(ent, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 544 Lines • ▼ Show 20 Lines | GuiInterface.prototype.GetFoundationSnapData = function(player, data) | ||||
if (!template) | if (!template) | ||||
{ | { | ||||
warn("[GetFoundationSnapData] Failed to load template '" + data.template + "'"); | warn("[GetFoundationSnapData] Failed to load template '" + data.template + "'"); | ||||
return false; | return false; | ||||
} | } | ||||
if (data.snapEntities && data.snapRadius && data.snapRadius > 0) | if (data.snapEntities && data.snapRadius && data.snapRadius > 0) | ||||
{ | { | ||||
// see if {data.x, data.z} is inside the snap radius of any of the snap entities; and if so, to which it is closest | // see if {data.x, data.z} is inside the snap radius of any of the snap entities; and if so, to which it is closest | ||||
Not Done Inline Actions2.0 ? Stan: 2.0 ? | |||||
// (TODO: break unlikely ties by choosing the lowest entity ID) | // (TODO: break unlikely ties by choosing the lowest entity ID) | ||||
let minDist2 = -1; | let minDist2 = -1; | ||||
let minDistEntitySnapData = null; | let minDistEntitySnapData = null; | ||||
let radius2 = data.snapRadius * data.snapRadius; | let radius2 = data.snapRadius * data.snapRadius; | ||||
for (let ent of data.snapEntities) | for (let ent of data.snapEntities) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 371 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
half of foundation size ?