Skip to content

Commit

Permalink
Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Dec 2, 2022
1 parent 340afdf commit 7359d2f
Show file tree
Hide file tree
Showing 40 changed files with 492 additions and 433 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@ List of features:
* it works through gamepad cores, that specify how the buttons are activated (keyboard, mouse, gamepads)
* example:
```js
PP.myLeftGamepad.registerButtonEventListener(PP.ButtonType.THUMBSTICK, PP.ButtonEvent.PRESS_START, this, this._thumbstickPressStart.bind(this));
PP.myRightGamepad.getButtonInfo(PP.ButtonType.TOP_BUTTON).isTouchEnd();
PP.myLeftGamepad.getButtonInfo(PP.ButtonType.SQUEEZE).isPressStart(2); // fast pressed 2 times
PP.myLeftGamepad.registerButtonEventListener(PP.GamepadButtonID.THUMBSTICK, PP.ButtonEvent.PRESS_START, this, this._thumbstickPressStart.bind(this));
PP.myRightGamepad.getButtonInfo(PP.GamepadButtonID.TOP_BUTTON).isTouchEnd();
PP.myLeftGamepad.getButtonInfo(PP.GamepadButtonID.SQUEEZE).isPressStart(2); // fast pressed 2 times
PP.myGamepads[PP.Handedness.LEFT].getAxesInfo().getAxes();
PP.myRightGamepad.pulse(0.5, 1);
```
- [`Gamepad Buttons`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_buttons.js)
* here u can find the enums for the buttons and axes types and events and the classes the contains the buttons and axes infos
* here u can find the enums for the buttons and axes ids and events and the classes the contains the buttons and axes infos
- [`PP.GamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/gamepad_core.js)
* the base class that u can inherit to create a custom gamepad core that u can then plug into the universal gamepad
- [`PP.XRGamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/xr_gamepad_core.js) / [`PP.KeyboardGamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/keyboard_gamepad_core.js)
Expand Down
8 changes: 4 additions & 4 deletions wle_pp/wle_pp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@ List of features:
* it works through gamepad cores, that specify how the buttons are activated (keyboard, mouse, gamepads)
* example:
```js
PP.myLeftGamepad.registerButtonEventListener(PP.ButtonType.THUMBSTICK, PP.ButtonEvent.PRESS_START, this, this._thumbstickPressStart.bind(this));
PP.myRightGamepad.getButtonInfo(PP.ButtonType.TOP_BUTTON).isTouchEnd();
PP.myLeftGamepad.getButtonInfo(PP.ButtonType.SQUEEZE).isPressStart(2); // fast pressed 2 times
PP.myLeftGamepad.registerButtonEventListener(PP.GamepadButtonID.THUMBSTICK, PP.ButtonEvent.PRESS_START, this, this._thumbstickPressStart.bind(this));
PP.myRightGamepad.getButtonInfo(PP.GamepadButtonID.TOP_BUTTON).isTouchEnd();
PP.myLeftGamepad.getButtonInfo(PP.GamepadButtonID.SQUEEZE).isPressStart(2); // fast pressed 2 times
PP.myGamepads[PP.Handedness.LEFT].getAxesInfo().getAxes();
PP.myRightGamepad.pulse(0.5, 1);
```
- [`Gamepad Buttons`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_buttons.js)
* here u can find the enums for the buttons and axes types and events and the classes the contains the buttons and axes infos
* here u can find the enums for the buttons and axes ids and events and the classes the contains the buttons and axes infos
- [`PP.GamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/gamepad_core.js)
* the base class that u can inherit to create a custom gamepad core that u can then plug into the universal gamepad
- [`PP.XRGamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/xr_gamepad_core.js) / [`PP.KeyboardGamepadCore`](https://github.com/SignorPipo/wle_pp/blob/main/wle_pp/wle_pp_bundler/js/pp/input/gamepad/gamepad_cores/keyboard_gamepad_core.js)
Expand Down
62 changes: 31 additions & 31 deletions wle_pp/wle_pp/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
Loading

0 comments on commit 7359d2f

Please sign in to comment.