Skip to content

Commit

Permalink
Merge pull request #24 from RobotlegsJS/context-view
Browse files Browse the repository at this point in the history
Use IContextView to get a reference of the stage
  • Loading branch information
tiagoschenkel authored Nov 20, 2017
2 parents 38c8c07 + 1a162de commit 8bff457
Show file tree
Hide file tree
Showing 20 changed files with 433 additions and 486 deletions.
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- Update README.

- Update @robotlegsjs/pixi to version 0.1.0 (see #17).
- Update @robotlegsjs/pixi to version 0.1.1 (see #17 and #24).

- Add Changelog (see #20).

Expand All @@ -28,25 +28,27 @@

- Add Pull Request Template (see #23).

- Use IContextView to get a reference of the stage (see #24).

- Update dev dependencies to latest version.

## RobotlegsJS-Pixi-Palidor 0.0.1

### [v0.0.6](https://github.com/RobotlegsJS/RobotlegsJS-Pixi/releases/tag/0.0.6) - 2017-10-18
### [v0.0.6](https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/releases/tag/0.0.6) - 2017-10-18

- Update @robotlegsjs/pixi to version 0.0.6 (see #14).

- Remove direct dependency of @robotlegsjs/core, since @robotlegsjs/pixi already have it as a direct dependency.

- Update dev dependencies to latest version.

### [v0.0.5](https://github.com/RobotlegsJS/RobotlegsJS-Pixi/releases/tag/0.0.5) - 2017-10-11
### [v0.0.5](https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/releases/tag/0.0.5) - 2017-10-11

- Update @robotlegsjs/pixi to version 0.0.5 (see #12).

- Update dev dependencies to latest version.

### [v0.0.4](https://github.com/RobotlegsJS/RobotlegsJS-Pixi/releases/tag/0.0.4) - 2017-09-26
### [v0.0.4](https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/releases/tag/0.0.4) - 2017-09-26

- Adapt to NPM [v5.0.0](http://blog.npmjs.org/post/161081169345/v500) (see #5).

Expand All @@ -58,7 +60,7 @@

- Update dev dependencies to latest version.

### [v0.0.3](https://github.com/RobotlegsJS/RobotlegsJS-Pixi/releases/tag/0.0.3) - 2017-09-15
### [v0.0.3](https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/releases/tag/0.0.3) - 2017-09-15

- Update @robotlegsjs/core to version 0.0.5 (see #2).

Expand All @@ -72,7 +74,7 @@

- Update dev dependencies to latest version.

### [v0.0.2](https://github.com/RobotlegsJS/RobotlegsJS-Pixi/releases/tag/0.0.2) - 2017-09-03
### [v0.0.2](https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/releases/tag/0.0.2) - 2017-09-03

- Add copyright.

Expand Down
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,51 @@ RobotlegsJS Pixi Palidor Extension
[![Greenkeeper badge](https://badges.greenkeeper.io/RobotlegsJS/RobotlegsJS-Pixi-Palidor.svg)](https://greenkeeper.io/)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

Palidor is an extension of RobotlegsJS for Pixi, designed to help the management of the Main Container, taking the responsibility to add, remove and, switch the views. Perfect for game development.
Palidor is an extension of RobotlegsJS for Pixi, designed to help the management of the Main Container, taking the responsibility to add, remove and switch the views. Perfect for game development.

Installation
===
---

You can get the latest release of Palidor and its dependencies using npm:
You can get the latest release and the type definitions using [NPM](https://www.npmjs.com/):

```bash
npm install @robotlegsjs/pixi-palidor
```
npm install @robotlegsjs/pixi-palidor @robotlegsjs/core @robotlegsjs/pixi pixi.js

Or using [Yarn](https://yarnpkg.com/en/):

```bash
yarn add @robotlegsjs/pixi-palidor
```
**Dependencies**

+ [RobotlegsJS](https://github.com/RobotlegsJS/RobotlegsJS)
+ [RobotlegsJS-Pixi](https://github.com/RobotlegsJS/RobotlegsJS-Pixi)
+ [PixiJS](https://www.pixijs.com/)
+ [PixiJS](https://github.com/pixijs/pixi.js)

Usage
===
Palidor was designed to be simple and, practical. You just need to follow three steps to start to use.

### Step 1 - Install/Configure

Firstly, you need to instantiate your RobotlegsJS's context, and then install and configure the PalidorPixiExtension and a PixiRootContainer.
Firstly, you need to instantiate your RobotlegsJS's context, and then install and configure the PalidorPixiExtension:

```ts
```typescript
let stage = new PIXI.Container();
let context = new Context()
.install(MVCSBundle)
.install(PixiBundle)
.install(PalidorPixiExtension)
.configure(new PixiRootContainer(this.stage))
.configure(PalidorConfig)
.configure(new ContextView(this.stage))
.configure(MyPalidorConfig)
.initialize();
```

+ **MVCSBundle:** Installs a number of extensions and configurations for developers who are comfortable with the typical [RobotlegsJS](https://github.com/RobotlegsJS/RobotlegsJS) setup.
+ **PixiBundle:** Installs a view / mediator layer provided by [RobotlegsJS-Pixi](https://github.com/RobotlegsJS/RobotlegsJS-Pixi).
+ **PalidorPixiExtension:** It is the extension itself.
+ **PixiRootContainer:** It is the class responsible for register the Main Container.
+ **PalidorConfig:** The Class that implements the Robotlegs's IConfig and will be responsible for map all Views and FloatingViews.
+ **MyPalidorConfig:** The Class that implements the Robotlegs's IConfig and will be responsible for map all your Views and FloatingViews.

### Step 2 - Mapping the Views/FloatingViews

Expand All @@ -58,7 +68,7 @@ Palidor splits the Main Container into two distinct Layers, one to each type of

The FlowManager will be the responsible to tells to Palidor each event mapped to each View.

```ts
```typescript
import { IFlowManager } from "@robotlegsjs/pixi-palidor";
import { IConfig, injectable, inject } from "@robotlegsjs/core";

Expand All @@ -76,9 +86,9 @@ export class MyPalidorConfig implements IConfig {

### Step 3 - Adding a View

The last part it is the way that Palidor will add the views on the stage, you just need to dispatcher an event using the IEventDispatcher which is available for Injection like any other Robotlegs Command.
The last part it is the way that Palidor will add the views on the stage, you just need to dispatch an event using the IEventDispatcher which is available for Injection like any other Robotlegs Command.

```ts
```typescript
this.eventDispatcher.dispatchEvent(new CustomEvent(CustomEvent.SHOW_FIRST_VIEW));
```

Expand All @@ -93,7 +103,6 @@ There are some predefined events on the Palidor to help to remove a view or flo
Examples
===


+ [Game - Battleship](https://github.com/RonaldoSetzer/GAME-Battleship)
+ [Game - Minesweeper](https://github.com/RonaldoSetzer/GAME-Minesweeper)
+ [Game - Space Invaders](https://github.com/RonaldoSetzer/GAME-SpaceInvaders)
Expand All @@ -103,4 +112,4 @@ Examples
License
---

[MIT](LICENSE)
[MIT](LICENSE)
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@
],
"author": "RobotlegsJS",
"contributors": [
"Ronaldo Santiago <ronaldo.setzers@gmail.com>"
"Ronaldo Santiago <ronaldo.setzers@gmail.com>",
"Tiago Schenkel <tiago.schenkel@gmail.com>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor/issues"
},
"homepage": "https://github.com/RobotlegsJS/RobotlegsJS-Pixi-Palidor#readme",
"dependencies": {
"@robotlegsjs/pixi": "^0.1.0"
"@robotlegsjs/pixi": "^0.1.1"
},
"devDependencies": {
"@types/bluebird": "^3.5.17",
"@types/chai": "^4.0.4",
"@types/chai": "^4.0.5",
"@types/mocha": "^2.2.44",
"@types/pixi.js": "^4.5.7",
"@types/pixi.js": "^4.6.0",
"@types/sinon": "^4.0.0",
"bluebird": "^3.5.1",
"browserify-versionify": "^1.0.6",
Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export {
export {
IFlowViewMapping
} from "./robotlegs/bender/extensions/palidorPixi/api/IFlowViewMapping";
export {
IPixiRootContainer
} from "./robotlegs/bender/extensions/palidorPixi/api/IPixiRootContainer";
export {
PalidorEvent
} from "./robotlegs/bender/extensions/palidorPixi/events/PalidorEvent";
Expand All @@ -32,9 +29,6 @@ export {
export {
PixiContainerContoller
} from "./robotlegs/bender/extensions/palidorPixi/impl/PixiContainerContoller";
export {
PixiRootContainer
} from "./robotlegs/bender/extensions/palidorPixi/impl/PixiRootContainer";
export {
PalidorPixiExtension
} from "./robotlegs/bender/extensions/palidorPixi/PalidorPixiExtension";
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import { IContainerController } from "./api/IContainerController";
import { IFlowManager } from "./api/IFlowManager";
import { IPixiRootContainer } from "./api/IPixiRootContainer";

import { FlowManager } from "./impl/FlowManager";
import { PixiContainerContoller } from "./impl/PixiContainerContoller";
import { PixiRootContainer } from "./impl/PixiRootContainer";

import {
IContext,
Expand All @@ -19,20 +18,21 @@ import {
instanceOfType
} from "@robotlegsjs/core";

import { IContextView, ContextView } from "@robotlegsjs/pixi";

export class PalidorPixiExtension implements IExtension {
private _injector: IInjector;

public extend(context: IContext): void {
this._injector = context.injector;

context.addConfigHandler(
instanceOfType(PixiRootContainer),
this.handlePixiRootContainer.bind(this)
instanceOfType(ContextView),
this.handleContextView.bind(this)
);
}

private handlePixiRootContainer(root: PixiRootContainer): void {
this._injector.bind(IPixiRootContainer).toConstantValue(root);
private handleContextView(contextView: IContextView): void {
this._injector
.bind(IContainerController)
.to(PixiContainerContoller)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { Container } from "pixi.js";

export let IContainerController = Symbol("IContainerController");
export interface IContainerController {
addView(view: any): void;
addView(view: Container): void;

changeView(view: any): void;
changeView(view: Container): void;

removeCurrentView(): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { Container } from "pixi.js";

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

export interface IFlowViewMapping {
toFloatingView(viewClass: any): void;
toFloatingView(viewClass: IClass<Container>): void;

toView(viewClass: any): void;
toView(viewClass: IClass<Container>): void;
}

This file was deleted.

31 changes: 20 additions & 11 deletions src/robotlegs/bender/extensions/palidorPixi/impl/FlowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { FlowViewMapping } from "./FlowViewMapping";
import { IContainerController } from "../api/IContainerController";
import { IFlowViewMapping } from "../api/IFlowViewMapping";
import { IFlowManager } from "../api/IFlowManager";

import { PalidorEvent } from "./../events/PalidorEvent";

import { FlowViewMapping } from "./FlowViewMapping";

import { Container } from "pixi.js";

import {
injectable,
inject,
IClass,
IEventMap,
IEventDispatcher
IEventDispatcher,
Event
} from "@robotlegsjs/core";

@injectable()
Expand All @@ -31,8 +37,8 @@ export class FlowManager implements IFlowManager {
return this._dispatcher;
}

private _views: Map<string, any>;
public get views(): Map<string, any> {
private _views: Map<string, IClass<Container>>;
public get views(): Map<string, IClass<Container>> {
return this._views;
}

Expand All @@ -45,7 +51,7 @@ export class FlowManager implements IFlowManager {
this._dispatcher = eventDispatcher;
this._controller = controller;

this._views = new Map<string, any>();
this._views = new Map<string, IClass<Container>>();
this.mapPalidorListeners();
}

Expand All @@ -57,7 +63,7 @@ export class FlowManager implements IFlowManager {
return new FlowViewMapping(event, this);
}

public mapView(eventString: string, viewClass: any): void {
public mapView(eventString: string, viewClass: IClass<Container>): void {
this._views.set(eventString, viewClass);
this._eventMap.mapListener(
this._dispatcher,
Expand All @@ -67,7 +73,10 @@ export class FlowManager implements IFlowManager {
);
}

public mapFloatingView(eventString: string, viewClass: any): void {
public mapFloatingView(
eventString: string,
viewClass: IClass<Container>
): void {
this._views.set(eventString, viewClass);
this._eventMap.mapListener(
this._dispatcher,
Expand Down Expand Up @@ -98,26 +107,26 @@ export class FlowManager implements IFlowManager {
);
}

private onChangeView(e: any): void {
private onChangeView(e: Event): void {
let clazz = this._views.get(e.type);
this._controller.removeCurrentView();
this._controller.changeView(new clazz());
}

private onAddFloatingView(e: any): void {
private onAddFloatingView(e: Event): void {
let clazz = this._views.get(e.type);
this._controller.addView(new clazz());
}

private onRemoveCurrentView(e: any): void {
private onRemoveCurrentView(e: Event): void {
this._controller.removeCurrentView();
}

private onRemoveLastFloatingView(): void {
this._controller.removeLastFloatingViewAdded();
}

private onRemoveAllFloatingView(e: any): void {
private onRemoveAllFloatingView(e: Event): void {
this._controller.removeAllFloatingViews();
}
}
Loading

0 comments on commit 8bff457

Please sign in to comment.