220 lines
4.0 KiB
TypeScript
Raw Normal View History

2021-11-06 20:19:21 +08:00
// @ts-ignore
import {v4} from "uuid"
2021-04-04 19:21:17 +08:00
export enum DataType {
Number,
String,
Text,
Vec2,
Vec3,
Enum,
Bool,
Color,
2021-11-06 21:42:37 +08:00
Invalid,
2021-04-05 19:31:34 +08:00
Array, // 暂时在控制台打印下
Object,
2021-11-06 20:19:21 +08:00
ObjectItem,
2021-06-14 19:41:58 +08:00
Image, // 图片
2021-06-19 19:51:05 +08:00
Engine,// 引擎的类型cc.Node, cc.Sprite, cc.Label等。。。
2021-04-04 19:21:17 +08:00
}
2021-05-08 17:52:29 +08:00
export class Info {
2021-11-06 20:19:21 +08:00
public id: string | null = null;
2021-04-04 19:21:17 +08:00
public type: DataType = DataType.Number;
2021-04-05 18:38:44 +08:00
public data: any;
2021-05-08 20:36:32 +08:00
public readonly: boolean = false;
2021-04-07 17:26:16 +08:00
public path: Array<string> = [];// 属性对应的路径
2021-11-06 20:19:21 +08:00
constructor() {
this.id = v4();
}
2021-04-04 19:21:17 +08:00
}
export class TextData extends Info {
constructor() {
super();
this.type = DataType.Text;
}
}
2021-11-06 20:19:21 +08:00
export interface ObjectItemRequestData {
id: string | null;
data: Property[];
}
2021-06-19 19:51:05 +08:00
export class EngineData extends Info {
2021-11-06 20:19:21 +08:00
public engineType: string = "";
public engineUUID: string = "";
public engineName: string = "";
2021-06-19 19:51:05 +08:00
constructor() {
super();
this.type = DataType.Engine;
}
}
2021-04-05 19:31:34 +08:00
export class ArrayData extends Info {
2021-06-15 22:19:47 +08:00
data: Array<Property> = [];
2021-04-05 19:31:34 +08:00
constructor() {
super();
this.type = DataType.Array;
}
2021-06-15 22:19:47 +08:00
add(info: Property) {
this.data.push(info);
return this;
}
2021-04-05 19:31:34 +08:00
}
2021-11-06 20:19:21 +08:00
export class ObjectDataItem extends Info {
2021-06-17 22:35:37 +08:00
2021-11-06 20:19:21 +08:00
}
export class ObjectData extends Info {
data: string = "";// object的简单描述快照类似chrome的console{a:'fff',b:xxx}
2021-04-05 19:31:34 +08:00
constructor() {
super();
this.type = DataType.Object;
}
}
2021-11-06 21:42:37 +08:00
export class InvalidData extends Info {
2021-11-07 00:09:02 +08:00
data: "undefined" | "null" | "Infinity" | "NaN"|string;
2021-04-05 19:31:34 +08:00
2021-11-06 21:42:37 +08:00
constructor(data: any) {
super();
this.data = data;
this.type = DataType.Invalid;
2021-04-05 19:31:34 +08:00
}
}
2021-04-05 18:38:44 +08:00
export class ColorData extends Info {
constructor(color: string) {
super();
this.type = DataType.Color;
this.data = color;
}
}
2021-04-04 19:21:17 +08:00
export class StringData extends Info {
2021-04-05 18:38:44 +08:00
constructor(data: string) {
2021-04-04 19:21:17 +08:00
super();
this.type = DataType.String;
2021-04-05 18:38:44 +08:00
this.data = data;
2021-04-04 19:21:17 +08:00
}
}
export class NumberData extends Info {
2021-04-22 19:09:35 +08:00
constructor(data: number) {
2021-04-04 19:21:17 +08:00
super();
this.type = DataType.Number;
2021-04-22 19:09:35 +08:00
this.data = data;
2021-04-04 19:21:17 +08:00
}
2021-04-05 18:38:44 +08:00
}
2021-04-04 19:21:17 +08:00
2021-04-05 18:38:44 +08:00
export class BoolData extends Info {
constructor(bol: boolean) {
super();
this.type = DataType.Bool;
this.data = bol;
}
2021-04-04 19:21:17 +08:00
}
export class Vec2Data extends Info {
2021-06-14 18:46:45 +08:00
data: Array<Property> = [];
2021-04-05 18:38:44 +08:00
constructor() {
2021-04-04 19:21:17 +08:00
super();
this.type = DataType.Vec2
2021-04-05 18:38:44 +08:00
this.data = [];
return this;
}
add(info: Property) {
this.data.push(info);
return this;
2021-04-04 19:21:17 +08:00
}
}
export class Vec3Data extends Info {
2021-06-14 18:46:45 +08:00
data: Array<Property> = [];
2021-04-04 19:21:17 +08:00
2021-04-05 18:38:44 +08:00
constructor() {
2021-04-04 19:21:17 +08:00
super();
2021-04-05 18:38:44 +08:00
this.type = DataType.Vec3;
this.data = [];
return this;
}
add(info: Property) {
this.data.push(info);
return this;
2021-06-14 19:41:58 +08:00
}
}
export class ImageData extends Info {
data: string | null = null;
constructor() {
super();
this.type = DataType.Image;
this.data = null;
return this;
2021-04-04 19:21:17 +08:00
}
}
export class EnumData extends Info {
constructor() {
super();
this.type = DataType.Enum;
}
2021-05-08 17:52:29 +08:00
}
2021-04-04 19:21:17 +08:00
2021-05-08 17:52:29 +08:00
export class TreeData {
2021-05-11 22:15:29 +08:00
active: boolean = true;
2021-11-06 20:19:21 +08:00
uuid: string = "";
name: string = "";
2021-05-08 17:52:29 +08:00
children: Array<TreeData> = [];
2021-04-04 19:21:17 +08:00
}
2021-04-05 18:38:44 +08:00
export class Property {
2021-11-06 20:19:21 +08:00
public name: string = "property";
2021-04-05 18:38:44 +08:00
public value: Info = new Info();
constructor(name: string, info: Info) {
this.name = name;
this.value = info;
}
}
export class Group {
2021-11-06 20:19:21 +08:00
public name: string = "group";
2021-04-05 18:38:44 +08:00
public data: Array<Property> = [];
constructor(name: string) {
this.name = name;
}
addProperty(property: Property) {
this.data.push(property)
}
2021-05-08 18:44:10 +08:00
sort() {
2021-11-06 20:19:21 +08:00
let order = ["name", "active", "enabled", "uuid", "position", "rotation", "scale", "anchor", "size", "color", "opacity", "skew", "group"];
2021-05-08 18:44:10 +08:00
let orderKeys: Array<Property> = [];
let otherKeys: Array<Property> = [];
this.data.forEach(property => {
if (order.find(el => el === property.name)) {
orderKeys.push(property)
} else {
otherKeys.push(property);
}
})
orderKeys.sort((a, b) => {
return order.indexOf(a.name) - order.indexOf(b.name);
})
otherKeys.sort();
this.data = orderKeys.concat(otherKeys);
}
2021-04-05 18:38:44 +08:00
}