Skip to content

Commit

Permalink
Merge pull request simonlourson#13 from Sinetheta/keyboard
Browse files Browse the repository at this point in the history
add b for build button support
  • Loading branch information
RaceFPV authored Mar 22, 2023
2 parents 8567bdd + 1446142 commit 76f5343
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
41 changes: 39 additions & 2 deletions frontend/src/app/module-blueprint/common/tools/select-tool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BlueprintService } from "../../services/blueprint-service";
import {
BlueprintHelpers,
BlueprintItem,
CameraService,
DrawHelpers,
Expand All @@ -11,13 +12,16 @@ import { Injectable } from "@angular/core";
import { ITool, ToolType } from "./tool";
import { DrawPixi } from "../../drawing/draw-pixi";
import { SameItemCollection } from "./same-item-collection";
import { ToolService } from "src/app/module-blueprint/services/tool-service";

@Injectable()
export class SelectTool implements ITool {
public sameItemCollections: SameItemCollection[];

public observersSelectionChanged: IObsSelectionChanged[] = [];

parent: ToolService;

private cameraService: CameraService;
constructor(private blueprintService: BlueprintService) {
this.cameraService = CameraService.cameraService;
Expand Down Expand Up @@ -300,10 +304,28 @@ export class SelectTool implements ITool {
mouseDown(tile: Vector2) {}

leftClick(tile: Vector2) {
this.selectFromBox(tile, tile);
let doSelectFromBox = true;

if (this.currentMultipleSelectionIndex != -1) {
let next_group =
(this.currentMultipleSelectionIndex + 1) %
this.sameItemCollections.length;
doSelectFromBox =
this.sameItemCollections[next_group].items.find((item) =>
item.position.equals(tile)
) === undefined;
}

if (doSelectFromBox) {
this.selectFromBox(tile, tile);
} else {
this.itemGroupeNext();
}
}

rightClick(tile: Vector2) {}
rightClick(tile: Vector2) {
this.deselectAll();
}

hover(tile: Vector2) {}

Expand Down Expand Up @@ -343,6 +365,21 @@ export class SelectTool implements ITool {
this.buildingsDestroy(
this.sameItemCollections[itemGroupToDestroyIndex]
);
} else if (keyCode == "b") {
// find the currently selected item
let newItem = null;
let itemGroupToDestroyIndex = this.currentMultipleSelectionIndex;
if (itemGroupToDestroyIndex != -1) {
newItem = BlueprintHelpers.cloneBlueprintItem(
this.sameItemCollections[itemGroupToDestroyIndex].items[0]
);
}

// change tool
this.parent.changeTool(ToolType.build);
if (newItem != null) {
this.parent.buildTool.changeItem(newItem);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/module-blueprint/services/tool-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class ToolService implements ITool, IChangeTool {
this.allTools.push(this.buildTool);

this.buildTool.parent = this;
this.selectTool.parent = this;
}

subscribeToolChanged(observer: IObsToolChanged) {
Expand Down

0 comments on commit 76f5343

Please sign in to comment.