Skip to content

Commit

Permalink
Update to 0.3.1, add event listener on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kefniark committed Jun 29, 2017
1 parent 63d5d80 commit 4cfcf82
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 54 deletions.
42 changes: 22 additions & 20 deletions build/fatina.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Generated by dts-bundle v0.7.2
// Generated by dts-bundle v0.7.3

export let plugin: any;
export { EasingType as Easing };
export let time: number;
export function Elapsed(): number;
export function MainTicker(): ITicker;
export function AddListenerCreated(cb: (control: IControl) => void): void;
export function RemoveListenerCreated(cb: (control: IControl) => void): void;
export function Init(disableAutoTick?: boolean): boolean;
export function SetTimescale(scale: number): void;
export function Pause(): void;
Expand All @@ -22,9 +24,25 @@ export function Ticker(): ITicker;
export function LoadPlugin(newPlugin: IPlugin): void;

export enum Log {
None = 0,
Info = 1,
Debug = 2,
None = "none",
Info = "info",
Debug = "debug",
}

export interface IControl {
elapsed: number;
duration: number;
state: State;
Start(): void;
Pause(): void;
Resume(): void;
Kill(): void;
Reset(): void;
Skip(finalValue?: boolean): void;
IsIdle(): boolean;
IsRunning(): boolean;
IsFinished(): boolean;
IsPaused(): boolean;
}

export interface IPlayable extends IControl {
Expand Down Expand Up @@ -143,19 +161,3 @@ export enum State {
Killed = 4,
}

export interface IControl {
elapsed: number;
duration: number;
state: State;
Start(): void;
Pause(): void;
Resume(): void;
Kill(): void;
Reset(): void;
Skip(finalValue?: boolean): void;
IsIdle(): boolean;
IsRunning(): boolean;
IsFinished(): boolean;
IsPaused(): boolean;
}

50 changes: 41 additions & 9 deletions build/fatina.js

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

2 changes: 1 addition & 1 deletion build/fatina.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/fatina.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/fatina.min.js.map

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fatina",
"description": "Small & Light tweening library for web / games",
"version": "0.3.0",
"version": "0.3.1",
"homepage": "https://kefniark.github.io/Fatina/",
"main": "build/fatina.min.js",
"types": "build/fatina.d.ts",
Expand Down Expand Up @@ -46,20 +46,20 @@
"coveralls": "nyc --all --reporter=text-lcov npm run test:unittest | coveralls"
},
"devDependencies": {
"@types/node": "^8.0.1",
"@types/tape": "^4.2.30",
"@types/node": "8.0.5",
"@types/tape": "4.2.30",
"coveralls": "2.13.1",
"dts-bundle": "0.7.2",
"dts-bundle": "0.7.3",
"npm-run-all": "4.0.2",
"nyc": "^11.0.2",
"nyc": "11.0.3",
"rimraf": "2.6.1",
"tap-spec": "4.1.1",
"tape": "^4.6.3",
"ts-loader": "^2.2.0",
"ts-node": "^3.1.0",
"tslint": "^5.4.3",
"typedoc": "^0.7.1",
"typescript": "^2.4.0",
"tape": "4.7.0",
"ts-loader": "2.2.1",
"ts-node": "3.1.0",
"tslint": "5.4.3",
"typedoc": "0.7.1",
"typescript": "2.4.1",
"webpack": "3.0.0"
},
"nyc": {
Expand Down
12 changes: 9 additions & 3 deletions src/fatina/core/enum/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* Enum use to set the verbosity level of fatina and tweens
*
* @export
* @enum {number}
*/
export enum Log {
None,
Info,
Debug
None = 'none',
Info = 'info',
Debug = 'debug'
}
46 changes: 46 additions & 0 deletions src/fatina/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Log } from './core/enum/log';
import { IControl } from './core/interfaces/IControl';
import { IPlayable } from './core/interfaces/IPlayable';
import { IPlugin } from './core/interfaces/IPlugin';
import { ISequence } from './core/interfaces/ISequence';
Expand All @@ -17,6 +18,7 @@ let lastFrame: any;
let lastTime = 0;
let logLevel = Log.None;
let safe = true;
const eventCreated: {(control: IControl): void}[] = [];

const loadedPlugins: IPlugin[] = [];

Expand All @@ -41,6 +43,29 @@ export function MainTicker(): ITicker {
return tickerManager;
}

/**
* Add a listener method on tween/sequence creation
*
* @export
* @param {(control: IControl) => void} cb
*/
export function AddListenerCreated(cb: (control: IControl) => void): void {
eventCreated.push(cb);
}

/**
* Remove a listener method on tween/sequence creation
*
* @export
* @param {(control: IControl) => void} cb
*/
export function RemoveListenerCreated(cb: (control: IControl) => void): void {
const index = eventCreated.indexOf(cb);
if (index !== -1) {
eventCreated.splice(index, 1);
}
}

/**
* Method used when Fatina is used for the first time.
* Can take few ms. (pool initialization & object creation)
Expand Down Expand Up @@ -250,6 +275,8 @@ function AddContext(obj: IPlayable | ITween | ISequence): void {
if (!safe) {
obj.SetSafe(safe);
}

EmitCreated(obj);
}

/**
Expand All @@ -271,6 +298,7 @@ export function Ticker(): ITicker {
tickerManager.AddTickListener(handler);
tick.Start();

EmitCreated(tick);
Info(Log.Debug, '[Fatina.Manager] Ticker Instantiated', tick);
return tick;
}
Expand Down Expand Up @@ -298,6 +326,24 @@ function Info(level: Log, message: string, data?: any) {
}
}

function Emit(func: any, tween: IControl) {
if (!safe) {
return func(tween);
}

try {
func(tween);
} catch (e) {
console.warn(e);
}
}

function EmitCreated(tween: IControl) {
for (let i = 0; i < eventCreated.length; i++) {
Emit(eventCreated[i], tween);
}
}

/**
* This part manage the auto-update loop if necessary (browser only)
*/
Expand Down
8 changes: 4 additions & 4 deletions src/fatina/tweens/baseTween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export abstract class BaseTween<T extends BaseTween<any>> {
this.eventStart = new Array(0);
}
this.eventStart[this.eventStart.length] = cb;
this.Info(Log.Debug, 'onStart', this);
this.Info(Log.Debug, 'onStart');
return this as any;
}

Expand All @@ -352,7 +352,7 @@ export abstract class BaseTween<T extends BaseTween<any>> {
this.eventRestart = new Array(0);
}
this.eventRestart[this.eventRestart.length] = cb;
this.Info(Log.Debug, 'onRestart', this);
this.Info(Log.Debug, 'onRestart');
return this as any;
}

Expand Down Expand Up @@ -385,7 +385,7 @@ export abstract class BaseTween<T extends BaseTween<any>> {
this.eventKill = new Array(0);
}
this.eventKill[this.eventKill.length] = cb;
this.Info(Log.Debug, 'onKilled', this);
this.Info(Log.Debug, 'onKilled');
return this as any;
}

Expand All @@ -402,7 +402,7 @@ export abstract class BaseTween<T extends BaseTween<any>> {
this.eventComplete = new Array(0);
}
this.eventComplete[this.eventComplete.length] = cb;
this.Info(Log.Debug, 'onComplete', this);
this.Info(Log.Debug, 'onComplete');
return this as any;
}
}
Loading

0 comments on commit 4cfcf82

Please sign in to comment.