Commit 2d0906a1 authored by rockyl's avatar rockyl

增加自定义模块模拟环境

parent 57589133
/**
* Created by rockyl on 2019-12-16.
*/
(async function () {
const customId = engine.queryParams.id;
console.log(customId);
let customModule = await fetch(`../dist/customs/${customId}.json`);
customModule = await customModule.json();
console.log(customModule);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
engine.globalEvent.addEventListener('update-game-status', (e)=>{
console.log(e.type, e.data);
});
engine.registerCustomCodeModule(customModule);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
customs: [customModule],
views: [{
name: 'entry',
type: 'node',
}],
}, null, null, function(){
engine.addCustomModule(customModule.id, engine.gameStage.sceneContainer.getChildAt(0));
setTimeout(()=>{
engine.globalEvent.dispatchEvent('start-game', {level: 1});
}, 500);
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom Emulator</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;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: transparent;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<!--script src="http://localhost:4002/debug/engine.js"></script-->
<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.d253f569148b2343d5d6cc212e95f8237d52be24.js"></script>
<script src="app.js"></script>
<script>
</script>
</body>
\ No newline at end of file
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
"props": {}, "props": {},
"assets": [ "assets": [
{ {
"uuid": "20191216114509",
"url": "//yun.duiba.com.cn/aurora/af90069732223c75818c4799b3130bd0f0ad4ff8.png", "url": "//yun.duiba.com.cn/aurora/af90069732223c75818c4799b3130bd0f0ad4ff8.png",
"ext": ".png" "ext": ".png"
} }
], ],
"id": "test1", "id": "test1",
"code": "'use strict';\n\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nfunction __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\n\nvar Test1 = (function (_super) {\n __extends(Test1, _super);\n function Test1() {\n var _this = _super.call(this) || this;\n var rect = new engine.Rect();\n rect.width = 100;\n rect.height = 100;\n _this.addChild(rect);\n return _this;\n }\n return Test1;\n}(engine.Container));\n\nfunction index (options) {\n var instance = new Test1();\n return instance;\n}\n\nmodule.exports = index;\n" "code": "'use strict';\n\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nfunction __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\n\nvar Test1 = (function (_super) {\n __extends(Test1, _super);\n function Test1() {\n var _this = _super.call(this) || this;\n var sprite = new engine.Sprite(engine.Texture.from('20191216114509'));\n _this.addChild(sprite);\n sprite.addEventListener(engine.MouseEvent.CLICK, _this.onClick, _this);\n engine.globalEvent.addEventListener('start-game', _this.onGameStart, _this);\n return _this;\n }\n Test1.prototype.onClick = function (e) {\n engine.globalEvent.dispatchEvent('update-game-status', { score: 1 });\n };\n Test1.prototype.onGameStart = function (e) {\n console.log(e.type, e.data);\n var rect = new engine.Rect();\n rect.x = 100;\n rect.y = 100;\n rect.width = 100;\n rect.height = 100;\n rect.fillColor = 'green';\n this.addChild(rect);\n };\n return Test1;\n}(engine.Container));\n\nfunction index (options) {\n var instance = new Test1();\n return instance;\n}\n\nmodule.exports = index;\n"
} }
{ {
"name": "process-lib", "name": "process-lib",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build-process": "node scripts/compiler-process", "build-process": "node scripts/compiler-process",
"build-script": "node scripts/compiler-script", "build-script": "node scripts/compiler-script",
"build-custom": "node scripts/compiler-custom" "build-custom": "node scripts/compiler-custom"
}, },
"devDependencies": { "devDependencies": {
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-progress": "^1.1.1", "rollup-plugin-progress": "^1.1.1",
"rollup-plugin-typescript": "^1.0.1", "rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-uglify": "^6.0.3", "rollup-plugin-uglify": "^6.0.3",
"tslib": "^1.10.0", "tslib": "^1.10.0",
"typescript": "^3.7.2" "typescript": "^3.7.2",
}, "glob": "^7.1.6",
"dependencies": { "rollup": "^1.27.13"
"glob": "^7.1.6", },
"rollup": "^1.27.4" "dependencies": {
} }
} }
...@@ -29,7 +29,7 @@ const [_, __, sourcePath, outputPath = 'dist/customs'] = process.argv; ...@@ -29,7 +29,7 @@ const [_, __, sourcePath, outputPath = 'dist/customs'] = process.argv;
async function compileProcess(sourcePath, output) { async function compileProcess(sourcePath, output) {
const id = sourcePath; const id = sourcePath;
const meta = fs.readJsonSync(path.join('src/custom/' + sourcePath, 'meta.json')); const meta = fs.readJsonSync(path.join('src/custom/' + sourcePath, 'meta.json'));
const result = await compile('src/custom/' + sourcePath, false); const result = await compile('src/custom/' + sourcePath + '/index.ts', false);
meta.id = id; meta.id = id;
if(result){ if(result){
meta.code = result.code; meta.code = result.code;
...@@ -38,7 +38,7 @@ async function compileProcess(sourcePath, output) { ...@@ -38,7 +38,7 @@ async function compileProcess(sourcePath, output) {
const outputPath = path.join(output, sourcePath); const outputPath = path.join(output, sourcePath);
fs.ensureDirSync(path.dirname(outputPath)); fs.ensureDirSync(path.dirname(outputPath));
fs.writeJsonSync(outputPath + '.json', meta, {spaces: ' '}); fs.writeJsonSync(outputPath + '.json', meta, {spaces: ' '});
fs.writeFileSync(outputPath + '.js', code); //fs.writeFileSync(outputPath + '.js', result.code);
/*fs.writeJsonSync(outputPath + '-req.json', { /*fs.writeJsonSync(outputPath + '-req.json', {
data: JSON.stringify(meta) data: JSON.stringify(meta)
});*/ });*/
......
...@@ -2,13 +2,31 @@ ...@@ -2,13 +2,31 @@
* Created by rockyl on 2019-11-22. * Created by rockyl on 2019-11-22.
*/ */
export class Test1 extends engine.Container{ export class Test1 extends engine.Container {
constructor(){ constructor() {
super(); super();
let sprite = new engine.Sprite(engine.Texture.from('20191216114509'));
this.addChild(sprite);
sprite.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
engine.globalEvent.addEventListener('start-game', this.onGameStart, this);
}
private onClick(e){
engine.globalEvent.dispatchEvent('update-game-status', {score: 1});
}
private onGameStart(e){
console.log(e.type, e.data);
let rect = new engine.Rect(); let rect = new engine.Rect();
rect.x = 100;
rect.y = 200;
rect.width = 100; rect.width = 100;
rect.height = 100; rect.height = 100;
rect.fillColor = 'green';
this.addChild(rect); this.addChild(rect);
} }
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
}, },
"assets": [ "assets": [
{ {
"uuid": "20191216114509",
"url": "//yun.duiba.com.cn/aurora/af90069732223c75818c4799b3130bd0f0ad4ff8.png", "url": "//yun.duiba.com.cn/aurora/af90069732223c75818c4799b3130bd0f0ad4ff8.png",
"ext": ".png" "ext": ".png"
} }
......
...@@ -289,10 +289,10 @@ rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.8.1: ...@@ -289,10 +289,10 @@ rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.8.1:
dependencies: dependencies:
estree-walker "^0.6.1" estree-walker "^0.6.1"
rollup@^1.27.4: rollup@^1.27.13:
version "1.27.4" version "1.27.13"
resolved "https://registry.npm.taobao.org/rollup/download/rollup-1.27.4.tgz?cache=0&sync_timestamp=1574409829143&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Frollup%2Fdownload%2Frollup-1.27.4.tgz#5bca607a10c99c034288de9f9c756f9fe1a08431" resolved "https://registry.npm.taobao.org/rollup/download/rollup-1.27.13.tgz#d6d3500512daacbf8de54d2800de62d893085b90"
integrity sha1-W8pgehDJnANCiN6fnHVvn+GghDE= integrity sha1-1tNQBRLarL+N5U0oAN5i2JMIW5A=
dependencies: dependencies:
"@types/estree" "*" "@types/estree" "*"
"@types/node" "*" "@types/node" "*"
......
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