Skip to content

Commit

Permalink
Type to ID
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Dec 2, 2022
1 parent baf8242 commit 340afdf
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 344 deletions.
62 changes: 31 additions & 31 deletions wle_pp/wle_pp_bundler/js/pp/cauldron/fsm/fsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ PP.PendingPerform = class PendingPerform {
}
};

PP.PerformType = {
PP.PerformMode = {
IMMEDIATE: 0,
DELAYED: 1
};

PP.PerformDelayedType = {
PP.PerformDelayedMode = {
QUEUE: 0,
KEEP_FIRST: 1,
KEEP_LAST: 2
Expand All @@ -51,7 +51,7 @@ PP.SkipStateFunction = {

PP.FSM = class FSM {

constructor(performType = PP.PerformType.IMMEDIATE, performDelayedType = PP.PerformDelayedType.QUEUE) {
constructor(performMode = PP.PerformMode.IMMEDIATE, performDelayedMode = PP.PerformDelayedMode.QUEUE) {
this._myCurrentStateData = null;

this._myStateMap = new Map();
Expand All @@ -61,15 +61,15 @@ PP.FSM = class FSM {
this._myDebugShowDelayedInfo = false;
this._myDebugLogName = "FSM";

this._myPerformType = performType;
this._myPerformDelayedType = performDelayedType;
this._myPerformMode = performMode;
this._myPerformDelayedMode = performDelayedMode;
this._myPendingPerforms = [];
this._myCurrentlyPerformedTransition = null;

this._myInitCallbacks = new Map(); // Signature: callback(fsm, initStateData, initTransitionObject, ...args)
this._myInitIDCallbacks = new Map(); // Signature: callback(fsm, initStateData, initTransitionObject, ...args)
this._myTransitionCallbacks = new Map(); // Signature: callback(fsm, fromStateData, toStateData, transitionData, performType, ...args)
this._myTransitionIDCallbacks = []; // Signature: callback(fsm, fromStateData, toStateData, transitionData, performType, ...args)
this._myTransitionCallbacks = new Map(); // Signature: callback(fsm, fromStateData, toStateData, transitionData, performMode, ...args)
this._myTransitionIDCallbacks = []; // Signature: callback(fsm, fromStateData, toStateData, transitionData, performMode, ...args)
}

addState(stateID, state = null) {
Expand Down Expand Up @@ -171,7 +171,7 @@ PP.FSM = class FSM {
update(dt, ...args) {
if (this._myPendingPerforms.length > 0) {
for (let i = 0; i < this._myPendingPerforms.length; i++) {
this._perform(this._myPendingPerforms[i].myID, PP.PerformType.DELAYED, ...this._myPendingPerforms[i].myArgs);
this._perform(this._myPendingPerforms[i].myID, PP.PerformMode.DELAYED, ...this._myPendingPerforms[i].myArgs);
}
this._myPendingPerforms = [];
}
Expand All @@ -182,7 +182,7 @@ PP.FSM = class FSM {
}

perform(transitionID, ...args) {
if (this._myPerformType == PP.PerformType.DELAYED) {
if (this._myPerformMode == PP.PerformMode.DELAYED) {
this.performDelayed(transitionID, ...args);
} else {
this.performImmediate(transitionID, ...args);
Expand All @@ -192,18 +192,18 @@ PP.FSM = class FSM {
performDelayed(transitionID, ...args) {
let performDelayed = false;

switch (this._myPerformDelayedType) {
case PP.PerformDelayedType.QUEUE:
switch (this._myPerformDelayedMode) {
case PP.PerformDelayedMode.QUEUE:
this._myPendingPerforms.push(new PP.PendingPerform(transitionID, ...args));
performDelayed = true;
break;
case PP.PerformDelayedType.KEEP_FIRST:
case PP.PerformDelayedMode.KEEP_FIRST:
if (!this.hasPendingPerforms()) {
this._myPendingPerforms.push(new PP.PendingPerform(transitionID, ...args));
performDelayed = true;
}
break;
case PP.PerformDelayedType.KEEP_LAST:
case PP.PerformDelayedMode.KEEP_LAST:
this.resetPendingPerforms();
this._myPendingPerforms.push(new PP.PendingPerform(transitionID, ...args));
performDelayed = true;
Expand All @@ -214,7 +214,7 @@ PP.FSM = class FSM {
}

performImmediate(transitionID, ...args) {
return this._perform(transitionID, PP.PerformType.IMMEDIATE, ...args);
return this._perform(transitionID, PP.PerformMode.IMMEDIATE, ...args);
}

canPerform(transitionID) {
Expand Down Expand Up @@ -367,20 +367,20 @@ PP.FSM = class FSM {
return hasTransition;
}

setPerformType(performType) {
this._myPerformType = performType;
setPerformMode(performMode) {
this._myPerformMode = performMode;
}

getPerformType() {
return this._myPerformType;
getPerformMode() {
return this._myPerformMode;
}

setPerformDelayedType(performDelayedType) {
this._myPerformDelayedType = performDelayedType;
setPerformDelayedMode(performDelayedMode) {
this._myPerformDelayedMode = performDelayedMode;
}

getPerformDelayedType() {
return this._myPerformDelayedType;
getPerformDelayedMode() {
return this._myPerformDelayedMode;
}

hasPendingPerforms() {
Expand All @@ -402,8 +402,8 @@ PP.FSM = class FSM {
cloneFSM._myDebugShowDelayedInfo = this._myDebugShowDelayedInfo;
cloneFSM._myDebugLogName = this._myDebugLogName.slice(0);

cloneFSM._myPerformType = this._myPerformType;
cloneFSM._myPerformDelayedType = this._myPerformDelayedType;
cloneFSM._myPerformMode = this._myPerformMode;
cloneFSM._myPerformDelayedMode = this._myPerformDelayedMode;
cloneFSM._myPendingPerforms = this._myPendingPerforms.slice(0);

for (let entry of this._myStateMap.entries()) {
Expand Down Expand Up @@ -554,12 +554,12 @@ PP.FSM = class FSM {
}
}

_perform(transitionID, performType, ...args) {
_perform(transitionID, performMode, ...args) {
if (this.isPerformingTransition()) {
let currentlyPerformedTransition = this.getCurrentlyPerformedTransition();
let consoleArguments = [this._myDebugLogName, "- Trying to perform:", transitionID];
if (this._myDebugShowDelayedInfo) {
consoleArguments.push(performType == PP.PerformType.DELAYED ? "- Delayed" : "- Immediate");
consoleArguments.push(performMode == PP.PerformMode.DELAYED ? "- Delayed" : "- Immediate");
}
consoleArguments.push("- But another transition is currently being performed -", currentlyPerformedTransition.myID);
console.warn(...consoleArguments);
Expand All @@ -580,7 +580,7 @@ PP.FSM = class FSM {
if (this._myDebugLogActive) {
let consoleArguments = [this._myDebugLogName, "- From:", fromState.myID, "- To:", toState.myID, "- With:", transitionID];
if (this._myDebugShowDelayedInfo) {
consoleArguments.push(performType == PP.PerformType.DELAYED ? "- Delayed" : "- Immediate");
consoleArguments.push(performMode == PP.PerformMode.DELAYED ? "- Delayed" : "- Immediate");
}
console.log(...consoleArguments);
}
Expand All @@ -602,7 +602,7 @@ PP.FSM = class FSM {
this._myCurrentStateData = transitionToPerform.myToState;

if (this._myTransitionCallbacks.size > 0) {
this._myTransitionCallbacks.forEach(function (callback) { callback(this, fromState, toState, transitionToPerform, performType, ...args); }.bind(this));
this._myTransitionCallbacks.forEach(function (callback) { callback(this, fromState, toState, transitionToPerform, performMode, ...args); }.bind(this));
}

if (this._myTransitionIDCallbacks.length > 0) {
Expand All @@ -616,7 +616,7 @@ PP.FSM = class FSM {
}

for (let callbackMap of this.transitionIDMaps) {
callbackMap.forEach(function (callback) { callback(this, fromState, toState, transitionToPerform, performType, ...args); }.bind(this));
callbackMap.forEach(function (callback) { callback(this, fromState, toState, transitionToPerform, performMode, ...args); }.bind(this));
}
}

Expand All @@ -626,14 +626,14 @@ PP.FSM = class FSM {
} else if (this._myDebugLogActive) {
let consoleArguments = [this._myDebugLogName, "- No Transition:", transitionID, "- From:", this._myCurrentStateData.myID];
if (this._myDebugShowDelayedInfo) {
consoleArguments.push(performType == PP.PerformType.DELAYED ? "- Delayed" : "- Immediate");
consoleArguments.push(performMode == PP.PerformMode.DELAYED ? "- Delayed" : "- Immediate");
}
console.warn(...consoleArguments);
}
} else if (this._myDebugLogActive) {
let consoleArguments = [this._myDebugLogName, "- FSM not initialized yet"];
if (this._myDebugShowDelayedInfo) {
consoleArguments.push(performType == PP.PerformType.DELAYED ? "- Delayed" : "- Immediate");
consoleArguments.push(performMode == PP.PerformMode.DELAYED ? "- Delayed" : "- Immediate");
}
console.warn(...consoleArguments);
}
Expand Down
32 changes: 16 additions & 16 deletions wle_pp/wle_pp_bundler/js/pp/gameplay/grab_throw/grabber_hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ WL.registerComponent('pp-grabber-hand', {
}

if (this._myGrabButton == 0) {
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonType.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonType.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonID.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonID.SELECT));
} else if (this._myGrabButton == 1) {
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonType.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonType.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonID.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonID.SQUEEZE));
} else {
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonType.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonType.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonID.SQUEEZE));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonID.SQUEEZE));

this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonType.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonType.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_START, this, this._grab.bind(this, PP.GamepadButtonID.SELECT));
this._myGamepad.registerButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_END, this, this._throw.bind(this, PP.GamepadButtonID.SELECT));
}
},
onDeactivate() {
Expand All @@ -100,17 +100,17 @@ WL.registerComponent('pp-grabber-hand', {
}

if (this._myGrabButton == 0) {
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_END, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_END, this);
} else if (this._myGrabButton == 1) {
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this);
} else {
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SQUEEZE, PP.GamepadButtonEvent.PRESS_END, this);

this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonType.SELECT, PP.GamepadButtonEvent.PRESS_END, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_START, this);
this._myGamepad.unregisterButtonEventListener(PP.GamepadButtonID.SELECT, PP.GamepadButtonEvent.PRESS_END, this);
}
},
_grab: function (grabButton) {
Expand Down
4 changes: 2 additions & 2 deletions wle_pp/wle_pp_bundler/js/pp/input/cauldron/input_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PP.InputSourceType = {
TRACKED_HAND: 1
};

PP.TrackedHandJointType = {
PP.TrackedHandJointID = {
WRIST: "wrist",

THUMB_METACARPAL: "thumb-metacarpal",
Expand Down Expand Up @@ -47,7 +47,7 @@ PP.TrackedHandJointType = {
PINKY_FINGER_TIP: "pinky-finger-tip",
};

PP.TrackedHandJointTypeIndex = {
PP.TrackedHandJointIDIndex = {
WRIST: 0,

THUMB_METACARPAL: 1,
Expand Down
18 changes: 9 additions & 9 deletions wle_pp/wle_pp_bundler/js/pp/input/cauldron/input_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ PP.InputUtils = {

return oppositeHandedness;
},
getJointTypeByIndex: function (index) {
let jointType = null;
getJointIDByIndex: function (index) {
let jointID = null;

let jointTypeKey = null;
for (let jointTypeIndexKey in PP.TrackedHandJointTypeIndex) {
if (PP.TrackedHandJointTypeIndex[jointTypeIndexKey] == index) {
jointTypeKey = jointTypeIndexKey;
let jointIDKey = null;
for (let jointIDIndexKey in PP.TrackedHandJointIDIndex) {
if (PP.TrackedHandJointIDIndex[jointIDIndexKey] == index) {
jointIDKey = jointIDIndexKey;
break;
}
}

if (jointTypeKey != null) {
jointType = PP.TrackedHandJointType[jointTypeKey];
if (jointIDKey != null) {
jointID = PP.TrackedHandJointID[jointIDKey];
}

return jointType;
return jointID;
},
};
34 changes: 17 additions & 17 deletions wle_pp/wle_pp_bundler/js/pp/input/cauldron/keyboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PP.KeyType = {
PP.KeyID = {
_0: "0",
_1: "1",
_2: "2",
Expand Down Expand Up @@ -86,43 +86,43 @@ PP.Keyboard = class Keyboard {
constructor() {
this._myKeyInfos = new Map();

for (let keyType in PP.KeyType) {
this.addKey(PP.KeyType[keyType]);
for (let key in PP.KeyID) {
this.addKey(PP.KeyID[key]);
}
}

isKeyPressed(keyType) {
isKeyPressed(KeyID) {
let isPressed = false;

if (this._myKeyInfos.has(keyType)) {
isPressed = this._myKeyInfos.get(keyType).myIsPressed;
if (this._myKeyInfos.has(KeyID)) {
isPressed = this._myKeyInfos.get(KeyID).myIsPressed;
}

return isPressed;
}

isKeyPressStart(keyType) {
isKeyPressStart(KeyID) {
let isPressStart = false;

if (this._myKeyInfos.has(keyType)) {
isPressStart = this._myKeyInfos.get(keyType).myIsPressStart;
if (this._myKeyInfos.has(KeyID)) {
isPressStart = this._myKeyInfos.get(KeyID).myIsPressStart;
}

return isPressStart;
}

isKeyPressEnd(keyType) {
isKeyPressEnd(KeyID) {
let isPressEnd = false;

if (this._myKeyInfos.has(keyType)) {
isPressEnd = this._myKeyInfos.get(keyType).myIsPressEnd;
if (this._myKeyInfos.has(KeyID)) {
isPressEnd = this._myKeyInfos.get(KeyID).myIsPressEnd;
}

return isPressEnd;
}

addKey(keyType) {
this._myKeyInfos.set(keyType,
addKey(KeyID) {
this._myKeyInfos.set(KeyID,
{ myIsPressed: false, myIsPressStart: false, myIsPressStartToProcess: false, myIsPressEnd: false, myIsPressEndToProcess: false, });
}

Expand Down Expand Up @@ -163,9 +163,9 @@ PP.Keyboard = class Keyboard {
}
}

_keyPressedChanged(keyType, isPressed) {
if (this._myKeyInfos.has(keyType)) {
let keyInfo = this._myKeyInfos.get(keyType);
_keyPressedChanged(KeyID, isPressed) {
if (this._myKeyInfos.has(KeyID)) {
let keyInfo = this._myKeyInfos.get(KeyID);

if (isPressed) {
keyInfo.myIsPressed = true;
Expand Down
Loading

0 comments on commit 340afdf

Please sign in to comment.