Skip to content

Commit

Permalink
first commit. extract ContextView from robotlegs frameowrk.
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Aug 28, 2016
0 parents commit 21eae0f
Show file tree
Hide file tree
Showing 19 changed files with 698 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
typings
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing to RobotlegsJS

## Setup

1 - Clone your fork of the repository:
```
$ git clone https://github.com/YOUR_USERNAME/RobotlegsJS.git
```

2 - Install typings:
```
$ npm install -g typings
```

3 - Install type definitions:
```
$ typings install
```

4 - Install npm dependencies:
```
$ npm install
```

5 - Run build process
```
$ npm run build
```

## Guidelines

- Please try to [combine multiple commits before
pushing](http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git)

- Please use `TDD` when fixing bugs. This means that you should write a unit
test that fails because it reproduces the issue, then fix the issue finally run
the test to ensure that the issue has been resolved. This helps us to prevent
fixed bugs from happening again in the future.
- Always format your code using `./node_modules/.bin/tsfmt -r`.
- Please keep the test coverage at 100%. Write additional unit test if
necessary
- Please create an issue before sending a PR ff your it is going to change the
public interface of RobotlegsJS or it includes significant architecture
changes.
- Feel free to ask for help from other members of the RobotlegsJS team via the
chat or github issues.
23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The MIT License (MIT)

Copyright (c) 2016 Goodgame Studios https://www.goodgamestudios.com
Copyright (c) 2009 - 2013 the original author or authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
robotlegs-pixi
===

Integrate [RobotlegsJS](https://github.com/goodgamestudios/RobotlegsJs)
framework with [PixiJS v4](https://github.com/pixijs/pixi.js).

Usage
---

```ts
/// <reference path="node_modules/robotlegs-pixi/definitions/pixi.d.ts" />

import { Context, MVCSBundle } from "robotlegs";
import { ContextView } from "robotlegs-pixi";

let context = new Context();
context.
install( MVCSBundle ).
configure( new ContextView((<any>this.renderer).plugins.interaction) );
```


License
---

[MIT](LICENSE.md)
29 changes: 29 additions & 0 deletions definitions/pixi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path="../lib/index.d.ts" />

import { IEvent } from "robotlegs";

/**
* Augment PIXI module to recognize IEventDispatcher patch.
*/
declare module "pixi.js" {

interface IEventDispatcher {
addEventListener(type: string, listener?: Function): void;
hasEventListener(type: string, listener?: Function): boolean;
removeEventListener(type: string, listener?: Function): void;
willTrigger(type: string): void;
dispatchEvent(event: IEvent): void;
}

export interface DisplayObject extends IEventDispatcher {}
export interface SystemRenderer extends IEventDispatcher {}

export interface BaseTexture extends IEventDispatcher {}
export interface Texture extends IEventDispatcher {}

export namespace loaders {
export interface Loader extends IEventDispatcher {}
export interface Resource extends IEventDispatcher {}
}

}
35 changes: 35 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const webpack = require("webpack")
const path = require("path")

const webpackConfig = require('./webpack.config.js')

module.exports = function(config) {
config.set({
basePath: "",
frameworks: ["mocha", "chai", "sinon"],
files: [
"./test/**.test.ts"
],
preprocessors: {
"./test/**.test.ts": ["webpack"]
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},
plugins: [
require("karma-webpack"),
require("karma-mocha"),
require("karma-chai"),
require("karma-sinon"),
require("karma-chrome-launcher"),
],
reporters: ["dots"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
singleRun: false
});
};
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "robotlegs-pixi",
"version": "0.1.0",
"description": "PIXI v4 integration with for RobotlegsJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"test": "mocha test/**/*.test.ts --require ts-node/register",
"build": "cp node_modules/inversify-dts/inversify/inversify.d.ts . && tsc -d",
"prepublish": "publish-please guard && rimraf ./lib && npm run build",
"publish-please": "publish-please"
},
"repository": {
"type": "git",
"url": "git@source.services.ggs-net.com:game-core/typescript-robotlegs-framework.git"
},
"keywords": [
"TypeScript",
"Robotlegs",
"IoC"
],
"author": "Goodgame Studios",
"license": "MIT",
"dependencies": {
"robotlegs": "file:../robotlegsjs"
},
"devDependencies": {
"awesome-typescript-loader": "^1.1.1",
"browserify-versionify": "^1.0.6",
"glslify": "^5.1.0",
"inversify-dts": "^2.2.0",
"pixi.js": "^4.0.0",
"publish-please": "^2.1.4",
"reflect-metadata": "^0.1.8",
"rimraf": "^2.5.2",
"typescript": "^2.1.0-dev.20160811",
"webpack": "^2.1.0-beta.20",
"webpack-dev-server": "^2.1.0-beta.0"
},
"peerDependencies": {
"pixi.js": "*",
"eventemitter3": "*"
}
}
37 changes: 37 additions & 0 deletions src/ContextView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2016 Goodgame Studios. 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.
// ------------------------------------------------------------------------------

/**
* The Context View represents the root any for a Context
*/
export class ContextView {

/*============================================================================*/
/* Public Properties */
/*============================================================================*/

private _view: any;

/**
* The root DisplayObjectContainer for this Context
*/
public get view(): any {
return this._view;
}

/*============================================================================*/
/* Constructor */
/*============================================================================*/

/**
* The Context View represents the root any for a Context
* @param view The root any for this Context
*/
constructor(view: any) {
this._view = view;
}
}
66 changes: 66 additions & 0 deletions src/ContextViewExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2016 Goodgame Studios. 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 { instanceOfType, IContext, IExtension, IInjector, ILogger } from "robotlegs";

import { ContextView } from "./ContextView";
import { applyPixiPatch } from "./pixiPatch";

/**
* <p>This Extension waits for a ContextView to be added as a configuration
* and maps it into the context's injector.</p>
*
* <p>It should be installed before context initialization.</p>
*/
export class ContextViewExtension implements IExtension {

/*============================================================================*/
/* Private Properties */
/*============================================================================*/

private _injector: IInjector;

private _logger: ILogger;

/*============================================================================*/
/* Public Functions */
/*============================================================================*/

/**
* @inheritDoc
*/
public extend(context: IContext): void {
this._injector = context.injector;
this._logger = context.getLogger(this);
context.beforeInitializing(this.beforeInitializing.bind(this));
context.addConfigHandler(instanceOfType(ContextView), this.handleContextView.bind(this));
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/

private handleContextView(contextView: ContextView): void {
if (this._injector.isBound(ContextView)) {
this._logger.warn('A contextView has already been installed, ignoring {0}', [contextView.view]);
}
else {
this._logger.debug("Mapping {0} as contextView", [contextView.view]);

applyPixiPatch(contextView.view);

// this._injector.map(ContextView).toValue(contextView);
this._injector.bind(ContextView).toConstantValue(contextView);
}
}

private beforeInitializing(): void {
if (!this._injector.isBound(ContextView)) {
this._logger.error("A ContextView must be installed if you install the ContextViewExtension.");
}
}
}
41 changes: 41 additions & 0 deletions src/ContextViewListenerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2016 Goodgame Studios. 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 { injectable, inject, IConfig, IViewManager } from "robotlegs";
import { ContextView } from "./ContextView";

/**
* This configuration file adds the ContextView to the viewManager.
*
* It requires that the ViewManagerExtension, ContextViewExtension
* and a ContextView have been installed.
*/
@injectable()
export class ContextViewListenerConfig implements IConfig {

/*============================================================================*/
/* Public Properties */
/*============================================================================*/

@inject(ContextView)
private _contextView: ContextView;

@inject(IViewManager)
private _viewManager: IViewManager;

/*============================================================================*/
/* Public Functions */
/*============================================================================*/

/**
* @inheritDoc
*/
public configure(): void {
// Adds the Context View to the View Manager at startup
this._viewManager.addContainer(this._contextView.view);
}
}
Loading

0 comments on commit 21eae0f

Please sign in to comment.