|
@@ -2,10 +2,6 @@ import { scene } from "./scene.js";
|
|
|
import { push } from "./push.js";
|
|
import { push } from "./push.js";
|
|
|
import { material_icon } from "./icons.js";
|
|
import { material_icon } from "./icons.js";
|
|
|
import { container } from "./container.js";
|
|
import { container } from "./container.js";
|
|
|
-import { moving_directions } from "./directions.js";
|
|
|
|
|
-import { rotating_directions } from "./directions.js";
|
|
|
|
|
-import { is_moving_direction } from "./directions.js";
|
|
|
|
|
-import { is_rotating_direction } from "./directions.js";
|
|
|
|
|
import { position } from "./position.js";
|
|
import { position } from "./position.js";
|
|
|
|
|
|
|
|
class scene_ui {
|
|
class scene_ui {
|
|
@@ -28,29 +24,33 @@ class scene_ui {
|
|
|
this.#worker = worker;
|
|
this.#worker = worker;
|
|
|
|
|
|
|
|
this.#step_front = this.#create_push(
|
|
this.#step_front = this.#create_push(
|
|
|
- "front", "arrow_drop_up", moving_directions.front
|
|
|
|
|
|
|
+ "front", "arrow_drop_up",
|
|
|
|
|
+ (player) => { player.movement.add_front(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#step_back = this.#create_push(
|
|
this.#step_back = this.#create_push(
|
|
|
- "back", "arrow_drop_down", moving_directions.back
|
|
|
|
|
|
|
+ "back", "arrow_drop_down",
|
|
|
|
|
+ (player) => { player.movement.add_back(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#step_left = this.#create_push(
|
|
this.#step_left = this.#create_push(
|
|
|
- "left", "arrow_left", moving_directions.left
|
|
|
|
|
|
|
+ "left", "arrow_left",
|
|
|
|
|
+ (player) => { player.movement.add_left(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#step_right = this.#create_push(
|
|
this.#step_right = this.#create_push(
|
|
|
- "right", "arrow_right", moving_directions.right
|
|
|
|
|
|
|
+ "right", "arrow_right",
|
|
|
|
|
+ (player) => { player.movement.add_right(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#rotate_clockwise = this.#create_push(
|
|
this.#rotate_clockwise = this.#create_push(
|
|
|
"clockwise", "rotate_right",
|
|
"clockwise", "rotate_right",
|
|
|
- rotating_directions.clockwise
|
|
|
|
|
|
|
+ (player) => { player.rotation.add_right(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#rotate_countclockwise = this.#create_push(
|
|
this.#rotate_countclockwise = this.#create_push(
|
|
|
"countclockwise", "rotate_left",
|
|
"countclockwise", "rotate_left",
|
|
|
- rotating_directions.counterclockwise
|
|
|
|
|
|
|
+ (player) => { player.rotation.add_left(); }
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
this.#setup_stopers();
|
|
this.#setup_stopers();
|
|
@@ -80,19 +80,19 @@ class scene_ui {
|
|
|
document.addEventListener("keydown", (action) => {
|
|
document.addEventListener("keydown", (action) => {
|
|
|
switch (action.key) {
|
|
switch (action.key) {
|
|
|
case "w":
|
|
case "w":
|
|
|
- this.#worker.player.moving = moving_directions.front;
|
|
|
|
|
|
|
+ this.#worker.player.movement.add_front();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case "s":
|
|
case "s":
|
|
|
- this.#worker.player.moving = moving_directions.back;
|
|
|
|
|
|
|
+ this.#worker.player.movement.add_back();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case "d":
|
|
case "d":
|
|
|
- this.#worker.player.moving = moving_directions.right;
|
|
|
|
|
|
|
+ this.#worker.player.movement.add_right();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case "a":
|
|
case "a":
|
|
|
- this.#worker.player.moving = moving_directions.left;
|
|
|
|
|
|
|
+ this.#worker.player.movement.add_left();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -104,9 +104,12 @@ class scene_ui {
|
|
|
switch (action.key) {
|
|
switch (action.key) {
|
|
|
case "w":
|
|
case "w":
|
|
|
case "s":
|
|
case "s":
|
|
|
|
|
+ this.#worker.player.movement.stop_front_back();
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
case "a":
|
|
case "a":
|
|
|
case "d":
|
|
case "d":
|
|
|
- this.#worker.player.moving = moving_directions.stop;
|
|
|
|
|
|
|
+ this.#worker.player.movement.stop_left_right();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -141,8 +144,8 @@ class scene_ui {
|
|
|
|
|
|
|
|
#setup_stopers() {
|
|
#setup_stopers() {
|
|
|
const stoper = () => {
|
|
const stoper = () => {
|
|
|
- this.#worker.player.moving = moving_directions.stop;
|
|
|
|
|
- this.#worker.player.rotating = rotating_directions.stop;
|
|
|
|
|
|
|
+ this.#worker.player.movement.stop();
|
|
|
|
|
+ this.#worker.player.rotation.stop();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener("mouseup", stoper);
|
|
document.addEventListener("mouseup", stoper);
|
|
@@ -150,23 +153,13 @@ class scene_ui {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#create_push(name, icon, move) {
|
|
#create_push(name, icon, move) {
|
|
|
- if (!is_moving_direction(move) && !is_rotating_direction(move)) {
|
|
|
|
|
- throw new TypeError("Move muse be an direction.");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return push(name, null, (target) => {
|
|
return push(name, null, (target) => {
|
|
|
target.innerText = "";
|
|
target.innerText = "";
|
|
|
target.appendChild(material_icon(icon));
|
|
target.appendChild(material_icon(icon));
|
|
|
-
|
|
|
|
|
- if (is_moving_direction(move)) {
|
|
|
|
|
- target.addEventListener("mousedown", () => {
|
|
|
|
|
- this.#worker.player.moving = move;
|
|
|
|
|
- });
|
|
|
|
|
- } else if (is_rotating_direction(move)) {
|
|
|
|
|
- target.addEventListener("mousedown", () => {
|
|
|
|
|
- this.#worker.player.rotating = move;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ target.addEventListener("mousedown", () => {
|
|
|
|
|
+ move(this.#worker.player);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|