Commit 8c5a3ea8 authored by Stepheno's avatar Stepheno

Initial commit

parents
Pipeline #134935 failed with stages
in 0 seconds
{
"currentScene": "assets/scenes/main.scene",
"dependencies": {
"ui/Button": "1.0.0",
"animation/TouchZoom": "1.0.0",
"animation/Wave": "1.0.0",
"other/CameraController": "1.0.0",
"renderer/TextureRenderer": "1.0.0",
"renderer/RectRenderer": "1.0.0",
"renderer/TextRenderer": "1.0.0",
"base/InteractComponent": "1.0.0",
"renderer/GraphicRenderer": "1.0.0",
"base/Transform": "1.0.3",
"base/ScillaComponent": "1.0.0",
"renderer/Renderer": "1.0.0"
}
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"d79519a3-915b-4a9f-9303-a15b642cfe24","subMetas":{},"isGroup":true}
{
"name": "main",
"root": {
"components": [
{
"script": "components/base/Transform"
}
],
"children": [
{
"name": "MainStage",
"uuid": "20181212032053",
"components": [
{
"script": "components/base/Transform",
"properties": {}
},
{
"script": "components/other/CameraController"
},
{
"script": "./scripts/HelloScilla",
"properties": {
"label": "entity|797fad3f-17ed-4a9e-841f-a6b91aed37fa",
"name": "Tom",
"logo": "entity|6f148871-0515-4ef8-9c0c-d3ed7baa0a11"
}
}
],
"children": [
{
"name": "Image",
"components": [
{
"script": "components/base/Transform",
"properties": {
"position": {
"y": -150,
"_type_": "scilla/support/Vector2D"
}
}
},
{
"script": "components/renderer/TextureRenderer",
"properties": {
"texture": "res|8ad59445-0ff2-4382-bb1c-9f7a07845e48"
}
},
{
"script": "components/animation/Wave",
"properties": {
"loop": 1,
"waveMethod": "rotate",
"autoPlay": false,
"duration": 400
}
}
],
"uuid": "6f148871-0515-4ef8-9c0c-d3ed7baa0a11"
},
{
"name": "Label",
"components": [
{
"script": "components/base/Transform",
"properties": {}
},
{
"script": "components/renderer/TextRenderer",
"properties": {
"fillColor": "rgba(255, 255, 255, 1)",
"text": "Tap Button"
}
}
],
"uuid": "797fad3f-17ed-4a9e-841f-a6b91aed37fa"
},
{
"name": "Button",
"components": [
{
"script": "components/base/Transform",
"properties": {
"position": {
"y": 80,
"_type_": "scilla/support/Vector2D"
}
}
},
{
"script": "components/renderer/RectRenderer",
"properties": {
"fillColor": "rgba(0, 192, 255, 1)",
"width": 150,
"height": 60,
"cornerRadius": 10
}
},
{
"script": "components/animation/TouchZoom",
"properties": {
"easeName": "backOut"
}
},
{
"script": "components/ui/Button",
"properties": {
"onClick": [
{
"entity": "entity|20181212032053",
"component": 1,
"method": "tapMe"
}
]
}
}
],
"children": [
{
"name": "label",
"components": [
{
"script": "components/base/Transform"
},
{
"script": "components/renderer/TextRenderer",
"properties": {
"text": "button",
"fillColor": "rgba(255, 255, 255, 1)"
}
}
],
"uuid": "4f7d630d-026c-4c1a-bf40-19a5cbecadb6"
}
],
"uuid": "cd518011-9d11-4376-af30-f64cef2a08cd"
}
]
}
]
},
"entity-cache": [
"797fad3f-17ed-4a9e-841f-a6b91aed37fa",
"6f148871-0515-4ef8-9c0c-d3ed7baa0a11",
"20181212032053"
],
"resource-groups": {
"preload": [
{
"uuid": "8ad59445-0ff2-4382-bb1c-9f7a07845e48",
"url": "singles/logo.png"
}
]
}
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"1f50815f-bf2f-4cf6-8432-f56f3aa834ef","subMetas":{},"type":"scene"}
{"ver":"1.0.1","uuid":"def65e96-eed7-44b3-9804-e76dea9e5062","subMetas":{},"isGroup":true}
/**
* Created by rockyl on 2019-01-03.
*
* 砖块动画单体
*/
import {Entity,} from "scilla";
import TextRenderer from 'components/renderer/TextRenderer'
import Wave from 'components/animation/Wave'
import ScillaComponent from 'components/base/ScillaComponent';
export default class HelloScilla extends ScillaComponent {
name: string = 'scilla';
logo: Entity;
label: Entity;
private labelRenderer: TextRenderer;
private logoAnimation: Wave;
onCreate() {
super.onCreate();
this.labelRenderer = this.label.getComponent(TextRenderer);
this.logoAnimation = this.logo.getComponent(Wave);
}
tapMe(){
this.labelRenderer.text = 'Hello ' + this.name;
this.logoAnimation.play();
}
}
{"ver":"1.0.1","uuid":"bd9a9589-4961-44b9-ae8c-263297eb9a35","subMetas":{},"type":"script"}
{"ver":"1.0.1","uuid":"a67a10bf-16e9-47b7-8f10-ee7dcdeb2551","subMetas":{},"isGroup":true}
{
"ver": "1.0.1",
"uuid": "8ad59445-0ff2-4382-bb1c-9f7a07845e48",
"subMetas": {
"logo": {
"ver": "1.0.1",
"uuid": "c4c4d4b8-5178-4468-9460-c95435abefb8",
"rawTextureUuid": "8ad59445-0ff2-4382-bb1c-9f7a07845e48",
"type": "texture"
}
},
"type": "texture",
"imagePath": "/Users/rockyl/WorkSpaces/scilla/hello-scilla/assets/singles/logo.png"
}
/Users/firefly/.scilla/components
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>minner-tool</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html, body {
padding: 0;
margin: 0;
border: 0;
height: 100%;
background-color: #282C34;
}
</style>
</head>
<body>
<div id="gameContainer" style="width: 100%;height: 100%;overflow: hidden;"></div>
<script src="debug/bundle.js"></script>
<script>
setTimeout(function(){
var options = window['inputOptions'] || {};
window['minner-tool'].startup(document.getElementById('gameContainer'), options);
}, 100);
</script>
</body>
</html>
{"name":"minner-tool","engineConfig":{"fps":60,"designWidth":750,"designHeight":1334,"scaleMode":"showAll","modifyCanvasSize":false,"resPath":""},"customConfig":{"scene":{"scenes":{"main":"scenes/main.scene"},"entryScene":"main"},"webServiceUrl":"http://localhost:4001"},"dataCenterConfig":{"dataCenterRoot":[]},"projectUuid":"1ea735b4-a8cc-49e8-b2f6-24d9d29468ab"}
{
"code": "0000000000",
"data": {
"creditsConf": {
"creditsUp": 100,
"creditsType": "virtual",
"creditsDown": 50,
"prize": [
{
"img": "adsfsadf",
"credits": 20,
"id": 4,
"title": "0.3"
},
{
"img": "sadfasdf",
"credits": 150,
"id": 3,
"title": "1.5倍"
},
{
"img": "sadfasdf",
"credits": 100,
"id": 2,
"title": "1倍"
},
{
"img": "sadfasdf",
"credits": 50,
"id": 1,
"title": "0.5倍"
}
]
},
"floating": {
"jsTest": "//yun1.duiba.com.cn/h5/showCouponPrize/4.0.0/index_201710191434.js",
"cssTest": "//yun1.duiba.com.cn/h5/showCouponPrize/4.0.0/index_201710191440.css"
},
"options": [
{
"hidden": false,
"prizeType": "thanks",
"name": "谢谢参与",
"description": "",
"logo": "//yun1.duiba.com.cn/upload/uP99F1462438316972.png",
"id": 15581
},
{
"hidden": false,
"prizeType": "lucky",
"name": "幸运福袋",
"description": "",
"logo": "//yun1.duiba.com.cn/webapp/img/luckynewn.png",
"id": 15582
},
{
"itemId": 47861,
"scoreArea": "",
"hidden": false,
"prizeType": "alipay",
"name": "支付宝1",
"description": "",
"logo": "//yun1.duiba.com.cn/developer/img/activityTool/slotMachine/alipay.png",
"id": 15585
}
],
"rule": "adsfasdf",
"type": "hdtool",
"element": {
"isCreditsTypeOpen": false,
"myCreditsLong": 999999632167,
"freeLimit": -1,
"success": false,
"myCredits": "999999632167",
"needCredits": "100",
"freeEmpty": true,
"needCreditsLong": 100,
"status": 1
}
},
"success": true,
"desc": "OK",
"timestamp": 1548832971636
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550564744291,
"data": {
"skincontent": "f2fcc331f44c98883f3a5b4868d7d7f4",
"throughInfo": [
{
"step": 3,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 4,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 5,
"prizeType": 2,
"description": null,
"img": ""
},
{
"step": 6,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 7,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 9,
"prizeType": 2,
"description": null,
"img": ""
},
{
"step": 10,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 11,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 13,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 15,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 16,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 18,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 19,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 21,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 22,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 24,
"prizeType": 1,
"description": null,
"img": ""
},
{
"step": 27,
"prizeType": 4,
"description": null,
"img": ""
}
]
}
}
\ No newline at end of file
{
"success":true,
"code":"0000000000",
"desc":"OK",
"timestamp":1548915321930,
"data":1
}
\ No newline at end of file
{"success":true,"code":"0000000000","desc":"OK","timestamp":1548915321930,"data":123456}
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550569853824,
"data": {
"prizeType": "alipay",
"facePrice": "100",
"title": "1"
}
}
\ No newline at end of file
{
"success":true,
"code": 1,
"desc":"L(*ythj",
"timestamp":1548923950498
}
\ No newline at end of file
{"success":true,"code":"0000000000","desc":"OK","timestamp":1548923950498,"data":{"element":{"success":false,"isCreditsTypeOpen":false,"needCredits":"100","myCredits":"999999630434","myCreditsLong":999999630434,"needCreditsLong":100,"freeLimit":-1,"status":1,"freeEmpty":true},"lottery":{"id":null,"type":"thanks","imgUrl":null,"link":null,"title":null,"itemId":null,"appItemId":null,"bonus":null,"bonusMin":null,"bonusMax":null,"needAccount":null,"appLucky":null,"tip":null,"useBtnText":null,"validate":null,"couponCode":null,"couponKey":null,"stInfoDpmImg":null,"stInfoDpmClose":null,"stInfoDpmGoUse":null,"showUse":null,"openUrl":null,"iosDownloadUrl":null,"androidDownloadUrl":null,"isDownloadUrl":null,"confirm":null,"phaseNumber":null,"happyCode":null,"appHidden":true,"zybangJson":null},"exposure":null,"creditsInfo":{"activityId":82567,"prizeId":4,"orderNum":null,"developerBizId":"3029576","score":null,"recordStatus":1,"errorMsg":null},"againTag":null}}
{
"success":true,
"code":"0000000000",
"desc":"OK",
"timestamp":1548915321930,
"data":1
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550570639368,
"data": {
"orderId": "883006813674240289",
"submitToken": "d895deb9118f4b938d0b70a3dd2ace19",
"credits": "999999491765",
"unitName": "金币",
"consumerCredits": 999999491765
}
}
\ No newline at end of file
{
"success":true,
"code":"0000000000",
"desc":"OK",
"timestamp":1548915321930,
"data":123456
}
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550646190489,
"data": {
"score": 100,
"maxScore": 100
}
}
\ No newline at end of file
{
"success": true,
"code": 1,
"desc": "Hl7&L",
"timestamp": "1548915321930",
"data": "123123123"
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1551066205001,
"data": {
"resurrectionStatus": true,
"resurrectionCount": 2,
"resurrectionCredits": 300
}
}
\ No newline at end of file
{
"success": true,
"code": 0,
"desc": "ok",
"timestamp": "1519442544000",
"data": {
"valiDate": "2019-04-11 11:11:11",
"description": "xxx",
"title": "title",
"img": "//yun1.duiba.com.cn/upload/uP99F1462438316972.png"
}
}
\ No newline at end of file
{
"success":true,
"code":"0000000000",
"desc":"OK",
"timestamp":1548915321930,
"data":1
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550647892216,
"data": "扣积分成功"
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1550568405622,
"data": {
"needPrize": true,
"lastThrough": null,
"currentLocation": 6,
"prizeType": 5,
"retreat": null,
"forward": null,
"url": null,
"plginOrderId": null,
"point": 5
}
}
\ No newline at end of file
{
"success": true,
"code": "0000000000",
"desc": "OK",
"timestamp": 1552025592298,
"data": {
"element": null,
"rule": null,
"questions": [
{
"id": 1,
"type": "text",
"name": "题目1",
"options": [
{
"optionId": 1,
"option": "1"
},
{
"optionId": 2,
"option": "2"
},
{
"optionId": 3,
"option": "3"
},
{
"optionId": 4,
"option": "4"
}
]
},
{
"id": 3,
"type": "text",
"name": "题目3",
"options": [
{
"optionId": 1,
"option": "1"
},
{
"optionId": 2,
"option": "2"
},
{
"optionId": 3,
"option": "3"
},
{
"optionId": 4,
"option": "4"
}
]
}
]
}
}
\ No newline at end of file
{
"systemParams": "darwin-x64-72",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [
"dbtinypng",
"game-cli",
"scilla",
"scilla-cli",
"scilla-component-cli",
"scilla-components",
"scilla-components-docs-cli",
"scilla-core",
"scilla-docs-cli",
"test"
],
"topLevelPatterns": [
"scilla-launcher@git+http://gitlab2.dui88.com/laoqifeng/scilla-launcher#dev",
"scilla@git+http://gitlab2.dui88.com/laoqifeng/scilla-core#dev"
],
"lockfileEntries": {
"scilla-launcher@git+http://gitlab2.dui88.com/laoqifeng/scilla-launcher#dev": "git+http://gitlab2.dui88.com/laoqifeng/scilla-launcher#8881f38cf3d72c38585f2655b7559ca892973fea",
"scilla@git+http://gitlab2.dui88.com/laoqifeng/scilla-core#dev": "git+http://gitlab2.dui88.com/laoqifeng/scilla-core#860ceae5d6f63827a4ad200405d0500615fc5ed2"
},
"files": [],
"artifacts": {}
}
\ No newline at end of file
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
/.rpt2_cache/
/dist/
{
"name": "scilla-launcher",
"version": "1.0.1",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"license": "MIT",
"devDependencies": {
"glob": "^7.1.3",
"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');
const name = 'scilla-launcher';
export default {
input: 'src/index.ts',
output: {
file: `dist/${name}.js`,
format: 'umd',
name,
//sourcemap: true,
},
plugins: [
resolve({
browser: true,
}),
typescript({
typescript: require('typescript'),
tslib: require('tslib'),
declaration: false,
}),
commonjs(),
//uglify({}),
],
external: ['scilla']
};
<?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$/../scilla-launcher" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
/**
* Created by rockyl on 2018-12-03.
*/
import {Entity, ScillaEngine, setupScene} from "scilla";
/**
* 场景
*/
export default class Scene {
private _engine: ScillaEngine;
private _name: string;
private _resourceGroups: any = {
preload: [],
delay: [],
};
private _config: any;
private _root: Entity;
constructor(engine: ScillaEngine) {
this._engine = engine;
}
get root(): Entity {
return this._root;
}
/**
* 初始化
* @param config
*/
initByConfig(config: any) {
this._config = config;
this._name = config.name;
const resourceGroups = config['resource-groups'];
for (let key in resourceGroups) {
this._resourceGroups[key] = resourceGroups[key];
}
}
setup(root: Entity) {
this._root = root;
const assetsManager = this._engine.assetsManager;
setupScene(this._config, root, assetsManager.getRes.bind(assetsManager));
}
/**
* 加载资源组
* @param name
* @param replaceConfig
* @param progress
*/
async loadResGroup(name, replaceConfig?, progress?) {
await this._engine.assetsManager.loadResItems(this._resourceGroups[name], replaceConfig, progress);
}
}
/**
* Created by rockyl on 2018-12-04.
*/
import {engine, utils, cleanEntity} from "scilla";
import Scene from './Scene'
export {default as Scene} from './Scene'
export default class ScillaLauncher{
private currentScene: Scene;
private resUUIDs: string[];
/**
* 启动引擎
* @param containerElement
* @param options
* @param onProgress
*/
async launch(containerElement, options:any = {}, onProgress: Function) {
const resPath = options.resPath || '';
const manifest = await engine.assetsManager.loadJson(resPath + 'manifest.json');
engine.assetsManager.setResPath(resPath + 'assets/');
let engineConfig:any = {};
utils.injectProp(engineConfig, manifest.engineConfig);
utils.injectProp(engineConfig, options.engineConfig);
let customConfig:any = {};
utils.injectProp(customConfig, manifest.customConfig);
utils.injectProp(customConfig, options.customConfig);
let dataCenterConfig:any = {};
utils.injectProp(dataCenterConfig, manifest.dataCenterConfig);
utils.injectProp(dataCenterConfig, options.dataCenterConfig);
let canvas = document.createElement('canvas');
containerElement.appendChild(canvas);
engineConfig.canvas = canvas;
engine.setup(engineConfig, customConfig, dataCenterConfig);
let entryScene = options.scene || customConfig.scene.entryScene;
await this.launchScene(entryScene, options.resReplaceConfigs, onProgress)
}
/**
* 启动场景
* @param sceneNameOrPath
* @param resReplaceConfigs
* @param progress
*/
async launchScene(sceneNameOrPath, resReplaceConfigs?, progress?) {
const sceneConfig = engine.customConfig.scene;
let sceneFile = sceneConfig.scenes[sceneNameOrPath];
if(!sceneFile){
sceneFile = sceneNameOrPath;
}
const scene = await this.loadScene(sceneFile, 'scene_' + sceneFile);
this.resUUIDs = engine.assetsManager.getAllResUuids();
const replaceConfig = resReplaceConfigs && resReplaceConfigs[sceneFile];
await scene.loadResGroup('preload', replaceConfig, progress);
if(this.currentScene){
this.unmountScene(this.currentScene);
}
this.currentScene = scene;
this.mountScene(scene);
scene.loadResGroup('delay', null, progress);
}
/**
* 装载场景
* @param scene
*/
private mountScene(scene){
engine.pause();
scene.setup(engine.root);
engine.start();
}
/**
* 卸载场景
* @param scene
*/
private unmountScene(scene){
engine.pause();
cleanEntity(scene.root);
engine.assetsManager.destroyRes(this.resUUIDs);
}
/**
* 加载场景资源
* @param url url
* @param uuid 唯一名
* @param cache 是否缓存
* @param config
* @return Promise<any> 资源
*/
private async loadScene(url, uuid?, cache = false, config?) {
const sceneConfig = await engine.assetsManager.loadJson5(url);
const scene = new Scene(engine);
scene.initByConfig(sceneConfig);
return scene;
}
}
{
"compilerOptions": {
"target": "es5",
"outDir": "dist",
"experimentalDecorators": true,
"sourceMap": true,
"declarationDir": "types",
"declaration": true,
"lib": [
"es5",
"es6",
"dom",
"es2015.promise"
],
"baseUrl": "./",
"paths": {
"scilla": ["node_modules/scilla/src"]
}
},
"include": [
"src"
]
}
\ No newline at end of file
This diff is collapsed.
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
/.rpt2_cache/
/**
* Created by rockyl on 2018/11/23.
*/
import {Entity, traverse, traversePostorder} from "./Entity";
import {injectProp} from "../tools/utils";
import {setupContext as setupInteractContext} from "./context/InteractContext";
import {clear, ScaleMode, setupContext as setupRenderContext} from "./context/RenderContext";
import './requestAnimationFrame';
/**
* 创建引擎实例
* @param options
*/
export function createEngineInstance(options?) {
let instance = new ScillaEngine();
instance.setup(options);
}
/**
* 引擎类
*/
class ScillaEngine {
/**
* 默认配置
*/
options: any = {
fps: 60,
designWidth: 750,
designHeight: 1334,
scaleMode: ScaleMode.FIXED_WIDTH,
touchEnabled: true,
};
_flush: number = 0;
_currentFlush: number = 0;
tsStart: number;
tsLast: number;
lastFPS: number = 0;
private readonly root: Entity;
constructor() {
this.root = new Entity('root');
this.root._restrict();
}
setup(options?){
injectProp(this.options, options);
const {canvas, designWidth, designHeight, scaleMode, modifyCanvasSize, touchEnabled} = options;
let canvasElement = typeof canvas == 'object' ? canvas : document.getElementById(canvas);
setupInteractContext({
canvas: canvasElement,
touchHandler: {
onTouchBegin: this.onTouchBegin.bind(this),
onTouchMove: this.onTouchMove.bind(this),
onTouchEnd: this.onTouchEnd.bind(this),
},
touchEnabled,
});
setupRenderContext({
canvas: canvasElement,
designWidth,
designHeight,
scaleMode,
modifyCanvasSize,
});
}
/**
* 开始引擎
*/
start() {
this.root.enabled = true;
this.tsStart = Date.now();
this.startTick();
}
/**
* 暂停引擎
*/
pause() {
this.root.enabled = false;
this.stopTick();
}
/**
* 获取节点路径
* @param entity
*/
getEntityPath(entity?: Entity): string {
let path = '';
let current = entity || this.root;
while (current.parent) {
path = current.parent.children.indexOf(current) + (path.length > 0 ? '|' : '') + path;
current = current.parent;
}
return path;
}
/**
* 根据节点路径获取节点
* @param path
*/
getEntityByPath(path?: string): Entity {
let target = this.root;
if (path.length > 0) {
let arr = path.split('|');
for (let item of arr) {
target = target.children[item];
if (!target) {
target = null;
break;
}
}
}
return target;
}
/**
* 获取当前帧率
*/
get fps() {
return this.lastFPS;
}
/**
* 开始时钟
*/
private startTick() {
this._flush = 60 / this.options.fps - 1 >> 0;
if (this._flush < 0) {
this._flush = 0;
}
requestAnimationFrame(this.flush);
}
/**
* 停止时钟
*/
private stopTick() {
}
/**
* 时钟触发
*/
private flush(tsNow): void {
if (this._flush == 0) {
this.onFrameTick(tsNow);
} else {
if (this._currentFlush == 0) {
this.onFrameTick(tsNow);
this._currentFlush = this._flush;
} else {
this._currentFlush--;
}
}
requestAnimationFrame(this.flush);
}
nextTicks = [];
nextTick(func, tickCount = 1) {
this.nextTicks.push({func, tickCount});
}
private onFrameTick(tsNow) {
clear();
this.lastFPS = Math.floor(1000 / (tsNow - this.tsLast));
this.tsLast = tsNow;
const ts = tsNow - this.tsStart;
traverse(this.root, function (child) {
if (!child.isFree && child.enabled) {
child.onUpdate(ts);
} else {
return true;
}
}, -1, true, function (current) {
current.afterUpdate();
});
//const tsPass = Date.now() - tsNow;
for (let i = 0, li = this.nextTicks.length; i < li; i++) {
const item = this.nextTicks[i];
item.tickCount--;
if (item.tickCount <= 0) {
item.func(ts);
this.nextTicks.splice(i, 1);
i--;
li--;
}
}
}
/**
* 代理出来的onTouchBegin方法
* @param event
*/
private onTouchBegin(event) {
traversePostorder(this.root, function (child) {
return child.onInteract(0, event);
})
}
/**
* 代理出来的onTouchMove方法
* @param event
*/
private onTouchMove(event) {
traversePostorder(this.root, function (child) {
return child.onInteract(1, event);
})
}
/**
* 代理出来的onTouchEnd方法
* @param event
*/
private onTouchEnd(event) {
traversePostorder(this.root, function (child) {
return child.onInteract(2, event);
})
}
}
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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