Skip to content

Commit

Permalink
TPS movements unit module was added.
Browse files Browse the repository at this point in the history
Unit action manager and unit controller are removed, instead of them you can create your own config easily with the unit controller module.
Unit controller boilerplate was added.
  • Loading branch information
NewKrok committed Apr 10, 2022
1 parent c418c6e commit 021281e
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 415 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newkrok/three-tps",
"version": "0.3.0",
"version": "0.4.0",
"description": "TPS extension for THREE Game",
"exports": {
"./src/*": "./src/*"
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/NewKrok/three-tps#readme",
"dependencies": {
"@newkrok/three-game": "0.3.0"
"@newkrok/three-game": "0.4.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
UnitActionId,
unitControllerConfig,
} from "@newkrok/three-game/src/js/newkrok/three-game/boilerplates/unit-controller-boilerplates.js";

import { ButtonKey } from "@newkrok/three-game/src/js/newkrok/three-game/control/gamepad.js";
import { Mouse } from "@newkrok/three-game/src/js/newkrok/three-game/control/mouse.js";
import { TPSUnitModuleId } from "@newkrok/three-tps/src/js/newkrok/three-tps/modules/tps-module-enums.js";

export const TPSUnitActionId = {
...UnitActionId,
CAMERA: "CAMERA",
AIM: "AIM",
};

export const tpsUnitControllerConfig = {
actionConfig: [
...unitControllerConfig.actionConfig,
{
actionId: UnitActionId.CAMERA,
customTrigger: (trigger) => {
document.addEventListener("mousemove", ({ movementX, movementY }) => {
trigger({ x: movementX / 350, y: movementY / 350 });
});
},
gamepadButtons: [ButtonKey.LeftAxisX, ButtonKey.LeftAxisY],
},
{
actionId: UnitActionId.AIM,
mouse: [Mouse.RIGHT_BUTTON],
gamepadButtons: [ButtonKey.LeftTrigger],
},
],

handlers: [
...unitControllerConfig.handlers,
{
actionId: UnitActionId.FORWARD,
callback: ({ unit, value }) => {
const tpsMovementModule = unit.getModule(TPSUnitModuleId.TPS_MOVEMENT);
tpsMovementModule.setForwardValue(value);
},
},
{
actionId: UnitActionId.BACKWARD,
callback: ({ unit, value }) => {
const tpsMovementModule = unit.getModule(TPSUnitModuleId.TPS_MOVEMENT);
tpsMovementModule.setBackwardValue(value);
},
},
{
actionId: UnitActionId.LEFT,
callback: ({ unit, value }) => {
const tpsMovementModule = unit.getModule(TPSUnitModuleId.TPS_MOVEMENT);
tpsMovementModule.setLeftValue(value);
},
},
{
actionId: UnitActionId.RIGHT,
callback: ({ unit, value }) => {
const tpsMovementModule = unit.getModule(TPSUnitModuleId.TPS_MOVEMENT);
tpsMovementModule.setRightValue(value);
},
},
{
actionId: UnitActionId.CAMERA,
callback: ({ world, value: { x, y } }) => {
world.tpsCamera.updateRotation({ x, y });
},
},
{
actionId: UnitActionId.AIM,
callback: ({ unit, world }) => {
unit.userData.useAim = !unit.userData.useAim;
if (unit.userData.useAim) world.tpsCamera.useAimZoom();
else {
world.tpsCamera.disableAimZoom();
unit.userData.useAim = false;
}
},
},
],
};
241 changes: 0 additions & 241 deletions src/js/newkrok/three-tps/control/unit-action-manager.js

This file was deleted.

Loading

0 comments on commit 021281e

Please sign in to comment.