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) | |||||
{ | |||||
snapData = this.GetFoundationSnapData(player, { | |||||
Silier: half of foundation size ? | |||||
"x": cmd.pos.x, | |||||
"z": cmd.pos.z, | |||||
"template": cmd.template, | |||||
"snapEntities": cmd.snapEntities | |||||
}); | |||||
if (snapData) | |||||
this.SetSnapData(snapData, cmd, true); | |||||
} | |||||
// 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 | ||||
if (cmd.template == "") | if (cmd.template == "") | ||||
this.placementEntity = undefined; | this.placementEntity = undefined; | ||||
else | else | ||||
this.placementEntity = [cmd.template, Engine.AddLocalEntity("preview|" + cmd.template)]; | this.placementEntity = [cmd.template, Engine.AddLocalEntity("preview|" + cmd.template)]; | ||||
} | } | ||||
if (this.placementEntity) | if (this.placementEntity) | ||||
{ | { | ||||
let ent = this.placementEntity[1]; | let ent = this.placementEntity[1]; | ||||
// Move the preview into the right location | // Move the preview into the right location | ||||
let pos = Engine.QueryInterface(ent, IID_Position); | let pos = Engine.QueryInterface(ent, IID_Position); | ||||
if (pos) | if (pos) | ||||
{ | { | ||||
pos.JumpTo(cmd.x, cmd.z); | pos.JumpTo(cmd.pos.x, cmd.pos.z); | ||||
pos.SetYRotation(cmd.angle); | pos.SetYRotation(cmd.angle); | ||||
} | } | ||||
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); | ||||
cmpOwnership.SetOwner(player); | cmpOwnership.SetOwner(player); | ||||
// 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.pos.x; | |||||
result.z = cmd.pos.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 162 Lines • ▼ Show 20 Lines | let startSnapData = this.GetFoundationSnapData(player, { | ||||
"x": start.pos.x, | "x": start.pos.x, | ||||
"z": start.pos.z, | "z": start.pos.z, | ||||
"template": wallSet.templates.tower, | "template": wallSet.templates.tower, | ||||
"snapEntities": cmd.snapEntities, | "snapEntities": cmd.snapEntities, | ||||
"snapRadius": snapRadius, | "snapRadius": snapRadius, | ||||
}); | }); | ||||
if (startSnapData) | if (startSnapData) | ||||
{ | this.SetSnapData(startSnapData, start); | ||||
start.pos.x = startSnapData.x; | |||||
start.pos.z = startSnapData.z; | |||||
start.angle = startSnapData.angle; | |||||
start.snapped = true; | |||||
if (startSnapData.ent) | |||||
start.snappedEnt = startSnapData.ent; | |||||
} | |||||
if (end.pos) | if (end.pos) | ||||
{ | { | ||||
let endSnapData = this.GetFoundationSnapData(player, { | let endSnapData = this.GetFoundationSnapData(player, { | ||||
"x": end.pos.x, | "x": end.pos.x, | ||||
"z": end.pos.z, | "z": end.pos.z, | ||||
"template": wallSet.templates.tower, | "template": wallSet.templates.tower, | ||||
"snapEntities": cmd.snapEntities, | "snapEntities": cmd.snapEntities, | ||||
"snapRadius": snapRadius, | "snapRadius": snapRadius, | ||||
}); | }); | ||||
if (endSnapData) | if (endSnapData) | ||||
{ | this.SetSnapData(endSnapData, end); | ||||
end.pos.x = endSnapData.x; | |||||
end.pos.z = endSnapData.z; | |||||
end.angle = endSnapData.angle; | |||||
end.snapped = true; | |||||
if (endSnapData.ent) | |||||
end.snappedEnt = endSnapData.ent; | |||||
} | |||||
} | } | ||||
} | } | ||||
// clear the single-building preview entity (we'll be rolling our own) | // clear the single-building preview entity (we'll be rolling our own) | ||||
this.SetBuildingPlacementPreview(player, { "template": "" }); | this.SetBuildingPlacementPreview(player, { "template": "" }); | ||||
// -------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------- | ||||
// calculate wall placement and position preview entities | // calculate wall placement and position preview entities | ||||
▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
let template = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetTemplate(data.template); | let template = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetTemplate(data.template); | ||||
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 = Math.max( | |||||
template.Obstruction.Static["@depth"] / 2, | |||||
StanUnsubmitted Not Done Inline Actions2.0 ? Stan: 2.0 ? | |||||
template.Obstruction.Static["@width"] / 2); | |||||
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 | ||||
// (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; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (angle !== undefined) | ||||
"z": data.z, | "z": data.z, | ||||
"angle": angle | "angle": angle | ||||
}; | }; | ||||
} | } | ||||
return false; | return false; | ||||
}; | }; | ||||
/** | |||||
* @param {Object} snapData - The snapped object's data. | |||||
* @param {Object} target - The snapped object's target object. | |||||
* @param {boolean} isSnappedSlot - Whether the object is a slot. | |||||
*/ | |||||
GuiInterface.prototype.SetSnapData = function(snapData, target, isSnappedSlot) | |||||
{ | |||||
target.pos.x = snapData.x; | |||||
target.pos.z = snapData.z; | |||||
target.angle = snapData.angle; | |||||
target.snapped = true; | |||||
target.snappedSlot = isSnappedSlot; | |||||
if (snapData.ent) | |||||
target.snappedEnt = snapData.ent; | |||||
}; | |||||
GuiInterface.prototype.PlaySound = function(player, data) | GuiInterface.prototype.PlaySound = function(player, data) | ||||
{ | { | ||||
if (!data.entity) | if (!data.entity) | ||||
return; | return; | ||||
PlaySound(data.name, data.entity); | PlaySound(data.name, data.entity); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 317 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
half of foundation size ?