Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GuiInterface.js
Show First 20 Lines • Show All 1,034 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
let result = { | let result = { | ||||
"success": false, | "success": false, | ||||
"message": "", | "message": "", | ||||
"parameters": {}, | "parameters": {}, | ||||
"translateMessage": false, | "translateMessage": false, | ||||
"translateParameters": [], | "translateParameters": [], | ||||
}; | }; | ||||
if (cmd.snapEntities) | |||||
{ | |||||
let snapRadius = 10; | |||||
let snapData = this.GetFoundationSnapData(player, { | |||||
"x": cmd.x, | |||||
"z": cmd.z, | |||||
"template": "template_socket", | |||||
"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 | ||||
Silier: half of foundation size ? | |||||
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)]; | ||||
▲ Show 20 Lines • Show All 576 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 All 24 Lines | GuiInterface.prototype.GetFoundationSnapData = function(player, data) | ||||
if (data.snapToEdges) | if (data.snapToEdges) | ||||
{ | { | ||||
let position = this.obstructionSnap.getPosition(data, template); | let position = this.obstructionSnap.getPosition(data, template); | ||||
if (position) | if (position) | ||||
return position; | return position; | ||||
} | } | ||||
if (template.BuildRestrictions.PlacementType == "shore") | if (template.BuildRestrictions && | ||||
template.BuildRestrictions.PlacementType == "shore") | |||||
{ | { | ||||
let angle = GetDockAngle(template, data.x, data.z); | let angle = GetDockAngle(template, data.x, data.z); | ||||
if (angle !== undefined) | if (angle !== undefined) | ||||
return { | return { | ||||
"x": data.x, | "x": data.x, | ||||
"z": data.z, | "z": data.z, | ||||
"angle": angle | "angle": angle | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 330 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
half of foundation size ?