Commit b049da75 authored by rockyl's avatar rockyl

scilla新模式开始

parents
Pipeline #140313 failed with stages
in 0 seconds
# Created by .ignore support plugin (hsz.mobi)
/dist/
/node_modules/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
/**
* Created by rockyl on 16/5/19.
*
* 事件管理器
*/
export class EgretEventManager {
private static _instance: EgretEventManager;
public static get instance(): EgretEventManager {
if (this._instance == undefined) {
this._instance = new EgretEventManager();
}
return this._instance;
}
private _groups: any = {};
register(groupName: string, target: any, eventName, callback: Function, thisObj: any, priority: number = 0): void {
if (!target) {
console.error('target is empty');
}
let item: RegisterItem = new RegisterItem();
Object.assign(item, {target, eventName, callback, thisObj, priority});
let group: any = this._groups[groupName];
if (!group) {
group = this._groups[groupName] = {enable: false, items: []};
}
group.items.push(item);
if (group.enable) { //如果组已生效,添加进去的就立马生效
this.addEventListener(item);
}
}
registerOn(obj: any, target: any, eventName, callback: Function, thisObj: any, priority: number = 0): void {
this.register(getObjName(obj), target, eventName, callback, thisObj, priority);
}
enable(groupName: string): void {
let group: any = this._groups[groupName];
if (!group) {
group = this._groups[groupName] = {enable: false, items: []};
}
if (!group.enable) {
group.enable = true;
group.items.forEach(this.addEventListener);
}
}
private addEventListener(item: RegisterItem) {
item.target['addEventListener'](item.eventName, item.callback, item.thisObj, false, item.priority);
}
enableOn(obj: any): void {
this.enable(getObjName(obj));
}
disable(groupName: string): void {
let group: any = this._groups[groupName];
if (group && group.enable) {
group.enable = false;
group.items.forEach(this.removeEventListener);
}
}
private removeEventListener(item: RegisterItem) {
item.target['removeEventListener'](item.eventName, item.callback, item.thisObj);
}
disableOn(obj: any): void {
this.disable(getObjName(obj));
}
dump(groupName: string = null): void {
for (let key in this._groups) {
let group: any = this._groups[key];
console.log(key + '[' + group.items.length + ']: ' + (group.enable ? '● enable' : '○ disable'));
console.log(group.items.map((item: RegisterItem) => {
return item.eventName;
}).join(','));
}
}
}
class RegisterItem {
target: any;
eventName: string;
callback: Function;
thisObj: any;
priority: number;
}
function getObjName(obj){
return obj['__class__'] + '_' + obj.hashCode;
}
/**
* Created by rockyl on 2019-07-14.
*
* 场景
*/
import {RootEntity} from "./entities";
import {assetsManager, setupScene} from "../../scilla/src/core";
import {IScene} from "../../scilla/src/core/IScene";
export class Scene extends egret.DisplayObjectContainer implements IScene{
root: RootEntity;
constructor(root: RootEntity) {
super();
this.root = root;
this.once(egret.Event.ADDED_TO_STAGE, this.onAddedToStage, this);
}
protected onAddedToStage(event: egret.Event) {
}
async setup() {
const sceneConfig = await assetsManager.loadJson5('assets/scenes/main.scene');
setupScene(sceneConfig, this.root);
}
}
This diff is collapsed.
/**
* Created by rockyl on 2019-07-12.
*/
import {IEntity} from "../../scilla/src/core/IEntity";
import {ComponentsManager} from "../../scilla/src/core/ComponentsManager";
export class Entity extends egret.DisplayObjectContainer implements IEntity {
readonly components: ComponentsManager;
readonly uuid: string;
}
export class Text extends egret.TextField implements IEntity {
readonly components: ComponentsManager;
readonly uuid: string;
addChild(child: any) {
}
getChildAt(index) {
}
}
export class Bitmap extends egret.Bitmap implements IEntity {
readonly components: ComponentsManager;
readonly uuid: string;
addChild(child: any) {
}
getChildAt(index) {
}
}
export class Shape extends egret.Shape implements IEntity {
readonly components: ComponentsManager;
readonly uuid: string;
addChild(child: any) {
}
getChildAt(index) {
}
}
export class RootEntity extends Entity {
constructor() {
super();
this.once(egret.Event.ADDED_TO_STAGE, this.onAddedToStage, this);
}
protected onAddedToStage(event: egret.Event) {
this.x = this.stage.stageWidth / 2;
this.y = this.stage.stageHeight / 2;
}
}
/**
* Created by rockyl on 2019-07-14.
*/
import {EgretEventManager} from "./EgretEventManager";
import {ComponentsManager} from "../../scilla/src/core";
export function implementLifecycle(target) {
target.components = new ComponentsManager(target);
let events = EgretEventManager.instance;
target.addEventListener(egret.Event.ADDED_TO_STAGE, onAddedToStage, this);
events.registerOn(target, target, egret.Event.REMOVED_FROM_STAGE, onRemovedFromStage, this);
events.registerOn(target, target, egret.Event.ENTER_FRAME, onEnterFrame, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_BEGIN, onTouchBegin, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_MOVE, onTouchMove, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_END, onTouchEnd, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_TAP, onTouchTap, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_BEGIN, onStageTouchBegin, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_MOVE, onStageTouchMove, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_END, onStageTouchEnd, this);
events.registerOn(target, target, egret.TouchEvent.TOUCH_TAP, onStageTouchTap, this);
function onAddedToStage(event: egret.Event) {
target.components.enabled = true;
target.components.onEnable();
events.enableOn(target);
}
function onRemovedFromStage(event: egret.Event) {
target.components.enabled = false;
target.components.onDisable();
events.disableOn(target);
}
function onEnterFrame(event: egret.Event) {
target.components.onUpdate(egret.getTimer());
}
function onStageTouchBegin(event: egret.TouchEvent) {
target.components.onInteract(0, event);
}
function onStageTouchMove(event: egret.TouchEvent) {
target.components.onInteract(1, event);
}
function onStageTouchEnd(event: egret.TouchEvent) {
target.components.onInteract(2, event);
}
function onStageTouchTap(event: egret.TouchEvent) {
target.components.onInteract(3, event);
}
function onTouchBegin(event: egret.TouchEvent) {
target.components.onInteract(4, event);
}
function onTouchMove(event: egret.TouchEvent) {
target.components.onInteract(5, event);
}
function onTouchEnd(event: egret.TouchEvent) {
target.components.onInteract(6, event);
}
function onTouchTap(event: egret.TouchEvent) {
target.components.onInteract(7, event);
}
}
/**
* Created by rockyl on 2019-07-13.
*/
import {IBridge} from "../core/Bridge";
import {IEntity} from "../../scilla/src/core";
import {IScene} from "../../scilla/src/core/IScene";
import {implementLifecycle} from "./entity-proxy";
import {Scene} from "./Scene";
import {launch} from "./launcher";
export * from './entities'
export class Bridge implements IBridge{
createEntity(def, options?): IEntity {
let instance = new def();
if(options.name){
instance['name'] = options.name;
}
if(options.uuid){
instance['uuid'] = options.uuid;
}
implementLifecycle(instance);
return instance;
}
launch(options?) {
launch(options);
}
}
/**
* Created by rockyl on 2019-07-14.
*/
import {RootEntity} from "./entities";
import {Scene} from "./Scene";
class Main extends egret.DisplayObjectContainer {
constructor() {
super();
this.once(egret.Event.ADDED_TO_STAGE, this.onAddedToStage, this);
}
protected onAddedToStage(event: egret.Event) {
let root = new RootEntity();
root.name = 'root';
this.addChild(root);
let scene = new Scene(root);
scene.setup();
}
}
window['Main'] = Main;
export function launch(options?) {
egret.runEgret({
renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor: function (context: any) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment