Commit 50ad6cc9 authored by rockyl's avatar rockyl

init

parents
Pipeline #119794 failed with stages
in 0 seconds
# 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/
/**
* Created by rockyl on 2018-12-03.
*/
import { Entity, ScillaEngine } from "scilla";
/**
* 场景
*/
export default class Scene {
private _engine;
private _name;
private _resourceGroups;
private _config;
private _root;
constructor(engine: ScillaEngine);
readonly root: Entity;
/**
* 初始化
* @param config
*/
initByConfig(config: any): void;
setup(root: Entity): void;
/**
* 加载资源组
* @param name
* @param progress
*/
loadResGroup(name: any, progress?: any): Promise<void>;
}
/**
* Created by rockyl on 2018-12-04.
*/
import { ScillaEngine } from "scilla";
export { default as Scene } from './Scene';
export default class ScillaLauncher {
private currentScene;
private resUUIDs;
private _engine;
constructor(engine: ScillaEngine);
readonly engine: ScillaEngine;
/**
* 启动引擎
* @param containerElement
* @param options
* @param onProgress
*/
launch(containerElement: any, options: any, onProgress: Function): Promise<void>;
/**
* 启动场景
* @param sceneNameOrPath
* @param progress
*/
launchScene(sceneNameOrPath: any, progress?: any): Promise<void>;
/**
* 装载场景
* @param scene
*/
private mountScene;
/**
* 卸载场景
* @param scene
*/
private unmountScene;
/**
* 加载场景资源
* @param url url
* @param uuid 唯一名
* @param cache 是否缓存
* @param config
* @return Promise<any> 资源
*/
private loadScene;
}
This diff is collapsed.
{
"name": "scilla-launcher",
"version": "1.0.0",
"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 progress
*/
async loadResGroup(name, progress?) {
await this._engine.assetsManager.loadResItems(this._resourceGroups[name], progress);
}
}
declare const DEBUG: boolean;
declare const RELEASE: boolean;
\ No newline at end of file
/**
* Created by rockyl on 2018-12-04.
*/
import {ScillaEngine, utils, cleanEntity} from "scilla";
import Scene from './Scene'
export {default as Scene} from './Scene'
export default class ScillaLauncher{
private currentScene: Scene;
private resUUIDs: string[];
private _engine: ScillaEngine;
constructor(engine: ScillaEngine){
this._engine = engine;
}
get engine(): ScillaEngine{
return this._engine;
}
/**
* 启动引擎
* @param containerElement
* @param options
* @param onProgress
*/
async launch(containerElement, options:any = {}, onProgress: Function) {
const engine = this._engine;
const manifest = await engine.assetsManager.loadJson('manifest.json');
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);
engine.assetsManager.setResPath(DEBUG ? 'assets/' : engineConfig.resPath);
let canvas = document.createElement('canvas');
containerElement.appendChild(canvas);
engineConfig.canvas = canvas;
engine.setup(engineConfig, customConfig);
let entryScene = options.scene || customConfig.scene.entryScene;
this.launchScene(entryScene, onProgress).catch(e => {
console.log(e);
});
}
/**
* 启动场景
* @param sceneNameOrPath
* @param progress
*/
async launchScene(sceneNameOrPath, progress?) {
const sceneConfig = this.engine.customConfig.scene;
let sceneFile = sceneConfig.scenes[sceneNameOrPath];
if(!sceneFile){
sceneFile = sceneNameOrPath;
}
const scene = await this.loadScene(sceneFile, 'scene_' + sceneFile);
this.resUUIDs = this._engine.assetsManager.getAllResUuids();
await scene.loadResGroup('preload', progress);
if(this.currentScene){
this.unmountScene(this.currentScene);
}
this.currentScene = scene;
this.mountScene(scene);
scene.loadResGroup('delay', progress);
}
/**
* 装载场景
* @param scene
*/
private mountScene(scene){
this._engine.pause();
scene.setup(this._engine.root);
this._engine.start();
}
/**
* 卸载场景
* @param scene
*/
private unmountScene(scene){
this._engine.pause();
cleanEntity(scene.root);
this._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 this._engine.assetsManager.loadJson5(url);
const scene = new Scene(this._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.
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