Skip to content

WIP: Prepare package for generic display list #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coverage
dist/lib
dist-test
lib
lib-example
lib-test
node_modules
*.as
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Usage
---

```typescript
/// <reference path="node_modules/@robotlegsjs/createjs/definitions/createjs.d.ts" />

import "reflect-metadata";

import { Context, MVCSBundle } from "@robotlegsjs/core";

import { ContextView, CreateJSBundle } from "@robotlegsjs/createjs";
Expand Down
17 changes: 17 additions & 0 deletions definitions/createjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

/**
* Augment CreateJS module to recognize EventDispatcher patch.
*/
declare namespace createjs {
interface IEventDispatcher {
once(type: string, listener: Function, thisObject?: any, useCapture?: boolean, priority?: number): void;
}

export interface EventDispatcher extends IEventDispatcher {}
}
4 changes: 4 additions & 0 deletions example/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

/// <reference path="../definitions/createjs.d.ts" />

import "reflect-metadata";

import { Context, MVCSBundle } from "@robotlegsjs/core";

import { ContextView, CreateJSBundle } from "../src";
Expand Down
2 changes: 0 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import "reflect-metadata";

import { Game } from "./Game";

(<any>window).initGame = () => {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions example/view/RobotlegsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class RobotlegsView extends createjs.Container {
super();

this.loadLogo();
this.enable();
}

private loadLogo(): void {
Expand All @@ -36,8 +37,11 @@ export class RobotlegsView extends createjs.Container {
graphics.drawRect(bitmap.x, bitmap.y, logo.width, logo.height);

this.hitArea = area;
}

private enable(): void {
this.mouseEnabled = true;
this.mouseChildren = false;
this.cursor = "pointer";
}
}
7 changes: 7 additions & 0 deletions example/view/SmileyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SmileyView extends createjs.Container {

this.drawSmiley();
this.move();
this.enable();
}

private drawSmiley(): void {
Expand Down Expand Up @@ -54,4 +55,10 @@ export class SmileyView extends createjs.Container {
this.y = Math.max(this.y, this._radius);
this.y = Math.min(this.y, 400 - this._radius);
}

private enable(): void {
this.mouseEnabled = true;
this.mouseChildren = false;
this.cursor = "pointer";
}
}
6 changes: 5 additions & 1 deletion src/robotlegs/bender/bundles/createjs/CreateJSBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { StageCrawlerExtension } from "../../extensions/viewManager/StageCrawler
import { StageObserverExtension } from "../../extensions/viewManager/StageObserverExtension";
import { ViewManagerExtension } from "../../extensions/viewManager/ViewManagerExtension";

import { applyCreateJSPatch } from "./patch/createjs-patch";

/**
* For that Classic Robotlegs flavour
*
Expand Down Expand Up @@ -59,7 +61,9 @@ export class CreateJSBundle implements IBundle {
/* Private Functions */
/*============================================================================*/

private handleContextView(): void {
private handleContextView(contextView: ContextView): void {
applyCreateJSPatch(<any>contextView.view);

this._context.configure(ContextViewListenerConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@
* - emit "added"/"removed" events on stage
*/

import "./eventDispatcher-patch";

import { Event } from "@robotlegsjs/core";

function isConnectedToStage(stage: createjs.Stage, displayObject: createjs.DisplayObject): boolean {
return displayObject.stage === stage;
}

function emitAddedEvent(stage: createjs.Stage, target: createjs.DisplayObject): void {
let event: createjs.Event = new createjs.Event("added", true, false);
let event: Event = new Event("addedToStage", true);

event.data = target;

stage.dispatchEvent(event);
target.dispatchEvent(event);

if (target instanceof createjs.Container) {
target.children.forEach(child => emitAddedEvent(stage, child));
}
}

function emitRemovedEvent(stage: createjs.Stage, target: createjs.DisplayObject): void {
let event: createjs.Event = new createjs.Event("removed", true, false);
let event: Event = new Event("removedFromStage", true);

event.data = target;

stage.dispatchEvent(event);
target.dispatchEvent(event);

if (target instanceof createjs.Container) {
target.children.forEach(child => emitRemovedEvent(stage, child));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

/**
* Patch PIXI event handling.
*
* - Proxy PIXI events to be compatible with EventDispatcher
* - Implements event bubbling on `dispatchEvent` when `bubbles` is true.
*/

const EventDispatcherMixin = {
once(type: string, listener: Function, thisObject?: any, useCapture?: boolean, priority?: number): void {
this.on(type, listener, thisObject, true, null, useCapture);
}
};

Object.assign(createjs.EventDispatcher.prototype, EventDispatcherMixin);
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { instanceOfType, IContext, IExtension, IInjector, ILogger } from "@robot
import { IContextView } from "./api/IContextView";
import { ContextView } from "./impl/ContextView";

import { applyCreateJSPatch } from "./createjsPatch/createjs-patch";

/**
* <p>This Extension waits for a ContextView to be added as a configuration
* and maps it into the context's injector.</p>
Expand Down Expand Up @@ -51,8 +49,6 @@ export class ContextViewExtension implements IExtension {
} else {
this._logger.debug("Mapping {0} as contextView", [contextView.view]);

applyCreateJSPatch(contextView.view);

this._injector.bind(IContextView).toConstantValue(contextView);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { IDisplayObjectContainer } from "./IDisplayObjectContainer";

export let IContextView = Symbol("IContextView");
export interface IContextView {
view: createjs.Stage;
view: IDisplayObjectContainer;
}
15 changes: 15 additions & 0 deletions src/robotlegs/bender/extensions/contextView/api/IDisplayObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { IEventDispatcher } from "@robotlegsjs/core";

import { IDisplayObjectContainer } from "./IDisplayObjectContainer";

export let IDisplayObject = Symbol("IDisplayObject");
export interface IDisplayObject extends IEventDispatcher {
parent: IDisplayObjectContainer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { IDisplayObject } from "./IDisplayObject";

export let IDisplayObjectContainer = Symbol("IDisplayObjectContainer");
export interface IDisplayObjectContainer extends IDisplayObject {
children: IDisplayObject[];

contains(child: IDisplayObject): boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import { IConfig } from "@robotlegsjs/core";

import { IContextView } from "../api/IContextView";
import { IDisplayObjectContainer } from "../api/IDisplayObjectContainer";

/**
* The Context View represents the root Container for a Context
*/
export class ContextView implements IContextView, IConfig {
private _view: createjs.Stage;
private _view: IDisplayObjectContainer;

/*============================================================================*/
/* Constructor */
Expand All @@ -23,7 +24,7 @@ export class ContextView implements IContextView, IConfig {
* The Context View represents the root Container for a Context
* @param view The root Container for this Context
*/
constructor(view: createjs.Stage) {
constructor(view: IDisplayObjectContainer) {
if (view !== null && view !== undefined) {
this._view = view;
} else {
Expand All @@ -43,7 +44,7 @@ export class ContextView implements IContextView, IConfig {
/**
* The root Container for this Context
*/
public get view(): createjs.Stage {
public get view(): IDisplayObjectContainer {
return this._view;
}
}

This file was deleted.

Loading