Commit 379ed1e1 authored by rockyl's avatar rockyl

修改scilla-core为scilla

parent dd09d269
{
"name": "scilla-core",
"name": "scilla",
"version": "1.0.0",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"license": "MIT",
"scripts": {
"scripts": {},
"devDependencies": {
"rollup-plugin-commonjs": "^9.2.2",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-typescript2": "^0.20.1",
"rollup-plugin-uglify": "^6.0.2",
"tslib": "^1.9.3",
"typescript": "^3.3.4000"
}
}
/**
* Created by rockyl on 2018/11/16.
*/
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const typescript = require('rollup-plugin-typescript2');
const {uglify} = require('rollup-plugin-uglify');
export default {
input: 'src/index.ts',
output: {
file: 'dist/bundle.js',
format: 'umd',
name: 'scilla',
},
plugins: [
resolve({
browser: true,
}),
typescript({
typescript: require('typescript'),
tslib: require('tslib'),
useTsconfigDeclarationDir: true,
}),
commonjs(),
//uglify({}),
]
};
......@@ -425,7 +425,7 @@ export class Entity extends HashObject {
onEnable() {
this.forEachComponent(comp => {
if (comp.enabled) {
return comp.onAwake();
return comp.$onAwake();
}
});
}
......@@ -436,19 +436,23 @@ export class Entity extends HashObject {
onDisable() {
this.forEachComponent(comp => {
if (comp.enabled) {
return comp.onSleep();
return comp.$onSleep();
}
});
}
/**
* 当始终更新时
* 当时钟更新时
* @param t
*/
onUpdate(t) {
this.forEachComponent(comp => {
if (comp.enabled) {
return comp.$onUpdate(t);
if(EngineConfig.editorMode){
return comp.$onEditorUpdate(t);
}else{
return comp.$onUpdate(t);
}
}
});
}
......@@ -459,7 +463,11 @@ export class Entity extends HashObject {
afterUpdate() {
this.forEachComponent(comp => {
if(comp.enabled){
return comp.afterUpdate();
if(EngineConfig.editorMode){
return comp.$afterEditorUpdate();
}else{
return comp.$afterUpdate();
}
}
});
}
......@@ -504,7 +512,7 @@ export class Entity extends HashObject {
*/
awakeComponent(component) {
if (!this._isFree && this._enabled) {
component.onAwake();
component.$onAwake();
}
}
......@@ -525,7 +533,7 @@ export class Entity extends HashObject {
*/
sleepComponent(component) {
if (!this._isFree && this._enabled) {
component.onSleep();
component.$onSleep();
}
}
......
......@@ -3,7 +3,7 @@
*/
import HashObject from "./HashObject";
import {Entity, } from "./Entity";
import {Entity,} from "./Entity";
import {EngineConfig} from "../engine-config";
const interactiveMap = [
......@@ -37,10 +37,12 @@ export class ScillaComponent extends HashObject {
if (this._enabled !== value) {
this._enabled = value;
if (this.entity && this.entity.isActive) {
if (this._enabled) {
this.onEnable();
} else {
this.onDisable();
if(!EngineConfig.editorMode){
if (this._enabled) {
this.onEnable();
} else {
this.onDisable();
}
}
}
}
......@@ -52,7 +54,9 @@ export class ScillaComponent extends HashObject {
*/
_setup(entity: Entity) {
this.entity = entity;
this.onCreate();
if(!EngineConfig.editorMode){
this.onCreate();
}
}
/**
......@@ -60,7 +64,9 @@ export class ScillaComponent extends HashObject {
*/
_unSetup() {
this.entity = null;
this.onDestroy();
if(!EngineConfig.editorMode){
this.onDestroy();
}
}
/**
......@@ -70,6 +76,12 @@ export class ScillaComponent extends HashObject {
}
$onAwake(){
if(!EngineConfig.editorMode){
this.onAwake();
}
}
/**
* 当组件被唤醒时
*/
......@@ -80,36 +92,48 @@ export class ScillaComponent extends HashObject {
/**
* 当组件生效时
*/
onEnable(){
onEnable() {
}
/**
* 当组件失效时
*/
onDisable(){
onDisable() {
}
$onUpdate(t) {
this.onUpdate(t);
if(!this._firstUpdate){
if (!this._firstUpdate) {
this.invokeDelayCallback(t);
}
this._firstUpdate = false;
}
private invokeDelayCallback(t){
$onEditorUpdate(t) {
this.onEditorUpdate(t);
}
$afterUpdate(){
this.afterUpdate();
}
$afterEditorUpdate() {
this.afterEditorUpdate();
}
private invokeDelayCallback(t) {
const removed = [];
for (let i = 0, li = this.delayCallbacks.length; i < li; i++) {
let {callback, once} = this.delayCallbacks[i];
if(once){
if (once) {
removed.push(i);
}
callback.call(this, t);
}
for(let item of removed){
for (let item of removed) {
this.delayCallbacks.splice(item, 1);
}
}
......@@ -122,6 +146,10 @@ export class ScillaComponent extends HashObject {
}
onEditorUpdate(t) {
}
/**
* 当子节点的时钟更新结束后
*/
......@@ -129,6 +157,16 @@ export class ScillaComponent extends HashObject {
}
afterEditorUpdate(){
}
$onSleep() {
if(!EngineConfig.editorMode){
this.onSleep();
}
}
/**
* 当组件沉睡时
*/
......@@ -149,14 +187,14 @@ export class ScillaComponent extends HashObject {
* @param key
* @param oldValue
*/
protected onModify(value, key, oldValue){
protected onModify(value, key, oldValue) {
}
private getDelayCallback(callback){
private getDelayCallback(callback) {
let result;
for(let item of this.delayCallbacks){
if(item.callback == callback){
for (let item of this.delayCallbacks) {
if (item.callback == callback) {
result = item;
break;
}
......@@ -176,10 +214,10 @@ export class ScillaComponent extends HashObject {
}
}
cancelOnNextTick(callback){
cancelOnNextTick(callback) {
const item = this.getDelayCallback(callback);
const index = this.delayCallbacks.indexOf(item);
if(index >= 0){
if (index >= 0) {
this.delayCallbacks.splice(index, 1);
}
}
......@@ -234,7 +272,7 @@ export class ScillaComponent extends HashObject {
}
get transform(){
get transform() {
return this.entity.getComponent('components/base/Transform');
}
......
......@@ -99,7 +99,7 @@ export default class Texture extends HashObject {
/**
* 销毁缓存画布
*/
destroyCacheCanvas(){
destroyCacheCanvas() {
this._cacheCanvas = null;
}
}
......@@ -109,7 +109,7 @@ export default class Texture extends HashObject {
* @param img
* @param frame
*/
export function createTexture(img, frame?): Texture {
export function createTexture(img, frame?: { x: number, y: number, w: number, h: number }): Texture {
const texture = new Texture();
texture.setImg(img);
texture.setFrame(frame || {x: 0, y: 0, w: img.width, h: img.height});
......
......@@ -7,6 +7,7 @@ import {injectProp} from "../tools/utils";
import {setupContext as setupInteractContext} from "./context/InteractContext";
import {clear, ScaleMode, setupContext as setupRenderContext} from "./context/RenderContext";
import './requestAnimationFrame';
import {EngineConfig} from "../engine-config";
/**
* 默认配置
......@@ -166,8 +167,8 @@ function flush(tsNow): void {
}
const nextTicks = [];
export function nextTick(func){
nextTicks.push(func);
export function nextTick(func, tickCount = 1){
nextTicks.push({func, tickCount});
}
function onFrameTick(tsNow) {
......@@ -188,9 +189,17 @@ function onFrameTick(tsNow) {
});
//const tsPass = Date.now() - tsNow;
while(nextTicks.length > 0){
let func = nextTicks.shift();
func();
for (let i = 0, li = nextTicks.length; i < li; i++) {
const item = nextTicks[i];
item.tickCount --;
if(item.tickCount <= 0){
item.func(ts);
nextTicks.splice(i, 1);
i--;
li--;
}
}
}
......
......@@ -6,6 +6,7 @@
import {Entity, Scene, ScillaEvent} from "../core";
import {getRes} from "../assets-manager";
import {EngineConfig} from "../engine-config";
let entityCache = {};
let entityCacheConfig;
......@@ -224,15 +225,16 @@ export function instantiateComponent(entity: Entity, config: any) {
/**
* 根据名称获取定义
* @param name
* @param showWarn
*/
function getDefByName(name): any {
export function getDefByName(name: string, showWarn: boolean = true): any {
let def;
/*if (name.indexOf('/') >= 0) {//addition
name = name.substr(name.lastIndexOf('/') + 1);
}*/
def = defMap[name];
if (!def) {
if (!def && showWarn) {
console.warn('missing def:', name);
return;
}
......@@ -261,7 +263,9 @@ function injectProperties(node, propertiesConfig, pid?) {
let propertyOfInstance = node[key];
if (typeof propertyOfConfig === 'object') {
if (propertyOfInstance instanceof ScillaEvent) {
injectEvent(propertyOfInstance, propertyOfConfig, pid);
if(!EngineConfig.editorMode){
injectEvent(propertyOfInstance, propertyOfConfig, pid);
}
} else if (propertyOfConfig._type_ === 'raw') {
node[key] = propertyOfInstance = propertyOfConfig.data;
} else {
......
......@@ -12,6 +12,7 @@ export const EngineConfig = {
sleepComponentWhenRemoved: true,
drawRenderRect: false,
imgCrossOrigin: true,
editorMode: false,
};
export function modifyEngineConfig(_options) {
......
This diff is collapsed.
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