Skip to content

Commit

Permalink
v1.2.0 drop deprecated categoryMask, register mixin (#8)
Browse files Browse the repository at this point in the history
* dont register mixin automatically

* update docs

* remove deprecated category mask

* package-lock-json
  • Loading branch information
reececomo authored Apr 26, 2024
1 parent bc1c8fa commit 690de91
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 64 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,32 @@ npm install pixijs-actions
yarn add pixijs-actions
```

2. Import `pixijs-actions` somewhere in your application. The DisplayObject mixin and its types are automatically registered when you import the library.
2. Register the DisplayObject mixin:

3. Register the global ticker with your PixiJS app (or other render loop):
```ts
import * as PIXI from 'pixi.js';
import { registerDisplayObjectMixin } from 'pixijs-actions';

registerDisplayObjectMixin(PIXI.DisplayObject);
```

2. Register the `registerDisplayObjectMixin()` mixin and ticker with your PixiJS app (or other render loop):

```ts
import { Action } from 'pixijs-actions';
import * as PIXI from 'pixi.js';
import { Action, registerDisplayObjectMixin } from 'pixijs-actions';

const myApp = new PIXI.Application({ ... });
// Register the Actions mixin
registerDisplayObjectMixin(PIXI.DisplayObject);

// PixiJS v8:
myApp.ticker.add(ticker => Action.tick(ticker.deltaTime));
const myApp = new PIXI.Application({ ... });

// or PixiJS v6 + v7:
myApp.ticker.add(dt => Action.tick(dt));
// Tick actions
myApp.ticker.add(ticker => Action.tick(ticker.deltaTime)); // PixiJS v8
myApp.ticker.add(dt => Action.tick(dt)); // PixiJS v6 + v7
```

Now you are ready to start using actions!
Now you can add your first action!

## Action Initializers

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixijs-actions",
"version": "1.1.7",
"version": "1.2.0",
"author": "Reece Como <[email protected]>",
"authors": [
"Reece Como <[email protected]>",
Expand Down
13 changes: 4 additions & 9 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,10 @@ export abstract class _ extends Action {
* Tick all actions forward.
*
* @param deltaTimeMs Delta time in milliseconds.
* @param categoryMask (Optional) Bitmask to filter which categories of actions to update.
* @param onErrorHandler (Optional) Handler errors from each action's tick.
*/
public static tick(
deltaTimeMs: number,
categoryMask: number | undefined = undefined,
onErrorHandler?: (error: any) => void
): void {
ActionTicker.tickAll(deltaTimeMs, categoryMask, onErrorHandler);
* @param onErrorHandler Handle action errors.
*/
public static tick(deltaTimeMs: number, onErrorHandler?: (error: any) => void): void {
ActionTicker.tickAll(deltaTimeMs, onErrorHandler);
}

//
Expand Down
7 changes: 4 additions & 3 deletions src/DisplayObject.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export function registerDisplayObjectMixin(displayObject: any): void {
prototype.isPaused = false;

// - Methods:
prototype.run = function (_action: Action, completion?: () => void): void {
const action = completion ? Action.sequence([_action, Action.run(completion)]) : _action;
ActionTicker.runAction(undefined, this, action);
prototype.run = function (action: Action, completion?: () => void): void {
return completion
? ActionTicker.runAction(undefined, this, Action.sequence([action, Action.run(completion)]))
: ActionTicker.runAction(undefined, this, action);
};

prototype.runWithKey = function (action: Action, key: string): void {
Expand Down
8 changes: 3 additions & 5 deletions src/__tests__/Action.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Container, Sprite } from 'pixi.js';
import { Action, TimingMode } from '../index';
import { Container, DisplayObject, Sprite } from 'pixi.js';
import { Action, TimingMode, registerDisplayObjectMixin } from '../index';
// import { registerDisplayObjectMixin } from '../DisplayObject.mixin';

function simulateTime(seconds: number, steps: number = 100): void {
Expand All @@ -12,7 +12,7 @@ function simulateTime(seconds: number, steps: number = 100): void {
}

/** Load the DisplayObject mixin first. */
// beforeAll(() => registerDisplayObjectMixin(DisplayObject));
beforeAll(() => registerDisplayObjectMixin(DisplayObject));

describe('DefaultTimingMode static properties', () => {
it('should reflect the DefaultTimingModeEaseInOut on the root Action type', () => {
Expand Down Expand Up @@ -255,10 +255,8 @@ describe('Action Chaining', () => {
});

it('should work with repeatForever()', () => {
let i = 0;
const myCustomAction = Action.customAction(5.0, (target, t) => {
target.position.x = 5.0 * t;
i++;
});

const myNode = new Container();
Expand Down
8 changes: 0 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import * as PIXI from 'pixi.js';

import { _ as Action } from "./Action";
import { TimingMode, TimingModeFn } from "./TimingMode";
import { registerDisplayObjectMixin } from './DisplayObject.mixin';

//
// ----- [Side-effect] Initialize DisplayObject mixin: -----
//

registerDisplayObjectMixin(PIXI.DisplayObject);

//
// ----- PixiJS Actions library: -----
//
Expand Down
15 changes: 0 additions & 15 deletions src/lib/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export abstract class Action {
public speed: number = 1,
/** A setting that controls the speed curve of an animation. */
public timingMode: TimingModeFn = TimingMode.linear,
/** @deprecated A global category bitmask which can be used to group actions. */
public categoryMask: number = 0x1,
) {
if (duration < 0) {
throw new RangeError('Action duration must be 0 or more.');
Expand All @@ -33,19 +31,6 @@ export abstract class Action {
return this.duration / this.speed;
}

/**
* @deprecated To be removed soon. Modify node and action speed directly instead.
*
* Set a category mask for this action.
* Use this to tick different categories of actions separately (e.g. separate different UI).
*
* This function mutates the underlying action.
*/
public setCategory(categoryMask: number): this {
this.categoryMask = categoryMask;
return this;
}

/**
* Set the action's speed scale. Default: `1.0`.
*
Expand Down
15 changes: 3 additions & 12 deletions src/lib/ActionTicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ export class ActionTicker {
* Tick all actions forward.
*
* @param deltaTimeMs Delta time given in milliseconds.
* @param categoryMask (Optional) Bitmask to filter which categories of actions to update.
* @param onErrorHandler (Optional) Handler errors from each action's tick.
* @param onErrorHandler Handle action errors.
*/
public static tickAll(
deltaTimeMs: number,
categoryMask: number | undefined = undefined,
onErrorHandler?: (error: any) => void
): void {
public static tickAll(deltaTimeMs: number, onErrorHandler?: (error: any) => void): void {
const deltaTime = deltaTimeMs * 0.001;

for (const [target, tickers] of this._tickers.entries()) {
Expand All @@ -39,15 +34,11 @@ export class ActionTicker {
}

for (const actionTicker of tickers.values()) {
if (categoryMask !== undefined && (categoryMask & actionTicker.action.categoryMask) === 0) {
continue;
}

try {
actionTicker.tick(deltaTime * speed);
}
catch (error) {
// Isolate individual action errors.
// Report individual action errors.
if (onErrorHandler === undefined) {
console.error('Action failed with error: ', error);
}
Expand Down

0 comments on commit 690de91

Please sign in to comment.