[add] EventBus使用

This commit is contained in:
建喵 2022-08-01 14:23:29 +08:00
parent 17b9af484e
commit cf95786b9c
34 changed files with 34622 additions and 635 deletions

51
Project/.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
/library/
/temp/
/local/
/build/
#/////////////////////////////////////////////////////////////////////////////
# npm files
#/////////////////////////////////////////////////////////////////////////////
npm-debug.log
node_modules/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.pidb
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# WebStorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code files
#//////////////////////////
.vscode/

2
Project/README.md Normal file
View File

@ -0,0 +1,2 @@
# hello-world
Hello world new project template.

12
Project/assets/Scene.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
{
"ver": "1.2.9",
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@ -0,0 +1,41 @@
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class HelloWorld extends cc.Component {
@property(cc.Label)
public Label: cc.Label = null;
@property
public Text: string = 'hello';
@property(cc.Button)
public Btn: cc.Button = null;
// LIFE-CYCLE CALLBACKS:
// protected onLoad() {}
public onClickBtn() {
let url: string = window.location.search;
let URLscheme: any[] = [];
if (url.indexOf("?") !== -1) {
let str = url.substring(1);
let strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
if (URLscheme["host"]) {
opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
window.close();
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "fdc7a7f1-b81c-4e03-b45f-06e57e3529a6",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,36 @@
{
"ver": "2.3.5",
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 195,
"height": 270,
"platformSettings": {},
"subMetas": {
"HelloWorld": {
"ver": "1.0.4",
"uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc",
"rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 195,
"height": 270,
"rawWidth": 195,
"rawHeight": 270,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

View File

@ -0,0 +1,36 @@
{
"ver": "2.3.5",
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 2,
"height": 2,
"platformSettings": {},
"subMetas": {
"singleColor": {
"ver": "1.0.4",
"uuid": "410fb916-8721-4663-bab8-34397391ace7",
"rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 2,
"height": 2,
"rawWidth": 2,
"rawHeight": 2,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

32073
Project/creator.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

15
Project/jsconfig.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
".vscode",
"library",
"local",
"settings",
"temp"
]
}

8
Project/project.json Normal file
View File

@ -0,0 +1,8 @@
{
"engine": "cocos2d-html5",
"packages": "packages",
"version": "2.4.4",
"name": "Project",
"id": "479e2add-b5da-4eaf-8a13-1c577012231c",
"isNew": false
}

View File

@ -0,0 +1,55 @@
{
"excludeScenes": [],
"orientation": {
"landscapeLeft": true,
"landscapeRight": true,
"portrait": false,
"upsideDown": false
},
"packageName": "org.cocos2d.helloworld",
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "hello_world",
"webOrientation": "auto",
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"mainCompressionType": "default",
"mainIsRemote": false,
"optimizeHotUpdate": false,
"md5Cache": false,
"nativeMd5Cache": true,
"encryptJs": true,
"xxteaKey": "436ef688-31f3-44",
"zipCompressJs": true,
"fb-instant-games": {},
"android": {
"REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo"
},
"ios": {
"REMOTE_SERVER_ROOT": "",
"ios_enable_jit": true,
"packageName": "org.cocos2d.demo"
},
"mac": {
"REMOTE_SERVER_ROOT": "",
"height": 720,
"packageName": "org.cocos2d.demo",
"width": 1280
},
"win32": {
"REMOTE_SERVER_ROOT": "",
"height": 720,
"width": 1280
},
"android-instant": {
"REMOTE_SERVER_ROOT": "",
"host": "",
"packageName": "org.cocos2d.demo",
"pathPattern": "",
"recordPath": "",
"scheme": "https",
"skipRecord": false
},
"appBundle": false,
"agreements": {}
}

View File

@ -0,0 +1,7 @@
{
"excludeScenes": [],
"packageName": "org.cocos2d.helloworld",
"platform": "web-mobile",
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "HelloWorld"
}

View File

@ -0,0 +1,24 @@
{
"collision-matrix": [
[
true
]
],
"excluded-modules": [],
"group-list": [
"default"
],
"start-scene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"design-resolution-width": 960,
"design-resolution-height": 640,
"fit-width": false,
"fit-height": true,
"use-project-simulator-setting": false,
"simulator-orientation": false,
"use-customize-simulator": false,
"simulator-resolution": {
"width": 960,
"height": 640
},
"last-module-event-record-time": 1659333193249
}

View File

@ -0,0 +1,6 @@
{
"game": {
"name": "未知游戏",
"appid": "UNKNOW"
}
}

BIN
Project/template-banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

5
Project/template.json Normal file
View File

@ -0,0 +1,5 @@
{
"name": "TEMPLATES.helloworld.name",
"desc": "TEMPLATES.helloworld.desc",
"banner": "template-banner.png"
}

19
Project/tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [ "es2015", "es2017", "dom" ],
"target": "es5",
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "temp/vscode-dist",
"forceConsistentCasingInFileNames": true
},
"exclude": [
"node_modules",
"library",
"local",
"temp",
"build",
"settings"
]
}

View File

@ -1,11 +1,22 @@
<script setup lang="ts">
import { ElDialog } from 'element-plus';
import { ref } from 'vue';
import 'vue-loading-overlay/dist/vue-loading.css';
import GameCanvas from './components/GameCanvas.vue';
import Popup from './components/Popup.vue';
const visible = ref(false)
window["eventBus"].on('alert', (msg: string) => {
visible.value = true;
})
</script>
<template>
<GameCanvas />
<el-dialog v-model="visible" :show-close="false">
<Popup />
</el-dialog>
</template>
<style>

11
src/components/Popup.vue Normal file
View File

@ -0,0 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue';
import 'vue-loading-overlay/dist/vue-loading.css';
const input = ref('')
</script>
<template>
<el-input v-model="input" placeholder="Please input A" />
<el-input v-model="input" placeholder="Please input B" />
</template>

View File

@ -1,26 +1,44 @@
{
"paths": {},
"uuids": [
"29FYIk+N1GYaeWH/q1NxQO",
"2dL3kvpAxJu6GJ7RdqJG5J",
"31vIlawANFZqnzLlSuHBfc",
"41D7kWhyFGY7q4NDlzkazn",
"6aoKpq6+5BVaCIpoemqt7E",
"a8Anh32NZGRZegUtSgEj26"
"71VhFCTINJM6/Ky3oX9nBT",
"a8Anh32NZGRZegUtSgEj26",
"b4P/PCArtIdIH38t6mlw8Y",
"e8Ueib+qJEhL6mXAHdnwbi",
"e97GVMl6JHh5Ml5qEDdSGa",
"ecpdLyjvZBwrvm+cedCcQy",
"f0BIwQ8D5Ml7nTNQbh1YlS"
],
"scenes": {
"db://assets/Scene/helloworld.fire": "2dL3kvpAxJu6GJ7RdqJG5J"
},
"redirect": [],
"deps": [],
"redirect": [
"ecpdLyjvZBwrvm+cedCcQy",
0
],
"deps": [
"internal"
],
"packs": {
"05dd1dc0e": [
"03f133834": [
"29FYIk+N1GYaeWH/q1NxQO",
"2dL3kvpAxJu6GJ7RdqJG5J",
"31vIlawANFZqnzLlSuHBfc",
"41D7kWhyFGY7q4NDlzkazn"
"41D7kWhyFGY7q4NDlzkazn",
"e97GVMl6JHh5Ml5qEDdSGa",
"f0BIwQ8D5Ml7nTNQbh1YlS"
],
"0cfd22b7a": [
"0e489d570": [
"6aoKpq6+5BVaCIpoemqt7E",
"a8Anh32NZGRZegUtSgEj26"
"71VhFCTINJM6/Ky3oX9nBT",
"a8Anh32NZGRZegUtSgEj26",
"b4P/PCArtIdIH38t6mlw8Y",
"e8Ueib+qJEhL6mXAHdnwbi"
]
},
"name": "main",

File diff suppressed because it is too large Load Diff

View File

@ -1,546 +0,0 @@
[
1,
[
"41D7kWhyFGY7q4NDlzkazn",
"31vIlawANFZqnzLlSuHBfc",
"6aoKpq6+5BVaCIpoemqt7E",
"a8Anh32NZGRZegUtSgEj26"
],
[
"node",
"_spriteFrame",
"_textureSetter",
"label",
"scene",
"_parent"
],
[
[
"cc.Node",
[
"_name",
"_id",
"_components",
"_contentSize",
"_color",
"_trs",
"_parent",
"_children"
],
1,
9,
5,
5,
7,
1,
2
],
"cc.SpriteFrame",
[
"cc.Widget",
[
"_alignFlags",
"_originalWidth",
"_originalHeight",
"_wasAlignOnce",
"node"
],
-1,
1
],
[
"cc.Sprite",
[
"_type",
"_sizeMode",
"node",
"_spriteFrame"
],
1,
1,
6
],
[
"cc.SceneAsset",
[
"_name",
"asyncLoadAssets"
],
1
],
[
"cc.Node",
[
"_name",
"_parent",
"_components",
"_contentSize",
"_trs"
],
2,
1,
2,
5,
7
],
[
"cc.Canvas",
[
"node"
],
3,
1
],
[
"e1b90/rohdEk4SdmmEZANaD",
[
"node",
"label"
],
3,
1,
1
],
[
"cc.Scene",
[
"_name",
"_children",
"_anchorPoint",
"_trs"
],
2,
2,
5,
7
],
[
"cc.Label",
[
"_string",
"_fontSize",
"_lineHeight",
"_N$horizontalAlign",
"_N$verticalAlign",
"node"
],
-2,
1
]
],
[
[
4,
0,
1,
3
],
[
0,
0,
1,
7,
2,
4,
3,
5,
3
],
[
0,
0,
6,
2,
4,
3,
2
],
[
0,
0,
6,
2,
3,
5,
2
],
[
5,
0,
1,
2,
3,
4,
2
],
[
6,
0,
1
],
[
7,
0,
1,
1
],
[
2,
0,
4,
2
],
[
2,
0,
1,
2,
3,
4,
5
],
[
3,
0,
1,
2,
3,
3
],
[
3,
2,
3,
1
],
[
8,
0,
1,
2,
3,
2
],
[
9,
0,
1,
2,
3,
4,
5,
6
]
],
[
[
[
[
0,
"helloworld",
null
],
[
1,
"Canvas",
"a286bbGknJLZpRpxROV6M94",
[
-5,
-6,
-7
],
[
[
5,
-1
],
[
6,
-3,
-2
],
[
7,
45,
-4
]
],
[
4,
4294769916
],
[
5,
960,
640
],
[
480,
320,
0,
0,
0,
0,
1,
1,
1,
1
]
],
[
2,
"background",
1,
[
[
8,
45,
200,
150,
{},
-8
],
[
9,
1,
0,
-9,
0
]
],
[
4,
4281214491
],
[
5,
960,
640
]
],
[
11,
"New Node",
[
1
],
[
0,
0,
0
],
[
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
],
[
3,
"cocos",
1,
[
[
10,
-10,
1
]
],
[
5,
195,
270
],
[
0,
50,
0,
0,
0,
0,
1,
1,
1,
1
]
],
[
4,
"label",
1,
[
-11
],
[
5,
342.33,
60
],
[
0,
-180,
0,
0,
0,
0,
1,
1,
1,
1
]
],
[
12,
"Hello, World!",
60,
60,
1,
1,
5
]
],
0,
[
0,
0,
1,
0,
3,
6,
0,
0,
1,
0,
0,
1,
0,
-1,
2,
0,
-2,
4,
0,
-3,
5,
0,
0,
2,
0,
0,
2,
0,
0,
4,
0,
-1,
6,
0,
4,
3,
1,
5,
3,
11
],
[
0,
0
],
[
1,
1
],
[
0,
1
]
],
[
[
{
"name": "HelloWorld",
"rect": [
0,
0,
195,
270
],
"offset": [
0,
0
],
"originalSize": [
195,
270
],
"capInsets": [
0,
0,
0,
0
]
}
],
[
1
],
0,
[
0
],
[
2
],
[
2
]
],
[
[
{
"name": "singleColor",
"rect": [
0,
0,
2,
2
],
"offset": [
0,
0
],
"originalSize": [
2,
2
],
"capInsets": [
0,
0,
0,
0
]
}
],
[
1
],
0,
[
0
],
[
2
],
[
3
]
]
]
]

View File

@ -1,4 +0,0 @@
{
"type": "cc.Texture2D",
"data": "0,9729,9729,33071,33071,0,0,1|0,9729,9729,33071,33071,0,0,1"
}

View File

@ -0,0 +1,4 @@
{
"type": "cc.Texture2D",
"data": "0,9729,9729,33071,33071,0,0,1|0,9729,9729,33071,33071,0,0,1|0,9729,9729,33071,33071,0,0,1|0,9729,9729,33071,33071,0,0,1|0,9729,9729,33071,33071,0,0,1"
}

View File

@ -15,7 +15,7 @@ window.__require = function e(t, n, r) {
var f = n[o] = {
exports: {}
};
t[o][0].call(f.exports, function(e) {
t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];
return s(n || e);
}, f, f.exports, e, t, n, r);
@ -26,22 +26,22 @@ window.__require = function e(t, n, r) {
for (var o = 0; o < r.length; o++) s(r[o]);
return s;
}({
Helloworld: [ function(require, module, exports) {
HelloWorld: [function (require, module, exports) {
"use strict";
cc._RF.push(module, "e1b90/rohdEk4SdmmEZANaD", "Helloworld");
cc._RF.push(module, "fdc7afxuBxOA7RfBuV+NSmm", "HelloWorld");
"use strict";
var __extends = this && this.__extends || function() {
var extendStatics = function(d, b) {
var __extends = this && this.__extends || function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(d, b) {
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function(d, b) {
} || function (d, b) {
for (var p in b) Object.prototype.hasOwnProperty.call(b, p) && (d[p] = b[p]);
};
return extendStatics(d, b);
};
return function(d, b) {
return function (d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
@ -49,7 +49,7 @@ window.__require = function e(t, n, r) {
d.prototype = null === b ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
var __decorate = this && this.__decorate || function(decorators, target, key, desc) {
var __decorate = this && this.__decorate || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if ("object" === typeof Reflect && "function" === typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
return c > 3 && r && Object.defineProperty(target, key, r), r;
@ -58,23 +58,41 @@ window.__require = function e(t, n, r) {
value: true
});
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Helloworld = function(_super) {
__extends(Helloworld, _super);
function Helloworld() {
var HelloWorld = function (_super) {
__extends(HelloWorld, _super);
function HelloWorld() {
var _this = null !== _super && _super.apply(this, arguments) || this;
_this.label = null;
_this.text = "hello";
_this.Label = null;
_this.Text = "hello";
_this.Btn = null;
return _this;
}
Helloworld.prototype.start = function() {
this.label.string = this.text;
HelloWorld.prototype.onClickBtn = function () {
var url = window.location.search;
var URLscheme = [];
if (-1 !== url.indexOf("?")) {
var str = url.substring(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
// if (URLscheme["host"]) {
if (window.location.host) {
// null === opener || void 0 === opener ? void 0 : opener.window.parent.postMessage({
// window.frames.postMessage({
// data: "hello"
// }, window.location.host);
// window.close();
window.eventBus.emit("alert", "hello");
return;
}
};
__decorate([ property(cc.Label) ], Helloworld.prototype, "label", void 0);
__decorate([ property ], Helloworld.prototype, "text", void 0);
Helloworld = __decorate([ ccclass ], Helloworld);
return Helloworld;
__decorate([property(cc.Label)], HelloWorld.prototype, "Label", void 0);
__decorate([property], HelloWorld.prototype, "Text", void 0);
__decorate([property(cc.Button)], HelloWorld.prototype, "Btn", void 0);
HelloWorld = __decorate([ccclass], HelloWorld);
return HelloWorld;
}(cc.Component);
exports.default = Helloworld;
exports.default = HelloWorld;
cc._RF.pop();
}, {} ]
}, {}, [ "Helloworld" ]);
}, {}]
}, {}, ["HelloWorld"]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB