protobuf归类
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
6
protubuf/protobuf-egret/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
egret-project/bin-debug
|
||||
egret-project/libs
|
||||
egret-project/protobuf
|
||||
egret-project_wxgame/js
|
||||
egret-project_wxgame/resource
|
||||
2
protubuf/protobuf-egret/.npmignore
Normal file
@@ -0,0 +1,2 @@
|
||||
egret-project
|
||||
egret-project_wxgame
|
||||
74
protubuf/protobuf-egret/README.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# egret protobuf
|
||||
|
||||
## 特性
|
||||
|
||||
|
||||
1. 提供 protobuf.js 基础运行时库
|
||||
2. 提供命令行脚本,将 protofile 生成 JavaScript 代码
|
||||
3. 生成正确的 .d.ts 代码,以方便 TypeScript 项目使用
|
||||
4. 一键配置白鹭引擎的配置文件,无需开发者手动修改配置即可在项目中直接集成
|
||||
5. 本项目虽然名为 egret protobuf ,但是理论上支持所有 HTML5 游戏引擎。欢迎使用 PIXI.js , Cocos2d-js , LayaAir 等其他引擎的开发者使用本库。
|
||||
|
||||
## 原理
|
||||
|
||||
封装了 protobufjs 库及命令行。使用 protobufjs 6.8.4 的运行时库。
|
||||
|
||||
protobufjs 自身存在着 pbts 命令,虽然也可以生成 .d.ts 文件,但是在全局模式而非 ES6 module 的情况下存在一些错误,本项目致力于解决这个问题,使 protobufjs 可以在非 ES6 模块项目中(比如白鹭引擎)中也可以使用 protobufjs
|
||||
|
||||
protobufjs 提供了多种使用方式,由于微信小游戏禁止 eval , new Function 等动态代码形式,所以本项目只提供了生成代码的形式,不支持通过 ```protobuf.load('awesome.proto')``` 的方式(因为这种方式也无法在微信小游戏中运行)。
|
||||
|
||||
|
||||
## 如何安装
|
||||
|
||||
```
|
||||
npm install protobufjs@6.8.4 -g
|
||||
npm install @egret/protobuf -g
|
||||
```
|
||||
|
||||
## 如何使用
|
||||
|
||||
```
|
||||
# 假设用户有个名为 egret-project 的白鹭项目
|
||||
cd egret-project
|
||||
# 将代码和项目结构拷贝至白鹭项目中
|
||||
pb-egret add
|
||||
# 将 protofile 文件放在 egret-project/protobuf/protofile 文件夹中
|
||||
pb-egret generate
|
||||
# 文件将会生成到 protobuf/bundles 文件夹中
|
||||
|
||||
```
|
||||
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 1.2.0
|
||||
|
||||
添加 keepCase 支持
|
||||
|
||||
|
||||
### 1.1.1
|
||||
|
||||
添加 pbconfig.json
|
||||
|
||||
### 1.0.7
|
||||
|
||||
初始版本
|
||||
|
||||
|
||||
## 如何运行 Demo
|
||||
|
||||
下载源代码,使用 ```egret run egret-project ```即可直接运行 demo 项目
|
||||
|
||||
## 已知问题
|
||||
|
||||
proto 文件中的每一个协议一定要从属于一个 package,否则.d.ts生成会出现错误导致 ts 文件无法正确的找到这些类
|
||||
|
||||
|
||||
## 路线图
|
||||
|
||||
* 使用 profobuf 配置文件
|
||||
* 集成 egret 构建管线
|
||||
|
||||
|
||||
|
||||
|
||||
2653
protubuf/protobuf-egret/dist/protobuf-library.d.ts
vendored
Normal file
8567
protubuf/protobuf-egret/dist/protobuf-library.js
vendored
Normal file
1
protubuf/protobuf-egret/dist/protobuf-library.min.js
vendored
Normal file
41
protubuf/protobuf-egret/egret-project/egretProperties.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"engineVersion": "5.1.2",
|
||||
"compilerVersion": "5.1.2",
|
||||
"template": {},
|
||||
"target": {
|
||||
"current": "web"
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "egret"
|
||||
},
|
||||
{
|
||||
"name": "game"
|
||||
},
|
||||
{
|
||||
"name": "tween"
|
||||
},
|
||||
{
|
||||
"name": "assetsmanager"
|
||||
},
|
||||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "protobuf-library",
|
||||
"path": "protobuf/library"
|
||||
},
|
||||
{
|
||||
"name": "protobuf-bundles",
|
||||
"path": "protobuf/bundles"
|
||||
},
|
||||
{
|
||||
"name": "protobuf-library",
|
||||
"path": "protobuf/library"
|
||||
},
|
||||
{
|
||||
"name": "protobuf-bundles",
|
||||
"path": "protobuf/bundles"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
protubuf/protobuf-egret/egret-project/favicon.ico
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
96
protubuf/protobuf-egret/egret-project/index.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Egret</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 {
|
||||
-ms-touch-action: none;
|
||||
background: #888888;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="margin: auto;width: 100%;height: 100%;" class="egret-player"
|
||||
data-entry-class="Main"
|
||||
data-orientation="auto"
|
||||
data-scale-mode="showAll"
|
||||
data-frame-rate="30"
|
||||
data-content-width="640"
|
||||
data-content-height="1136"
|
||||
data-show-paint-rect="false"
|
||||
data-multi-fingered="2"
|
||||
data-show-fps="false" data-show-log="false"
|
||||
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
|
||||
</div>
|
||||
<script>
|
||||
var loadScript = function (list, callback) {
|
||||
var loaded = 0;
|
||||
var loadNext = function () {
|
||||
loadSingleScript(list[loaded], function () {
|
||||
loaded++;
|
||||
if (loaded >= list.length) {
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
loadNext();
|
||||
}
|
||||
})
|
||||
};
|
||||
loadNext();
|
||||
};
|
||||
|
||||
var loadSingleScript = function (src, callback) {
|
||||
var s = document.createElement('script');
|
||||
s.async = false;
|
||||
s.src = src;
|
||||
s.addEventListener('load', function () {
|
||||
s.parentNode.removeChild(s);
|
||||
s.removeEventListener('load', arguments.callee, false);
|
||||
callback();
|
||||
}, false);
|
||||
document.body.appendChild(s);
|
||||
};
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', './manifest.json?v=' + Math.random(), true);
|
||||
xhr.addEventListener("load", function () {
|
||||
var manifest = JSON.parse(xhr.response);
|
||||
var list = manifest.initial.concat(manifest.game);
|
||||
loadScript(list, function () {
|
||||
/**
|
||||
* {
|
||||
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
|
||||
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
|
||||
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
|
||||
* "calculateCanvasScaleFactor": //a function return canvas scale factor
|
||||
* }
|
||||
**/
|
||||
egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) {
|
||||
var backingStore = context.backingStorePixelRatio ||
|
||||
context.webkitBackingStorePixelRatio ||
|
||||
context.mozBackingStorePixelRatio ||
|
||||
context.msBackingStorePixelRatio ||
|
||||
context.oBackingStorePixelRatio ||
|
||||
context.backingStorePixelRatio || 1;
|
||||
return (window.devicePixelRatio || 1) / backingStore;
|
||||
}});
|
||||
});
|
||||
});
|
||||
xhr.send(null);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
17
protubuf/protobuf-egret/egret-project/manifest.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"initial": [
|
||||
"libs/modules/egret/egret.js",
|
||||
"libs/modules/egret/egret.web.js",
|
||||
"libs/modules/game/game.js",
|
||||
"libs/modules/tween/tween.js",
|
||||
"libs/modules/assetsmanager/assetsmanager.js",
|
||||
"libs/modules/promise/promise.js",
|
||||
"protobuf/library/protobuf-library.js",
|
||||
"protobuf/bundles/protobuf-bundles.js"
|
||||
],
|
||||
"game": [
|
||||
"bin-debug/LoadingUI.js",
|
||||
"bin-debug/Main.js",
|
||||
"bin-debug/Platform.js"
|
||||
]
|
||||
}
|
||||
BIN
protubuf/protobuf-egret/egret-project/resource/assets/bg.jpg
Normal file
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 6.6 KiB |
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"<font color=0x00ff0c>Open-source</font>,<font color=0x00ff0c>Free</font>,<font color=0x00ff0c>Multi-platform</font>",
|
||||
"Push <font color=0x00ff0c>Game </font>Forward",
|
||||
"<font color=0x00ff0c>HTML5 </font>Game Engine"
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"groups":[
|
||||
{
|
||||
"keys":"bg_jpg,egret_icon_png,description_json",
|
||||
"name":"preload"
|
||||
}],
|
||||
"resources":[
|
||||
{
|
||||
"name":"bg_jpg",
|
||||
"type":"image",
|
||||
"url":"assets/bg.jpg"
|
||||
},
|
||||
{
|
||||
"name":"egret_icon_png",
|
||||
"type":"image",
|
||||
"url":"assets/egret_icon.png"
|
||||
},
|
||||
{
|
||||
"name":"description_json",
|
||||
"type":"json",
|
||||
"url":"config/description.json"
|
||||
}]
|
||||
}
|
||||
310
protubuf/protobuf-egret/egret-project/scripts/api.d.ts
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
|
||||
/**
|
||||
* ResourceManager 配置文件
|
||||
*/
|
||||
type ResourceManagerConfig = {
|
||||
/**
|
||||
* 配置文件生成路径
|
||||
*/
|
||||
configPath: string,
|
||||
/**
|
||||
* 资源根目录路径
|
||||
*/
|
||||
resourceRoot: () => string,
|
||||
/**
|
||||
* 构建与发布配置
|
||||
*/
|
||||
buildConfig: (param: BuildConfigParam) => UserConfig,
|
||||
/**
|
||||
* 设置资源类型
|
||||
*/
|
||||
typeSelector: (path: string) => (string | null | undefined)
|
||||
/**
|
||||
* 设置资源的合并策略
|
||||
*/
|
||||
mergeSelector?: (path: string) => (string | null | undefined),
|
||||
/**
|
||||
* 设置资源的命名策略
|
||||
* beta 功能,请勿随意使用
|
||||
*/
|
||||
nameSelector?: (path: string) => (string | null | undefined)
|
||||
}
|
||||
/**
|
||||
* 构建配置
|
||||
*/
|
||||
type UserConfig = {
|
||||
/**
|
||||
* 输出路径
|
||||
*/
|
||||
outputDir: string,
|
||||
/**
|
||||
* 插件
|
||||
*/
|
||||
commands: (string | plugins.Command) []
|
||||
}
|
||||
|
||||
type BuildConfigParam = {
|
||||
|
||||
|
||||
/**
|
||||
* 当前命令,build 或者 command
|
||||
*/
|
||||
readonly command: string;
|
||||
|
||||
/**
|
||||
* 发布平台
|
||||
*/
|
||||
readonly target: string;
|
||||
|
||||
/**
|
||||
* 开发者指定的版本号
|
||||
*/
|
||||
readonly version: string;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
readonly projectName: string;
|
||||
|
||||
/**
|
||||
* 项目路径
|
||||
*/
|
||||
readonly projectRoot: string;
|
||||
}
|
||||
|
||||
|
||||
declare namespace plugins {
|
||||
|
||||
interface CommandContext {
|
||||
|
||||
/**
|
||||
* 可以用此接口进行文件创建
|
||||
*/
|
||||
createFile(relativeFilePath: string, contents: Buffer);
|
||||
|
||||
/**
|
||||
* 构建配置
|
||||
*/
|
||||
buildConfig: BuildConfigParam;
|
||||
|
||||
/**
|
||||
* 项目绝对路径
|
||||
*/
|
||||
projectRoot: string;
|
||||
|
||||
/**
|
||||
* 项目输出绝对路径
|
||||
*/
|
||||
outputDir: string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建管线命令
|
||||
*/
|
||||
interface Command {
|
||||
|
||||
/**
|
||||
* 项目中的每个文件都会执行此函数,返回 file 表示保留此文件,返回 null 表示将此文件从构建管线中删除,即不会发布
|
||||
*/
|
||||
onFile?(file: File): Promise<File | null>
|
||||
|
||||
/**
|
||||
* 项目中所有文件均执行完后,最终会执行此函数。
|
||||
* 这个函数主要被用于创建新文件
|
||||
*/
|
||||
onFinish?(pluginContext?: CommandContext): Promise<void>
|
||||
|
||||
[options: string]: any;
|
||||
}
|
||||
|
||||
interface File {
|
||||
|
||||
/**
|
||||
* 文件内容的二进制流,如果开发者需要修改文件内容,请修改此属性
|
||||
*/
|
||||
contents: Buffer;
|
||||
|
||||
|
||||
/**
|
||||
* 文件绝对路径,如果开发者需要对文件进行重命名,请修改此属性
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* 文件所在的项目的项目路径
|
||||
*/
|
||||
readonly base: string;
|
||||
|
||||
/**
|
||||
* 文件的相对于 base 属性的相对路径
|
||||
*/
|
||||
readonly relative: string;
|
||||
|
||||
|
||||
/**
|
||||
* 文件变更历史,history[0] 即 origin 属性
|
||||
*/
|
||||
readonly history: ReadonlyArray<string>;
|
||||
|
||||
|
||||
/**
|
||||
* 文件所在的文件夹的绝对路径
|
||||
*/
|
||||
readonly dirname: string;
|
||||
|
||||
/**
|
||||
* 文件的文件名
|
||||
*/
|
||||
readonly basename: string;
|
||||
|
||||
|
||||
/**
|
||||
* 文件的扩展名
|
||||
*/
|
||||
readonly extname: string;
|
||||
|
||||
/**
|
||||
* 文件的初始文件名
|
||||
*/
|
||||
readonly origin: string;
|
||||
|
||||
/**
|
||||
* 其他自定义属性
|
||||
*/
|
||||
[customProperty: string]: any;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
declare module 'built-in' {
|
||||
|
||||
/**
|
||||
* 混淆插件参数,设置源代码和目标代码
|
||||
*/
|
||||
type UglifyPluginOption = { sources: string[], target: string };
|
||||
|
||||
type UglifyPluginOptions = UglifyPluginOption[];
|
||||
|
||||
/**
|
||||
* 混淆插件
|
||||
*/
|
||||
export class UglifyPlugin implements plugins.Command {
|
||||
|
||||
constructor(mergeSelector: UglifyPluginOptions);
|
||||
|
||||
}
|
||||
|
||||
|
||||
type LibraryType = "debug" | "release";
|
||||
|
||||
type CompilePluginOptions = { libraryType: LibraryType };
|
||||
/**
|
||||
* 编译命令
|
||||
*/
|
||||
export class CompilePlugin implements plugins.Command {
|
||||
|
||||
constructor(options: CompilePluginOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* EXML 插件,用于发布 EXML 文件
|
||||
*/
|
||||
export class ExmlPlugin implements plugins.Command {
|
||||
|
||||
constructor(publishPolicy: EXML_Publish_Policy);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布策略
|
||||
* * default : 使用 egretProperties.json 中的 exmlPublishPolicy 中的策略
|
||||
* * debug : 默认策略,用于开发环境
|
||||
* * contents : 将 EXML 的内容写入到主题文件中
|
||||
* * gjs : 将生成的JS文件写入到主题文件中
|
||||
* * commonjs : 将EXML合并为一个 CommonJS 风格的文件
|
||||
*/
|
||||
type EXML_Publish_Policy = "default" | "debug" | "contents" | "gjs" | "commonjs"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成 manifest 文件,这个文件会被用于记录 JavaScript 文件的版本号
|
||||
*/
|
||||
export class ManifestPlugin implements plugins.Command {
|
||||
constructor(options?: ManifestPluginOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文件的文件名
|
||||
* 支持 json 与 js 两种格式
|
||||
*/
|
||||
type ManifestPluginOptions = {
|
||||
|
||||
output: string,
|
||||
|
||||
hash?: "crc32",
|
||||
|
||||
/**
|
||||
* 是否输出转换过程
|
||||
*/
|
||||
verbose?: boolean
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* EmitResConfigFilePlugin 的参数
|
||||
* * output: 生成路径,可以指定生成为 *.res.js 文件或者 *.res.json 文件
|
||||
* * typeSelector: 根据文件路径决定文件类型
|
||||
* * nameSelector: 根据文件路径决定文件的资源名
|
||||
* * groupSelector: 根据文件路径决定资源所述的资源组
|
||||
*/
|
||||
type EmitResConfigFilePluginOptions = {
|
||||
output: string,
|
||||
typeSelector: (path: string) => string | null | undefined,
|
||||
nameSelector: (path: string) => string | null | undefined,
|
||||
groupSelector: (path: string) => string | null | undefined,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成 res.json 文件或者 res.js 文件
|
||||
*/
|
||||
export class EmitResConfigFilePlugin implements plugins.Command {
|
||||
|
||||
constructor(options: EmitResConfigFilePluginOptions)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增量编译
|
||||
* 这个插件生成的 JavaScript 代码不会被添加到构建管线中,后续其他插件无法获取生成的 js 文件
|
||||
* 这个功能将会在未来被 watch 模式代替掉
|
||||
*/
|
||||
export class IncrementCompilePlugin implements plugins.Command {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 TextureMerger 实现纹理自动合并,依赖 TextureMerger 1.7 以上的版本
|
||||
*/
|
||||
export class TextureMergerPlugin implements plugins.Command {
|
||||
|
||||
constructor();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
|
||||
type ManifestConfig = {
|
||||
|
||||
initial: string[],
|
||||
|
||||
game: string[]
|
||||
|
||||
}
|
||||
|
||||
export class BricksPlugin implements plugins.Command {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
async onFile(file: plugins.File) {
|
||||
const filename = file.origin;
|
||||
if (filename == 'manifest.json') {
|
||||
const contents = file.contents.toString();
|
||||
const jsonData: ManifestConfig = JSON.parse(contents);
|
||||
|
||||
let content = '';
|
||||
|
||||
for (let item of jsonData.initial) {
|
||||
if (item != 'js/promise.js' && item != 'js/promise.min.js') {
|
||||
content += `BK.Script.loadlib("GameRes://${item}");\n`
|
||||
}
|
||||
if (item == "js/egret.js" || item == 'js/egret.min.js') {
|
||||
content += `BK.Script.loadlib("GameRes://egret.bricks.js");\n`
|
||||
}
|
||||
}
|
||||
for (let item of jsonData.game) {
|
||||
content += `BK.Script.loadlib("GameRes://${item}");\n`
|
||||
}
|
||||
file.path = file.dirname + '/manifest.js'
|
||||
file.contents = new Buffer(content);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
async onFinish(pluginContext) {
|
||||
|
||||
}
|
||||
}
|
||||
127
protubuf/protobuf-egret/egret-project/scripts/config.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
/// 阅读 api.d.ts 查看文档
|
||||
///<reference path="api.d.ts"/>
|
||||
|
||||
import * as path from 'path';
|
||||
import { UglifyPlugin, IncrementCompilePlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin } from 'built-in';
|
||||
import { WxgamePlugin } from './wxgame/wxgame';
|
||||
import { BricksPlugin } from './bricks/bricks';
|
||||
import { CustomPlugin } from './myplugin';
|
||||
|
||||
const config: ResourceManagerConfig = {
|
||||
|
||||
configPath: 'config.res.js',
|
||||
|
||||
resourceRoot: () => "resource",
|
||||
|
||||
buildConfig: (params) => {
|
||||
|
||||
|
||||
|
||||
const { target, command, projectName, version } = params;
|
||||
|
||||
if (target == 'wxgame') {
|
||||
const outputDir = `../${projectName}_wxgame`;
|
||||
return {
|
||||
outputDir,
|
||||
commands: [
|
||||
new CompilePlugin({ libraryType: "release" }),
|
||||
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
|
||||
new WxgamePlugin(),
|
||||
new UglifyPlugin([{
|
||||
sources: ["main.js"],
|
||||
target: "main.min.js"
|
||||
}
|
||||
]),
|
||||
new ManifestPlugin({ output: 'manifest.js' })
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (target == 'bricks') {
|
||||
const outputDir = `../${projectName}_bricks/PublicBrickEngineGame/Res`;
|
||||
return {
|
||||
outputDir,
|
||||
commands: [
|
||||
new CompilePlugin({ libraryType: "debug" }),
|
||||
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
|
||||
new ManifestPlugin({ output: 'manifest.json' }),
|
||||
new BricksPlugin()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (command == 'build') {
|
||||
const outputDir = '.';
|
||||
return {
|
||||
outputDir,
|
||||
commands: [
|
||||
// new EmitResConfigFilePlugin({
|
||||
// output: "resource/default.res.json",
|
||||
// typeSelector: config.typeSelector,
|
||||
// nameSelector: p => path.basename(p).replace(/\./gi, "_"),
|
||||
// groupSelector: p => "preload"
|
||||
// }),
|
||||
new ExmlPlugin('debug'), // 非 EUI 项目关闭此设置
|
||||
new IncrementCompilePlugin(),
|
||||
]
|
||||
}
|
||||
}
|
||||
else if (command == 'publish') {
|
||||
const outputDir = `bin-release/web/${version}`;
|
||||
return {
|
||||
outputDir,
|
||||
commands: [
|
||||
new CustomPlugin(),
|
||||
new CompilePlugin({ libraryType: "release" }),
|
||||
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
|
||||
new UglifyPlugin([{
|
||||
sources: ["main.js"],
|
||||
target: "main.min.js"
|
||||
}]),
|
||||
new ManifestPlugin({ output: "manifest.json", hash: "crc32" })
|
||||
]
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw `unknown command : ${params.command}`
|
||||
}
|
||||
},
|
||||
|
||||
mergeSelector: (path) => {
|
||||
if (path.indexOf("assets/bitmap/") >= 0) {
|
||||
return "assets/bitmap/sheet.sheet"
|
||||
}
|
||||
else if (path.indexOf("armature") >= 0 && path.indexOf(".json") >= 0) {
|
||||
return "assets/armature/1.zip";
|
||||
}
|
||||
},
|
||||
|
||||
typeSelector: (path) => {
|
||||
const ext = path.substr(path.lastIndexOf(".") + 1);
|
||||
const typeMap = {
|
||||
"jpg": "image",
|
||||
"png": "image",
|
||||
"webp": "image",
|
||||
"json": "json",
|
||||
"fnt": "font",
|
||||
"pvr": "pvr",
|
||||
"mp3": "sound",
|
||||
"zip": "zip",
|
||||
"sheet": "sheet",
|
||||
"exml": "text"
|
||||
}
|
||||
let type = typeMap[ext];
|
||||
if (type == "json") {
|
||||
if (path.indexOf("sheet") >= 0) {
|
||||
type = "sheet";
|
||||
} else if (path.indexOf("movieclip") >= 0) {
|
||||
type = "movieclip";
|
||||
};
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export = config;
|
||||
17
protubuf/protobuf-egret/egret-project/scripts/myplugin.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 示例自定义插件,您可以查阅 http://developer.egret.com/cn/2d/projectConfig/cmdExtensionPluginin/
|
||||
* 了解如何开发一个自定义插件
|
||||
*/
|
||||
export class CustomPlugin implements plugins.Command {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
async onFile(file: plugins.File) {
|
||||
return file;
|
||||
}
|
||||
|
||||
async onFinish(commandContext: plugins.CommandContext) {
|
||||
|
||||
}
|
||||
}
|
||||
4209
protubuf/protobuf-egret/egret-project/scripts/node.d.ts
vendored
Normal file
50
protubuf/protobuf-egret/egret-project/scripts/tsconfig.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
|
||||
"lib": [
|
||||
"es5",
|
||||
"es2015.promise"
|
||||
], /* Specify library files to be included in the compilation: */
|
||||
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
/* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
export class WxgamePlugin implements plugins.Command {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
async onFile(file: plugins.File) {
|
||||
if (file.extname == '.js') {
|
||||
const filename = file.origin;
|
||||
if (filename == "libs/modules/promise/promise.js" || filename == 'libs/modules/promise/promise.min.js') {
|
||||
return null;
|
||||
}
|
||||
if (filename == 'libs/modules/egret/egret.js' || filename == 'libs/modules/egret/egret.min.js') {
|
||||
let content = file.contents.toString();
|
||||
content += `;window.egret = egret;`;
|
||||
content = content.replace(/definition = __global/, "definition = window");
|
||||
file.contents = new Buffer(content);
|
||||
}
|
||||
else {
|
||||
let content = file.contents.toString();
|
||||
if (
|
||||
filename == "libs/modules/res/res.js" ||
|
||||
filename == 'libs/modules/res/res.min.js' ||
|
||||
filename == 'libs/modules/assetsmanager/assetsmanager.min.js' ||
|
||||
filename == 'libs/modules/assetsmanager/assetsmanager.js'
|
||||
) {
|
||||
content += ";window.RES = RES;"
|
||||
}
|
||||
if (filename == "libs/modules/eui/eui.js" || filename == 'libs/modules/eui/eui.min.js') {
|
||||
content += ";window.eui = eui;"
|
||||
}
|
||||
if (filename == 'libs/modules/dragonBones/dragonBones.js' || filename == 'libs/modules/dragonBones/dragonBones.min.js') {
|
||||
content += ';window.dragonBones = dragonBones';
|
||||
}
|
||||
content = "var egret = window.egret;" + content;
|
||||
if (filename == 'main.js') {
|
||||
content += ";window.Main = Main;"
|
||||
}
|
||||
file.contents = new Buffer(content);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
async onFinish(pluginContext) {
|
||||
|
||||
}
|
||||
}
|
||||
51
protubuf/protobuf-egret/egret-project/src/LoadingUI.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.createView();
|
||||
}
|
||||
|
||||
private textField: egret.TextField;
|
||||
|
||||
private createView(): void {
|
||||
this.textField = new egret.TextField();
|
||||
this.addChild(this.textField);
|
||||
this.textField.y = 300;
|
||||
this.textField.width = 480;
|
||||
this.textField.height = 100;
|
||||
this.textField.textAlign = "center";
|
||||
}
|
||||
|
||||
public onProgress(current: number, total: number): void {
|
||||
this.textField.text = `Loading...${current}/${total}`;
|
||||
}
|
||||
}
|
||||
238
protubuf/protobuf-egret/egret-project/src/Main.ts
Normal file
@@ -0,0 +1,238 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Main extends egret.DisplayObjectContainer {
|
||||
|
||||
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
|
||||
}
|
||||
|
||||
private onAddToStage(event: egret.Event) {
|
||||
|
||||
|
||||
// awesomepackage.AwesomeMessage.
|
||||
// let root = protobuf.Root.fromJSON(data);
|
||||
|
||||
// // Obtain a message type
|
||||
// var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
||||
|
||||
// Exemplary payload
|
||||
var payload = { awesomeField: "AwesomeString" };
|
||||
|
||||
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
|
||||
var errMsg = awesomepackage.AwesomeMessage.verify(payload);
|
||||
if (errMsg)
|
||||
throw Error(errMsg);
|
||||
// Create a new message
|
||||
var message = awesomepackage.AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
|
||||
console.log('message', message)
|
||||
// Encode a message to an Uint8Array (browser) or Buffer (node)
|
||||
var buffer = awesomepackage.AwesomeMessage.encode(message).finish();
|
||||
// ... do something with buffer
|
||||
console.log('buffer', buffer)
|
||||
// Decode an Uint8Array (browser) or Buffer (node) to a message
|
||||
var message = awesomepackage.AwesomeMessage.decode(buffer);
|
||||
|
||||
console.log('message', message)
|
||||
// ... do something with message
|
||||
// If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
|
||||
|
||||
// Maybe convert the message back to a plain object
|
||||
var object = awesomepackage.AwesomeMessage.toObject(message, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String,
|
||||
// see ConversionOptions
|
||||
});
|
||||
|
||||
console.log('object', object)
|
||||
|
||||
|
||||
// protobuf.load("awesome.proto", function (err, root) {
|
||||
|
||||
|
||||
|
||||
|
||||
// });
|
||||
|
||||
|
||||
|
||||
|
||||
egret.lifecycle.addLifecycleListener((context) => {
|
||||
// custom lifecycle plugin
|
||||
|
||||
context.onUpdate = () => {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
egret.lifecycle.onPause = () => {
|
||||
egret.ticker.pause();
|
||||
}
|
||||
|
||||
egret.lifecycle.onResume = () => {
|
||||
egret.ticker.resume();
|
||||
}
|
||||
|
||||
this.runGame().catch(e => {
|
||||
console.log(e);
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async runGame() {
|
||||
await this.loadResource()
|
||||
this.createGameScene();
|
||||
const result = await RES.getResAsync("description_json")
|
||||
this.startAnimation(result);
|
||||
await platform.login();
|
||||
const userInfo = await platform.getUserInfo();
|
||||
console.log(userInfo);
|
||||
|
||||
}
|
||||
|
||||
private async loadResource() {
|
||||
try {
|
||||
const loadingView = new LoadingUI();
|
||||
this.stage.addChild(loadingView);
|
||||
await RES.loadConfig("resource/default.res.json", "resource/");
|
||||
await RES.loadGroup("preload", 0, loadingView);
|
||||
this.stage.removeChild(loadingView);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private textfield: egret.TextField;
|
||||
|
||||
/**
|
||||
* 创建游戏场景
|
||||
* Create a game scene
|
||||
*/
|
||||
private createGameScene() {
|
||||
let sky = this.createBitmapByName("bg_jpg");
|
||||
this.addChild(sky);
|
||||
let stageW = this.stage.stageWidth;
|
||||
let stageH = this.stage.stageHeight;
|
||||
sky.width = stageW;
|
||||
sky.height = stageH;
|
||||
|
||||
let topMask = new egret.Shape();
|
||||
topMask.graphics.beginFill(0x000000, 0.5);
|
||||
topMask.graphics.drawRect(0, 0, stageW, 172);
|
||||
topMask.graphics.endFill();
|
||||
topMask.y = 33;
|
||||
this.addChild(topMask);
|
||||
|
||||
let icon = this.createBitmapByName("egret_icon_png");
|
||||
this.addChild(icon);
|
||||
icon.x = 26;
|
||||
icon.y = 33;
|
||||
|
||||
let line = new egret.Shape();
|
||||
line.graphics.lineStyle(2, 0xffffff);
|
||||
line.graphics.moveTo(0, 0);
|
||||
line.graphics.lineTo(0, 117);
|
||||
line.graphics.endFill();
|
||||
line.x = 172;
|
||||
line.y = 61;
|
||||
this.addChild(line);
|
||||
|
||||
|
||||
let colorLabel = new egret.TextField();
|
||||
colorLabel.textColor = 0xffffff;
|
||||
colorLabel.width = stageW - 172;
|
||||
colorLabel.textAlign = "center";
|
||||
colorLabel.text = "Hello Egret";
|
||||
colorLabel.size = 24;
|
||||
colorLabel.x = 172;
|
||||
colorLabel.y = 80;
|
||||
this.addChild(colorLabel);
|
||||
|
||||
let textfield = new egret.TextField();
|
||||
this.addChild(textfield);
|
||||
textfield.alpha = 0;
|
||||
textfield.width = stageW - 172;
|
||||
textfield.textAlign = egret.HorizontalAlign.CENTER;
|
||||
textfield.size = 24;
|
||||
textfield.textColor = 0xffffff;
|
||||
textfield.x = 172;
|
||||
textfield.y = 135;
|
||||
this.textfield = textfield;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
|
||||
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
|
||||
*/
|
||||
private createBitmapByName(name: string) {
|
||||
let result = new egret.Bitmap();
|
||||
let texture: egret.Texture = RES.getRes(name);
|
||||
result.texture = texture;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述文件加载成功,开始播放动画
|
||||
* Description file loading is successful, start to play the animation
|
||||
*/
|
||||
private startAnimation(result: string[]) {
|
||||
let parser = new egret.HtmlTextParser();
|
||||
|
||||
let textflowArr = result.map(text => parser.parse(text));
|
||||
let textfield = this.textfield;
|
||||
let count = -1;
|
||||
let change = () => {
|
||||
count++;
|
||||
if (count >= textflowArr.length) {
|
||||
count = 0;
|
||||
}
|
||||
let textFlow = textflowArr[count];
|
||||
|
||||
// 切换描述内容
|
||||
// Switch to described content
|
||||
textfield.textFlow = textFlow;
|
||||
let tw = egret.Tween.get(textfield);
|
||||
tw.to({ "alpha": 1 }, 200);
|
||||
tw.wait(2000);
|
||||
tw.to({ "alpha": 0 }, 200);
|
||||
tw.call(change, this);
|
||||
};
|
||||
|
||||
change();
|
||||
}
|
||||
}
|
||||
40
protubuf/protobuf-egret/egret-project/src/Platform.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 平台数据接口。
|
||||
* 由于每款游戏通常需要发布到多个平台上,所以提取出一个统一的接口用于开发者获取平台数据信息
|
||||
* 推荐开发者通过这种方式封装平台逻辑,以保证整体结构的稳定
|
||||
* 由于不同平台的接口形式各有不同,白鹭推荐开发者将所有接口封装为基于 Promise 的异步形式
|
||||
*/
|
||||
declare interface Platform {
|
||||
|
||||
getUserInfo(): Promise<any>;
|
||||
|
||||
login(): Promise<any>;
|
||||
}
|
||||
|
||||
class DebugPlatform implements Platform {
|
||||
async getUserInfo() {
|
||||
return { nickName: "username" }
|
||||
}
|
||||
async login() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!window.platform) {
|
||||
window.platform = new DebugPlatform();
|
||||
}
|
||||
|
||||
|
||||
|
||||
declare let platform: Platform;
|
||||
|
||||
declare interface Window {
|
||||
|
||||
platform: Platform
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
require("launcher/native_require.js");
|
||||
|
||||
egret_native.egtMain = function () {
|
||||
egret_native.nativeType = "native";
|
||||
|
||||
egret_native.egretInit();
|
||||
egret_native.egretStart();
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
var manifest = JSON.parse(egret_native.readFileSync("manifest.json"));
|
||||
var game_file_list = manifest.initial.concat(manifest.game);
|
||||
|
||||
var window = this;
|
||||
|
||||
egret_native.setSearchPaths([""]);
|
||||
|
||||
egret_native.requireFiles = function () {
|
||||
for (var key in game_file_list) {
|
||||
var src = game_file_list[key];
|
||||
require(src);
|
||||
}
|
||||
};
|
||||
|
||||
egret_native.egretInit = function () {
|
||||
if(egret_native.featureEnable) {
|
||||
//控制一些优化方案是否开启
|
||||
//Control whether some optimization options are open
|
||||
var result = egret_native.featureEnable({
|
||||
|
||||
});
|
||||
}
|
||||
egret_native.requireFiles();
|
||||
egret.dom = {};
|
||||
egret.dom.drawAsCanvas = function () {
|
||||
};
|
||||
};
|
||||
|
||||
egret_native.egretStart = function () {
|
||||
var option = {
|
||||
//以下为自动修改,请勿修改
|
||||
//The following is automatically modified, please do not modify
|
||||
//----auto option start----
|
||||
entryClassName: "Main",
|
||||
frameRate: 30,
|
||||
scaleMode: "showAll",
|
||||
contentWidth: 640,
|
||||
contentHeight: 1136,
|
||||
showPaintRect: false,
|
||||
showFPS: false,
|
||||
fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9",
|
||||
showLog: false,
|
||||
logFilter: "",
|
||||
maxTouches: 2,
|
||||
textureScaleFactor: 1
|
||||
//----auto option end----
|
||||
};
|
||||
|
||||
egret.native.NativePlayer.option = option;
|
||||
egret.runEgret();
|
||||
egret_native.Label.createLabel("/system/fonts/DroidSansFallback.ttf", 20, "", 0);
|
||||
egret_native.EGTView.preSetOffScreenBufferEnable(true);
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
require("launcher/native_require.js");
|
||||
|
||||
egret_native.egtMain = function () {
|
||||
egret_native.nativeType = "runtime";
|
||||
|
||||
egret_native.egretInit();
|
||||
egret_native.egretStart();
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Egret</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 {
|
||||
-ms-touch-action: none;
|
||||
background: #888888;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="margin: auto;width: 100%;height: 100%;" class="egret-player"
|
||||
data-entry-class="Main"
|
||||
data-orientation="auto"
|
||||
data-scale-mode="showAll"
|
||||
data-frame-rate="30"
|
||||
data-content-width="640"
|
||||
data-content-height="1136"
|
||||
data-show-paint-rect="false"
|
||||
data-multi-fingered="2"
|
||||
data-show-fps="false" data-show-log="false"
|
||||
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
|
||||
</div>
|
||||
<script>
|
||||
var loadScript = function (list, callback) {
|
||||
var loaded = 0;
|
||||
var loadNext = function () {
|
||||
loadSingleScript(list[loaded], function () {
|
||||
loaded++;
|
||||
if (loaded >= list.length) {
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
loadNext();
|
||||
}
|
||||
})
|
||||
};
|
||||
loadNext();
|
||||
};
|
||||
|
||||
var loadSingleScript = function (src, callback) {
|
||||
var s = document.createElement('script');
|
||||
s.async = false;
|
||||
s.src = src;
|
||||
s.addEventListener('load', function () {
|
||||
s.parentNode.removeChild(s);
|
||||
s.removeEventListener('load', arguments.callee, false);
|
||||
callback();
|
||||
}, false);
|
||||
document.body.appendChild(s);
|
||||
};
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', './manifest.json?v=' + Math.random(), true);
|
||||
xhr.addEventListener("load", function () {
|
||||
var manifest = JSON.parse(xhr.response);
|
||||
var list = manifest.initial.concat(manifest.game);
|
||||
loadScript(list, function () {
|
||||
/**
|
||||
* {
|
||||
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
|
||||
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
|
||||
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
|
||||
* "calculateCanvasScaleFactor": //a function return canvas scale factor
|
||||
* }
|
||||
**/
|
||||
egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) {
|
||||
var backingStore = context.backingStorePixelRatio ||
|
||||
context.webkitBackingStorePixelRatio ||
|
||||
context.mozBackingStorePixelRatio ||
|
||||
context.msBackingStorePixelRatio ||
|
||||
context.oBackingStorePixelRatio ||
|
||||
context.backingStorePixelRatio || 1;
|
||||
return (window.devicePixelRatio || 1) / backingStore;
|
||||
}});
|
||||
});
|
||||
});
|
||||
xhr.send(null);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
18
protubuf/protobuf-egret/egret-project/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"outDir": "bin-debug",
|
||||
"experimentalDecorators": true,
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.promise"
|
||||
],
|
||||
"types": []
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
"libs",
|
||||
"protobuf/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
BIN
protubuf/protobuf-egret/egret-project_wxgame/.DS_Store
vendored
Normal file
7773
protubuf/protobuf-egret/egret-project_wxgame/egret.wxgame.js
Normal file
26
protubuf/protobuf-egret/egret-project_wxgame/game.js
Normal file
@@ -0,0 +1,26 @@
|
||||
require('./weapp-adapter.js');
|
||||
require('./platform.js');
|
||||
require('./manifest.js');
|
||||
require('./egret.wxgame.js');
|
||||
|
||||
egret.runEgret({
|
||||
contentWidth: 640,
|
||||
contentHeight: 1136,
|
||||
scaleMode: "fixedWidth",
|
||||
entryClassName: "Main",
|
||||
frameRate: 30,
|
||||
orientation: "auto",
|
||||
renderMode: "webgl",
|
||||
audioType: 0,
|
||||
calculateCanvasScaleFactor: function (context) {
|
||||
var backingStore = context.backingStorePixelRatio ||
|
||||
context.webkitBackingStorePixelRatio ||
|
||||
context.mozBackingStorePixelRatio ||
|
||||
context.msBackingStorePixelRatio ||
|
||||
context.oBackingStorePixelRatio ||
|
||||
context.backingStorePixelRatio || 1;
|
||||
return (window.devicePixelRatio || 1) / backingStore;
|
||||
}
|
||||
});
|
||||
|
||||
// require("egret.min.js")
|
||||
9
protubuf/protobuf-egret/egret-project_wxgame/game.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"deviceOrientation": "portrait",
|
||||
"networkTimeout": {
|
||||
"request": 5000,
|
||||
"connectSocket": 5000,
|
||||
"uploadFile": 5000,
|
||||
"downloadFile": 5000
|
||||
}
|
||||
}
|
||||
7
protubuf/protobuf-egret/egret-project_wxgame/manifest.js
Normal file
@@ -0,0 +1,7 @@
|
||||
require("js/egret.min.js")
|
||||
require("js/game.min.js")
|
||||
require("js/tween.min.js")
|
||||
require("js/assetsmanager.min.js")
|
||||
require("js/protobuf-library.min.js")
|
||||
require("js/protobuf-bundles.min.js")
|
||||
require("js/main.min.js")
|
||||
39
protubuf/protobuf-egret/egret-project_wxgame/platform.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 请在白鹭引擎的Main.ts中调用 platform.login() 方法调用至此处。
|
||||
*/
|
||||
|
||||
class WxgamePlatform {
|
||||
|
||||
name = 'wxgame'
|
||||
|
||||
login() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
resolve(res)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getUserInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.getUserInfo({
|
||||
withCredentials: true,
|
||||
success: function (res) {
|
||||
var userInfo = res.userInfo
|
||||
var nickName = userInfo.nickName
|
||||
var avatarUrl = userInfo.avatarUrl
|
||||
var gender = userInfo.gender //性别 0:未知、1:男、2:女
|
||||
var province = userInfo.province
|
||||
var city = userInfo.city
|
||||
var country = userInfo.country
|
||||
resolve(userInfo);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.platform = new WxgamePlatform();
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"description": "项目配置文件。",
|
||||
"setting": {
|
||||
"urlCheck": true,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"newFeature": true
|
||||
},
|
||||
"compileType": "game",
|
||||
"libVersion": "game",
|
||||
"appid": "wx6ac3f5090a6b99c5",
|
||||
"projectname": "helloworld",
|
||||
"condition": {
|
||||
"search": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"conversation": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"game": {
|
||||
"list": [],
|
||||
"current": -1
|
||||
},
|
||||
"miniprogram": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
}
|
||||
1555
protubuf/protobuf-egret/egret-project_wxgame/weapp-adapter.js
Normal file
9
protubuf/protobuf-egret/out/cli.js
Normal file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
|
||||
var command = process.argv[2];
|
||||
var egretProject = process.argv[3];
|
||||
if (!egretProject) {
|
||||
egretProject = '.';
|
||||
}
|
||||
require('./').run(command, egretProject);
|
||||
253
protubuf/protobuf-egret/out/index.js
Normal file
@@ -0,0 +1,253 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var child_process = require("child_process");
|
||||
var fs = require("fs-extra-promise");
|
||||
var path = require("path");
|
||||
var UglifyJS = require("uglify-js");
|
||||
var os = require("os");
|
||||
var root = path.resolve(__filename, '../../');
|
||||
function shell(command, args) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var cmd = command + " " + args.join(" ");
|
||||
child_process.exec(cmd, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(stdout);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
var pbconfigContent = JSON.stringify({
|
||||
options: {
|
||||
"no-create": false,
|
||||
"no-verify": false,
|
||||
"no-convert": true,
|
||||
"no-delimited": false
|
||||
},
|
||||
sourceRoot: "protofile",
|
||||
outputFile: "bundles/protobuf-bundles.js"
|
||||
}, null, '\t');
|
||||
function generate(rootDir) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var pbconfigPath, pbconfigPath_1, pbconfig, tempfile, output, dirname, protoRoot, fileList, protoList, args, pbjsResult, minjs, pbtsResult;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
pbconfigPath = path.join(rootDir, 'pbconfig.json');
|
||||
return [4 /*yield*/, fs.existsAsync(pbconfigPath)];
|
||||
case 1:
|
||||
if (!!(_a.sent())) return [3 /*break*/, 9];
|
||||
return [4 /*yield*/, fs.existsAsync(path.join(rootDir, 'protobuf'))];
|
||||
case 2:
|
||||
if (!_a.sent()) return [3 /*break*/, 7];
|
||||
pbconfigPath_1 = path.join(rootDir, 'protobuf', 'pbconfig.json');
|
||||
return [4 /*yield*/, (fs.existsAsync(pbconfigPath_1))];
|
||||
case 3:
|
||||
if (!!(_a.sent())) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, fs.writeFileAsync(pbconfigPath_1, pbconfigContent, 'utf-8')];
|
||||
case 4:
|
||||
_a.sent();
|
||||
_a.label = 5;
|
||||
case 5: return [4 /*yield*/, generate(path.join(rootDir, 'protobuf'))];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7: throw '请首先执行 pb-egret add 命令';
|
||||
case 8: return [2 /*return*/];
|
||||
case 9: return [4 /*yield*/, fs.readJSONAsync(path.join(rootDir, 'pbconfig.json'))];
|
||||
case 10:
|
||||
pbconfig = _a.sent();
|
||||
tempfile = path.join(os.tmpdir(), 'pbegret', 'temp.js');
|
||||
return [4 /*yield*/, fs.mkdirpAsync(path.dirname(tempfile))];
|
||||
case 11:
|
||||
_a.sent();
|
||||
output = path.join(rootDir, pbconfig.outputFile);
|
||||
dirname = path.dirname(output);
|
||||
return [4 /*yield*/, fs.mkdirpAsync(dirname)];
|
||||
case 12:
|
||||
_a.sent();
|
||||
protoRoot = path.join(rootDir, pbconfig.sourceRoot);
|
||||
return [4 /*yield*/, fs.readdirAsync(protoRoot)];
|
||||
case 13:
|
||||
fileList = _a.sent();
|
||||
protoList = fileList.filter(function (item) { return path.extname(item) === '.proto'; });
|
||||
if (protoList.length == 0) {
|
||||
throw ' protofile 文件夹中不存在 .proto 文件';
|
||||
}
|
||||
return [4 /*yield*/, Promise.all(protoList.map(function (protofile) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var content;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fs.readFileAsync(path.join(protoRoot, protofile), 'utf-8')];
|
||||
case 1:
|
||||
content = _a.sent();
|
||||
if (content.indexOf('package') == -1) {
|
||||
throw protofile + " \u4E2D\u5FC5\u987B\u5305\u542B package \u5B57\u6BB5";
|
||||
}
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); }))];
|
||||
case 14:
|
||||
_a.sent();
|
||||
args = ['-t', 'static', '--keep-case', '-p', protoRoot, protoList.join(" "), '-o', tempfile];
|
||||
if (pbconfig.options['no-create']) {
|
||||
args.unshift('--no-create');
|
||||
}
|
||||
if (pbconfig.options['no-verify']) {
|
||||
args.unshift('--no-verify');
|
||||
}
|
||||
if (pbconfig.options['no-convert']) {
|
||||
args.unshift('--no-convert');
|
||||
}
|
||||
if (pbconfig.options["no-delimited"]) {
|
||||
args.unshift("--no-delimited");
|
||||
}
|
||||
return [4 /*yield*/, shell('pbjs', args)];
|
||||
case 15:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.readFileAsync(tempfile, 'utf-8')];
|
||||
case 16:
|
||||
pbjsResult = _a.sent();
|
||||
pbjsResult = 'var $protobuf = window.protobuf;\n$protobuf.roots.default=window;\n' + pbjsResult;
|
||||
return [4 /*yield*/, fs.writeFileAsync(output, pbjsResult, 'utf-8')];
|
||||
case 17:
|
||||
_a.sent();
|
||||
minjs = UglifyJS.minify(pbjsResult);
|
||||
return [4 /*yield*/, fs.writeFileAsync(output.replace('.js', '.min.js'), minjs.code, 'utf-8')];
|
||||
case 18:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, shell('pbts', ['--main', output, '-o', tempfile])];
|
||||
case 19:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.readFileAsync(tempfile, 'utf-8')];
|
||||
case 20:
|
||||
pbtsResult = _a.sent();
|
||||
pbtsResult = pbtsResult.replace(/\$protobuf/gi, "protobuf").replace(/export namespace/gi, 'declare namespace');
|
||||
pbtsResult = 'type Long = protobuf.Long;\n' + pbtsResult;
|
||||
return [4 /*yield*/, fs.writeFileAsync(output.replace(".js", ".d.ts"), pbtsResult, 'utf-8')];
|
||||
case 21:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.removeAsync(tempfile)];
|
||||
case 22:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function add(egretProjectRoot) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var egretPropertiesPath, egretProperties, tsconfig;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
console.log('正在将 protobuf 源码拷贝至项目中...');
|
||||
return [4 /*yield*/, fs.copyAsync(path.join(root, 'dist'), path.join(egretProjectRoot, 'protobuf/library'))];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/protofile'))];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/bundles'))];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs.writeFileAsync((path.join(egretProjectRoot, 'protobuf/pbconfig.json')), pbconfigContent, 'utf-8')];
|
||||
case 4:
|
||||
_a.sent();
|
||||
egretPropertiesPath = path.join(egretProjectRoot, 'egretProperties.json');
|
||||
return [4 /*yield*/, fs.existsAsync(egretPropertiesPath)];
|
||||
case 5:
|
||||
if (!_a.sent()) return [3 /*break*/, 10];
|
||||
console.log('正在将 protobuf 添加到 egretProperties.json 中...');
|
||||
return [4 /*yield*/, fs.readJSONAsync(egretPropertiesPath)];
|
||||
case 6:
|
||||
egretProperties = _a.sent();
|
||||
egretProperties.modules.push({ name: 'protobuf-library', path: 'protobuf/library' });
|
||||
egretProperties.modules.push({ name: 'protobuf-bundles', path: 'protobuf/bundles' });
|
||||
return [4 /*yield*/, fs.writeFileAsync(path.join(egretProjectRoot, 'egretProperties.json'), JSON.stringify(egretProperties, null, '\t\t'))];
|
||||
case 7:
|
||||
_a.sent();
|
||||
console.log('正在将 protobuf 添加到 tsconfig.json 中...');
|
||||
return [4 /*yield*/, fs.readJSONAsync(path.join(egretProjectRoot, 'tsconfig.json'))];
|
||||
case 8:
|
||||
tsconfig = _a.sent();
|
||||
tsconfig.include.push('protobuf/**/*.d.ts');
|
||||
return [4 /*yield*/, fs.writeFileAsync(path.join(egretProjectRoot, 'tsconfig.json'), JSON.stringify(tsconfig, null, '\t\t'))];
|
||||
case 9:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 11];
|
||||
case 10:
|
||||
console.log('输入的文件夹不是白鹭引擎项目');
|
||||
_a.label = 11;
|
||||
case 11: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function run(command, egretProjectRoot) {
|
||||
run_1(command, egretProjectRoot).catch(function (e) { return console.log(e); });
|
||||
}
|
||||
exports.run = run;
|
||||
function run_1(command, egretProjectRoot) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!(command == "add")) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, add(egretProjectRoot)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 5];
|
||||
case 2:
|
||||
if (!(command == "generate")) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, generate(egretProjectRoot)];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
console.error('请输入命令: add / generate');
|
||||
_a.label = 5;
|
||||
case 5: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
129
protubuf/protobuf-egret/package-lock.json
generated
Normal file
@@ -0,0 +1,129 @@
|
||||
{
|
||||
"name": "@egret/protobuf",
|
||||
"version": "1.1.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/bluebird": {
|
||||
"version": "3.5.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.24.tgz",
|
||||
"integrity": "sha512-YeQoDpq4Lm8ppSBqAnAeF/xy1cYp/dMTif2JFcvmAbETMRlvKHT2iLcWu+WyYiJO3b3Ivokwo7EQca/xfLVJmg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-4.0.8.tgz",
|
||||
"integrity": "sha512-Z5nu9Pbxj9yNeXIK3UwGlRdJth4cZ5sCq05nI7FaI6B0oz28nxkOtp6Lsz0ZnmLHJGvOJfB/VHxSTbVq/i6ujA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/fs-extra-promise": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra-promise/-/fs-extra-promise-1.0.7.tgz",
|
||||
"integrity": "sha512-HEyt6v64my1B6fBvMPzS1mc/mxbDikqSzJ7Qw9kHowMKPSPLFSKzaiJo9bsE7xUQa9OwCpEDlX+QEBxPiXnRPg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/bluebird": "*",
|
||||
"@types/fs-extra": "^4",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "9.6.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.31.tgz",
|
||||
"integrity": "sha512-kIVlvUBizL51ALNMPbmcZoM7quHyB7J6fLRwQe22JsMp39nrVSHdBeVVS3fnQCK1orxI3O8LScmb8cuiihkAfA==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/uglify-js": {
|
||||
"version": "2.6.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-2.6.31.tgz",
|
||||
"integrity": "sha512-LjcyGt6CHsgZ0AoofnMwhyxo9hUqz2mgl6IcF+S8B1zdSTxHAvTO/1RPvBAHG3C1ZeAc+AoWA5mb3lDJKtM9Zg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"source-map": "^0.6.1"
|
||||
}
|
||||
},
|
||||
"bluebird": {
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.2.tgz",
|
||||
"integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg=="
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.17.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
|
||||
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg=="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
|
||||
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"fs-extra-promise": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra-promise/-/fs-extra-promise-1.0.1.tgz",
|
||||
"integrity": "sha1-tu0azpexDga5X0WNBRt/BcZhPuY=",
|
||||
"requires": {
|
||||
"bluebird": "^3.5.0",
|
||||
"fs-extra": "^2.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-2.1.2.tgz",
|
||||
"integrity": "sha1-BGxwFjzvmq1GsOSn+kZ/si1x3jU=",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"jsonfile": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
|
||||
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.1.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
|
||||
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.4.9",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz",
|
||||
"integrity": "sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==",
|
||||
"requires": {
|
||||
"commander": "~2.17.1",
|
||||
"source-map": "~0.6.1"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
24
protubuf/protobuf-egret/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@egret/protobuf",
|
||||
"version": "1.2.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"pb-egret": "out/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fs-extra": "^5.0.0",
|
||||
"fs-extra-promise": "^1.0.1",
|
||||
"uglify-js": "^3.3.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra-promise": "^1.0.4",
|
||||
"@types/node": "^9.3.0",
|
||||
"@types/uglify-js": "^2.6.30"
|
||||
}
|
||||
}
|
||||
162
protubuf/protobuf-egret/src/index.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
import * as child_process from 'child_process';
|
||||
import * as fs from 'fs-extra-promise';
|
||||
import * as path from 'path';
|
||||
import * as UglifyJS from 'uglify-js';
|
||||
import * as os from 'os';
|
||||
|
||||
const root = path.resolve(__filename, '../../');
|
||||
|
||||
function shell(command: string, args: string[]) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
|
||||
const cmd = command + " " + args.join(" ");
|
||||
child_process.exec(cmd, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(stdout)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
type ProtobufConfig = {
|
||||
|
||||
options: {
|
||||
"no-create": boolean,
|
||||
"no-verify": boolean,
|
||||
"no-convert": boolean,
|
||||
"no-delimited": boolean
|
||||
},
|
||||
|
||||
sourceRoot: string,
|
||||
outputFile: string
|
||||
|
||||
|
||||
}
|
||||
|
||||
const pbconfigContent = JSON.stringify({
|
||||
options: {
|
||||
"no-create": false,
|
||||
"no-verify": false,
|
||||
"no-convert": true,
|
||||
"no-delimited": false
|
||||
},
|
||||
sourceRoot: "protofile",
|
||||
outputFile: "bundles/protobuf-bundles.js"
|
||||
} as ProtobufConfig, null, '\t');
|
||||
|
||||
async function generate(rootDir: string) {
|
||||
|
||||
const pbconfigPath = path.join(rootDir, 'pbconfig.json');
|
||||
if (!(await fs.existsAsync(pbconfigPath))) {
|
||||
if (await fs.existsAsync(path.join(rootDir, 'protobuf'))) {
|
||||
const pbconfigPath = path.join(rootDir, 'protobuf', 'pbconfig.json')
|
||||
if (!await (fs.existsAsync(pbconfigPath))) {
|
||||
await fs.writeFileAsync(pbconfigPath, pbconfigContent, 'utf-8');
|
||||
}
|
||||
await generate(path.join(rootDir, 'protobuf'));
|
||||
}
|
||||
else {
|
||||
throw '请首先执行 pb-egret add 命令'
|
||||
}
|
||||
return;
|
||||
}
|
||||
const pbconfig: ProtobufConfig = await fs.readJSONAsync(path.join(rootDir, 'pbconfig.json'));
|
||||
const tempfile = path.join(os.tmpdir(), 'pbegret', 'temp.js');
|
||||
await fs.mkdirpAsync(path.dirname(tempfile));
|
||||
const output = path.join(rootDir, pbconfig.outputFile);
|
||||
const dirname = path.dirname(output);
|
||||
await fs.mkdirpAsync(dirname);
|
||||
const protoRoot = path.join(rootDir, pbconfig.sourceRoot);
|
||||
const fileList = await fs.readdirAsync(protoRoot);
|
||||
const protoList = fileList.filter(item => path.extname(item) === '.proto')
|
||||
if (protoList.length == 0) {
|
||||
throw ' protofile 文件夹中不存在 .proto 文件'
|
||||
}
|
||||
await Promise.all(protoList.map(async (protofile) => {
|
||||
const content = await fs.readFileAsync(path.join(protoRoot, protofile), 'utf-8')
|
||||
if (content.indexOf('package') == -1) {
|
||||
throw `${protofile} 中必须包含 package 字段`
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
|
||||
|
||||
const args = ['-t', 'static', '--keep-case', '-p', protoRoot, protoList.join(" "), '-o', tempfile]
|
||||
if (pbconfig.options['no-create']) {
|
||||
args.unshift('--no-create');
|
||||
}
|
||||
if (pbconfig.options['no-verify']) {
|
||||
args.unshift('--no-verify');
|
||||
}
|
||||
if (pbconfig.options['no-convert']) {
|
||||
args.unshift('--no-convert')
|
||||
}
|
||||
if (pbconfig.options["no-delimited"]) {
|
||||
args.unshift("--no-delimited")
|
||||
}
|
||||
await shell('pbjs', args);
|
||||
let pbjsResult = await fs.readFileAsync(tempfile, 'utf-8');
|
||||
pbjsResult = 'var $protobuf = window.protobuf;\n$protobuf.roots.default=window;\n' + pbjsResult;
|
||||
await fs.writeFileAsync(output, pbjsResult, 'utf-8');
|
||||
const minjs = UglifyJS.minify(pbjsResult);
|
||||
await fs.writeFileAsync(output.replace('.js', '.min.js'), minjs.code, 'utf-8');
|
||||
await shell('pbts', ['--main', output, '-o', tempfile]);
|
||||
let pbtsResult = await fs.readFileAsync(tempfile, 'utf-8');
|
||||
pbtsResult = pbtsResult.replace(/\$protobuf/gi, "protobuf").replace(/export namespace/gi, 'declare namespace');
|
||||
pbtsResult = 'type Long = protobuf.Long;\n' + pbtsResult;
|
||||
await fs.writeFileAsync(output.replace(".js", ".d.ts"), pbtsResult, 'utf-8');
|
||||
await fs.removeAsync(tempfile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function add(egretProjectRoot: string) {
|
||||
console.log('正在将 protobuf 源码拷贝至项目中...');
|
||||
await fs.copyAsync(path.join(root, 'dist'), path.join(egretProjectRoot, 'protobuf/library'));
|
||||
await fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/protofile'));
|
||||
await fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/bundles'));
|
||||
await fs.writeFileAsync((path.join(egretProjectRoot, 'protobuf/pbconfig.json')), pbconfigContent, 'utf-8');
|
||||
|
||||
const egretPropertiesPath = path.join(egretProjectRoot, 'egretProperties.json');
|
||||
if (await fs.existsAsync(egretPropertiesPath)) {
|
||||
console.log('正在将 protobuf 添加到 egretProperties.json 中...');
|
||||
const egretProperties = await fs.readJSONAsync(egretPropertiesPath);
|
||||
egretProperties.modules.push({ name: 'protobuf-library', path: 'protobuf/library' });
|
||||
egretProperties.modules.push({ name: 'protobuf-bundles', path: 'protobuf/bundles' });
|
||||
await fs.writeFileAsync(path.join(egretProjectRoot, 'egretProperties.json'), JSON.stringify(egretProperties, null, '\t\t'));
|
||||
console.log('正在将 protobuf 添加到 tsconfig.json 中...');
|
||||
const tsconfig = await fs.readJSONAsync(path.join(egretProjectRoot, 'tsconfig.json'));
|
||||
tsconfig.include.push('protobuf/**/*.d.ts');
|
||||
await fs.writeFileAsync(path.join(egretProjectRoot, 'tsconfig.json'), JSON.stringify(tsconfig, null, '\t\t'));
|
||||
}
|
||||
else {
|
||||
console.log('输入的文件夹不是白鹭引擎项目')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function run(command: string, egretProjectRoot: string) {
|
||||
run_1(command, egretProjectRoot).catch(e => console.log(e))
|
||||
}
|
||||
|
||||
async function run_1(command: string, egretProjectRoot: string) {
|
||||
|
||||
if (command == "add") {
|
||||
await add(egretProjectRoot);
|
||||
}
|
||||
else if (command == "generate") {
|
||||
await generate(egretProjectRoot)
|
||||
}
|
||||
else {
|
||||
console.error('请输入命令: add / generate')
|
||||
}
|
||||
|
||||
}
|
||||
54
protubuf/protobuf-egret/tsconfig.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
|
||||
"lib": [
|
||||
"es2015"
|
||||
], /* Specify library files to be included in the compilation: */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./out", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"exclude": [
|
||||
"egret-project",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||