[add] Engine

This commit is contained in:
2022-08-26 16:48:17 +08:00
parent f67e566f2a
commit d9c19f096c
197 changed files with 10626 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.3",
"uuid": "3d4ae989-9f9b-429a-a331-191a8cd8193d",
"importer": "folder",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@@ -0,0 +1,4 @@
export interface ITableJson {
cols: string[],
rows: any[],
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "c5f8c44b-0b24-4f57-b229-4c3ad9301236",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,10 @@
export interface ITableRow {
Id: number;
}
/**
* 表沒有欄位
*/
export class WithoutRow implements ITableRow {
Id: number;
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "104d86f0-0cb9-4cd1-a305-44ea90ee3d7f",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,21 @@
import { ITableRow } from "./ITableRow";
export abstract class TableBase<TRow extends ITableRow> extends Array<TRow> {
constructor() {
super();
Object.setPrototypeOf(this, new.target.prototype);
}
/**欄位數量 */
public get Count(): number { return this.length; }
/**取得全部鍵值 */
public get Keys(): string[] { return Object.keys(this); }
/**取得全部欄位值 */
public get Rows(): Array<TRow> { return Object["values"](this); }
// public get Rows(): Array<TRow> { return this; }
/**是否包含該Id值的欄位 */
public ContainsRow(id: number): boolean {
return id in this;
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "e4f18713-244f-4375-b77a-c26bf197cd3f",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.3",
"uuid": "4a176b88-26e0-42ae-8acc-42ab2e942ace",
"importer": "folder",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@@ -0,0 +1,13 @@
import { TableManager } from "../TableManager";
import { StringExampleTableRow, StringTableExample } from "./Tables/StringTableExample";
const { ccclass } = cc._decorator;
@ccclass
export default class CSSettingsV3Example {
private static _stringExample: StringTableExample;
/** 共用_字串表#string.xlsx */
public static get StringExample(): StringTableExample { return this._stringExample = this._stringExample || TableManager.InitTable("#string", StringTableExample, StringExampleTableRow); }
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "04f57003-d6a1-4fee-adf8-69994db08f05",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,82 @@
import CSSettingsV3Example from "./CSSettingsV3Example";
import { StringExampleTable } from "./Tables/StringTableExample";
const { ccclass, property } = cc._decorator;
@ccclass
export default class TableUseExample extends cc.Component {
start() {
//#region StringExample表
cc.log("----------------#stringExample");
cc.log(CSSettingsV3Example.StringExample instanceof StringExampleTable); // true
cc.log(Array.isArray(CSSettingsV3Example.StringExample)); // true, 所以Array相關的方法都可以拿來操作
cc.log(CSSettingsV3Example.StringExample.length);
cc.log(CSSettingsV3Example.StringExample.Count); // 跟length一樣
cc.log(CSSettingsV3Example.StringExample.ContainsRow(11)); // 是否包含id=11的Row
cc.log(11 in CSSettingsV3Example.StringExample); // 同上
cc.log(CSSettingsV3Example.StringExample[1].MsgZnCh);
cc.log(CSSettingsV3Example.StringExample[1]["MsgZnCh"]); // 同上
cc.log(CSSettingsV3Example["StringExample"][1]["MsgZnCh"]); // 同上
cc.log("----------------");
for (let row of CSSettingsV3Example.StringExample) {
if (row) { // 如果Row沒有連號, 那有可能取到undefined值, 要先判斷, 不想判斷就用 CSSettings.StringExample.Rows
cc.log(row.Id, row.MsgZnCh);
}
}
cc.log("----------------");
for (let id of CSSettingsV3Example.StringExample.Keys) {
cc.log(id); // 只會列出有值的id, undefined會跳過
}
cc.log("----------------");
for (let row of CSSettingsV3Example.StringExample.Rows) {
cc.log(row.Id, row.MsgZnCh); // 只會列出有值的Row, undefined會跳過
}
//#endregion
//#region StringExample表 #StringFilter表
cc.log("----------------#stringExample#string_filter");
//cc.log(CSSettings.StringExample.StringFilter instanceof StringFilterTable); // true
cc.log(Array.isArray(CSSettingsV3Example.StringExample.StringFilter)); // true, 所以Array相關的方法都可以拿來操作
cc.log(CSSettingsV3Example.StringExample.StringFilter.length);
cc.log(CSSettingsV3Example.StringExample.StringFilter.Count); // 跟length一樣
cc.log(CSSettingsV3Example.StringExample.StringFilter.ContainsRow(11)); // 是否包含id=11的Row
cc.log(11 in CSSettingsV3Example.StringExample.StringFilter); // 同上
cc.log(CSSettingsV3Example.StringExample.StringFilter[1].FilterWord);
cc.log(CSSettingsV3Example.StringExample.StringFilter[1]["FilterWord"]); // 同上
cc.log(CSSettingsV3Example["StringExample"]["StringFilter"][1]["FilterWord"]); // 同上
cc.log("----------------");
for (let row of CSSettingsV3Example.StringExample.StringFilter) {
if (row) { // 如果Row沒有連號, 那有可能取到undefined值, 要先判斷, 不想判斷就用 CSSettings.StringExample.StringFilter.Rows
cc.log(row.Id, row.FilterWord);
}
}
cc.log("----------------");
for (let id of CSSettingsV3Example.StringExample.StringFilter.Keys) {
cc.log(id); // 只會列出有值的id, undefined會跳過
}
cc.log("----------------");
for (let row of CSSettingsV3Example.StringExample.StringFilter.Rows) {
cc.log(row.Id, row.FilterWord); // 只會列出有值的Row, undefined會跳過
}
//#endregion
cc.log("----------------");
//CSSettingsV3.ResetTables(); // 重置表
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "27d36ad6-da65-4673-abdb-4635a1a3d3a8",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.3",
"uuid": "e65b6243-578c-4cea-ac46-1dfd4d455017",
"importer": "folder",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@@ -0,0 +1,45 @@
import { ITableRow } from "../../Core/ITableRow";
import { TableBase } from "../../Core/TableBase";
import { TableManager } from "../../TableManager";
/**
* 共用_字串表#string.xlsx
* ##程式碼由工具產生, 在此做的修改都將被覆蓋##
*/
export class StringTableExample extends TableBase<StringExampleTableRow> {
private _stringFilter: StringFilterTable;
/** 共用_字串表#string.xlsx > #string_filter */
public get StringFilter(): StringFilterTable { return this._stringFilter = this._stringFilter || TableManager.InitTable("#string#string_filter", StringFilterTable, StringFilterTableRow); }
}
/**
* #string
*/
export class StringExampleTable extends TableBase<StringExampleTableRow> {}
export class StringExampleTableRow implements ITableRow {
/** 編號 */
Id: number;
/** 英文訊息 */
MsgEn: string;
/** 繁體中文訊息 */
MsgZnTw: string;
/** 簡體中文讯息 */
MsgZnCh: string;
/** 越南文讯息 */
MsgVi: string;
/** 泰文讯息 */
MsgTh: string;
}
/**
* #string_filter
*/
export class StringFilterTable extends TableBase<StringFilterTableRow> {}
export class StringFilterTableRow implements ITableRow {
/** 編號 */
Id: number;
/** 過濾字串 */
FilterWord: string;
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "c4bea919-96cd-40ee-a5f7-d9327414b1b2",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,48 @@
import { ITableJson } from "./Core/ITableJson";
import { ITableRow } from "./Core/ITableRow";
export class TableManager {
private static _tableJsons: { [key: string]: ITableJson } = {};
public static AddJsonAssets(jsonAssets: cc.JsonAsset[]) {
if (!jsonAssets) return;
let newAssets: cc.JsonAsset[] = jsonAssets.concat();
for (let jsonAsset of newAssets) {
this.AddJsonAsset(jsonAsset);
}
}
public static AddJsonAsset(jsonAsset: cc.JsonAsset) {
if (!jsonAsset) {
return;
}
for (let tableName in jsonAsset.json) {
console.log(`TableV3 [${tableName}] json loaded`);
this._tableJsons[tableName] = jsonAsset.json[tableName];
}
}
public static GetTable(name: string): ITableJson {
return this._tableJsons[name];
}
public static InitTable<T extends Array<ITableRow>>(name: string, tableType: { new(): T }, rowType: { new(): ITableRow }): T {
let json = this._tableJsons[name];
if (!json) {
throw new Error(`TableV3 [${name}] 尚未載入json檔`);
}
let table = new tableType();
let cols = json.cols;
let colLength = cols.length;
let rows = json.rows;
for (let r of rows) {
let trow = new rowType();
for (let i = 0; i < colLength; i++) {
trow[cols[i]] = r[i];
}
table[trow.Id] = trow;
}
//cc.log(`TableV3 [${name}] init done`);
return table;
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "f3bcfb76-6225-4757-a039-9018806ef54e",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}