Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | else if (placementSupport.mode === "wall") | ||||
{ | { | ||||
// Fetch an updated list of snapping candidate entities | // Fetch an updated list of snapping candidate entities | ||||
placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities( | placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities( | ||||
placementSupport.wallSet.templates.tower, | placementSupport.wallSet.templates.tower, | ||||
placementSupport.wallSnapEntitiesIncludeOffscreen, | placementSupport.wallSnapEntitiesIncludeOffscreen, | ||||
true, // require exact template match | true, // require exact template match | ||||
true // include foundations | true // include foundations | ||||
); | ); | ||||
placementSupport.wallSlots = null; | |||||
Freagarach: Is `placementSupport.wallSlots;` the same? | |||||
Done Inline ActionsWould be undefined :) Stan: Would be undefined :) | |||||
Done Inline ActionsYou can define this in placement.js as is the case of other properties. Freagarach: You can define this in `placement.js` as is the case of other properties. | |||||
if (placementSupport.wallSet.towerSlot) { | |||||
placementSupport.wallSlots = Engine.GuiInterfaceCall("getSlots", {"player": g_ViewedPlayer}); | |||||
} | |||||
return Engine.GuiInterfaceCall("SetWallPlacementPreview", { | return Engine.GuiInterfaceCall("SetWallPlacementPreview", { | ||||
"wallSet": placementSupport.wallSet, | "wallSet": placementSupport.wallSet, | ||||
"start": placementSupport.position, | "start": placementSupport.position, | ||||
"end": placementSupport.wallEndPosition, | "end": placementSupport.wallEndPosition, | ||||
"snapEntities": placementSupport.wallSnapEntities, // snapping entities (towers) for starting a wall segment | "snapEntities": placementSupport.wallSnapEntities, // snapping entities (towers) for starting a wall segment | ||||
"snapSlots": placementSupport.wallSlots | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | function tryPlaceBuilding(queued) | ||||
if (!updateBuildingPlacementPreview()) | if (!updateBuildingPlacementPreview()) | ||||
{ | { | ||||
// invalid location - don't build it | // invalid location - don't build it | ||||
// TODO: play a sound? | // TODO: play a sound? | ||||
return false; | return false; | ||||
} | } | ||||
var selection = g_Selection.toList(); | let selection = g_Selection.toList(); | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "construct", | "type": "construct", | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"angle": placementSupport.angle, | "angle": placementSupport.angle, | ||||
"actorSeed": placementSupport.actorSeed, | "actorSeed": placementSupport.actorSeed, | ||||
Show All 15 Lines | |||||
function tryPlaceWall(queued) | function tryPlaceWall(queued) | ||||
{ | { | ||||
if (placementSupport.mode !== "wall") | if (placementSupport.mode !== "wall") | ||||
{ | { | ||||
error("tryPlaceWall expected 'wall', got '" + placementSupport.mode + "'"); | error("tryPlaceWall expected 'wall', got '" + placementSupport.mode + "'"); | ||||
return false; | return false; | ||||
} | } | ||||
var wallPlacementInfo = updateBuildingPlacementPreview(); // entities making up the wall (wall segments, towers, ...) | let wallPlacementInfo = updateBuildingPlacementPreview(); // entities making up the wall (wall segments, towers, ...) | ||||
if (!(wallPlacementInfo === false || typeof(wallPlacementInfo) === "object")) | if (!(wallPlacementInfo === false || typeof(wallPlacementInfo) === "object")) | ||||
{ | { | ||||
error("Invalid updateBuildingPlacementPreview return value: " + uneval(wallPlacementInfo)); | error("Invalid updateBuildingPlacementPreview return value: " + uneval(wallPlacementInfo)); | ||||
return false; | return false; | ||||
} | } | ||||
if (!wallPlacementInfo) | if (!wallPlacementInfo) | ||||
return false; | return false; | ||||
var selection = g_Selection.toList(); | let selection = g_Selection.toList(); | ||||
var cmd = { | let cmd = { | ||||
"type": "construct-wall", | "type": "construct-wall", | ||||
"autorepair": true, | "autorepair": true, | ||||
"autocontinue": true, | "autocontinue": true, | ||||
"queued": queued, | "queued": queued, | ||||
"entities": selection, | "entities": selection, | ||||
"wallSet": placementSupport.wallSet, | "wallSet": placementSupport.wallSet, | ||||
"pieces": wallPlacementInfo.pieces, | "pieces": wallPlacementInfo.pieces, | ||||
"startSnappedEntity": wallPlacementInfo.startSnappedEnt, | "startSnappedEntity": wallPlacementInfo.startSnappedEnt, | ||||
"endSnappedEntity": wallPlacementInfo.endSnappedEnt, | "endSnappedEntity": wallPlacementInfo.endSnappedEnt, | ||||
"rebuildStartTower": wallPlacementInfo.rebuildStartTower | |||||
}; | }; | ||||
// make sure that there's at least one non-tower entity getting built, to prevent silly edge cases where the start and end | // make sure that there's at least one non-tower entity getting built, to prevent silly edge cases where the start and end | ||||
// point are too close together for the algorithm to place a wall segment inbetween, and only the towers are being previewed | // point are too close together for the algorithm to place a wall segment inbetween, and only the towers are being previewed | ||||
// (this is somewhat non-ideal and hardcode-ish) | // (this is somewhat non-ideal and hardcode-ish) | ||||
var hasWallSegment = false; | let hasWallSegment = false; | ||||
for (let piece of cmd.pieces) | for (let piece of cmd.pieces) | ||||
{ | { | ||||
if (piece.template != cmd.wallSet.templates.tower) // TODO: hardcode-ish :( | if (piece.template != cmd.wallSet.templates.tower) // TODO: hardcode-ish :( | ||||
{ | { | ||||
hasWallSegment = true; | hasWallSegment = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (hasWallSegment) | if (hasWallSegment || cmd.rebuildStartTower) | ||||
{ | { | ||||
Engine.PostNetworkCommand(cmd); | Engine.PostNetworkCommand(cmd); | ||||
Engine.GuiInterfaceCall("PlaySound", { "name": "order_repair", "entity": selection[0] }); | Engine.GuiInterfaceCall("PlaySound", { "name": "order_repair", "entity": selection[0] }); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | switch (ev.type) | ||||
placementSupport.wallEndPosition = undefined; | placementSupport.wallEndPosition = undefined; | ||||
inputState = INPUT_BUILDING_WALL_CLICK; | inputState = INPUT_BUILDING_WALL_CLICK; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
Engine.GuiInterfaceCall("SetSlotVisibility", {"player": g_ViewedPlayer, "active": false}); | |||||
} | } | ||||
} | } | ||||
else | else | ||||
placementSupport.tooltipMessage = translate("Cannot build wall here!"); | placementSupport.tooltipMessage = translate("Cannot build wall here!"); | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
return true; | return true; | ||||
} | } | ||||
else if (ev.button == SDL_BUTTON_RIGHT) | else if (ev.button == SDL_BUTTON_RIGHT) | ||||
{ | { | ||||
Engine.GuiInterfaceCall("SetSlotVisibility", {"player": g_ViewedPlayer, "active": false}); | |||||
// reset to normal input mode | // reset to normal input mode | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | case "mousebuttondown": | ||||
g_DragStart = new Vector2D(ev.x, ev.y); | g_DragStart = new Vector2D(ev.x, ev.y); | ||||
inputState = INPUT_BUILDING_CLICK; | inputState = INPUT_BUILDING_CLICK; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
else if (ev.button == SDL_BUTTON_RIGHT) | else if (ev.button == SDL_BUTTON_RIGHT) | ||||
{ | { | ||||
// Cancel building | // Cancel building | ||||
Engine.GuiInterfaceCall("SetSlotVisibility", {"player": g_ViewedPlayer, "active": false}); | |||||
StanAuthorUnsubmitted Done Inline Actions{"player": g_ViewedPlayer, "active": false} → { "player": g_ViewedPlayer, "active": false } Stan: {"player": g_ViewedPlayer, "active": false} → { "player": g_ViewedPlayer, "active": false } | |||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
case "hotkeydown": | case "hotkeydown": | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | function startBuildingPlacement(buildTemplate, playerState) | ||||
// TODO: we should clear any highlight selection rings here. If the mouse was over an entity before going onto the GUI | // TODO: we should clear any highlight selection rings here. If the mouse was over an entity before going onto the GUI | ||||
// to start building a structure, then the highlight selection rings are kept during the construction of the building. | // to start building a structure, then the highlight selection rings are kept during the construction of the building. | ||||
// Gives the impression that somehow the hovered-over entity has something to do with the building you're constructing. | // Gives the impression that somehow the hovered-over entity has something to do with the building you're constructing. | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
// find out if we're building a wall, and change the entity appropriately if so | // find out if we're building a wall, and change the entity appropriately if so | ||||
var templateData = GetTemplateData(buildTemplate); | let templateData = GetTemplateData(buildTemplate); | ||||
if (templateData.wallSet) | if (templateData.wallSet) | ||||
{ | { | ||||
placementSupport.mode = "wall"; | placementSupport.mode = "wall"; | ||||
placementSupport.wallSet = templateData.wallSet; | placementSupport.wallSet = templateData.wallSet; | ||||
inputState = INPUT_BUILDING_PLACEMENT; | inputState = INPUT_BUILDING_PLACEMENT; | ||||
Engine.GuiInterfaceCall("SetSlotVisibility", {"player": g_ViewedPlayer, "active": true}); | |||||
elexisUnsubmitted Done Inline Actions{space space} for JS objects elexis: {space space} for JS objects | |||||
StanAuthorUnsubmitted Done Inline Actions{"player": g_ViewedPlayer, "active": true}) → { "player": g_ViewedPlayer, "active": true }) Maybe it could be a function ? Stan: {"player": g_ViewedPlayer, "active": true}) → { "player": g_ViewedPlayer, "active": true })… | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
placementSupport.mode = "building"; | placementSupport.mode = "building"; | ||||
placementSupport.template = buildTemplate; | placementSupport.template = buildTemplate; | ||||
inputState = INPUT_BUILDING_PLACEMENT; | inputState = INPUT_BUILDING_PLACEMENT; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 330 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Is placementSupport.wallSlots; the same?