265 lines
5.7 KiB
TypeScript
Raw Normal View History

2024-12-09 16:23:58 +08:00
import { v4 } from "uuid";
2021-11-06 20:19:21 +08:00
2021-04-04 19:21:17 +08:00
export enum DataType {
2024-01-09 12:02:47 +08:00
Number = 'Number',
String = 'String',
Text = 'Text',
Vec2 = 'Vec2',
Vec3 = 'Vec3',
Enum = 'Enum',
Bool = 'Bool',
Color = 'Color',
Invalid = 'Invalid',
Array = 'Array', // 暂时在控制台打印下
Object = 'Object',
ObjectItem = 'ObjectItem',
Image = 'Image', // 图片
Engine = '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();
}
2024-01-09 15:33:34 +08:00
public isEnum(): boolean { return false; }
public isVec2(): boolean { return false; }
public isVec3(): boolean { return false; }
public isBool(): boolean { return false; }
public isText(): boolean { return false; }
public isString(): boolean { return false; }
public isColor(): boolean { return false; }
public isInvalid(): boolean { return false; }
public isNumber(): boolean { return false; }
public isArrayOrObject(): boolean { return false; }
public isArray(): boolean { return false; }
public isObject(): boolean { return false; }
public isImage(): boolean { return false; }
public isEngine(): boolean { return false; }
2021-04-04 19:21:17 +08:00
}
export class TextData extends Info {
constructor() {
super();
this.type = DataType.Text;
}
2024-01-09 15:33:34 +08:00
public isText(): boolean { return true; }
2021-04-04 19:21:17 +08:00
}
2021-11-06 20:19:21 +08:00
export interface ObjectItemRequestData {
id: string | null;
data: Property[];
}
2021-11-17 23:28:40 +08:00
export interface FrameDetails {
frameID: number;
url: string;
}
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;
}
2024-01-09 15:33:34 +08:00
public isEngine(): boolean { return true; }
2021-06-19 19:51:05 +08:00
}
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;
}
2024-01-09 15:33:34 +08:00
public isArray(): boolean { return true; }
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;
}
2024-01-09 15:33:34 +08:00
public isObject(): boolean { return true; }
2021-04-05 19:31:34 +08:00
}
2021-11-06 21:42:37 +08:00
export class InvalidData extends Info {
2021-11-09 15:24:10 +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
}
2024-01-09 15:33:34 +08:00
public isInvalid(): boolean { return true; }
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;
}
2024-01-09 15:33:34 +08:00
public isColor(): boolean { return true; }
2021-04-05 18:38:44 +08:00
}
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
}
2024-01-09 15:33:34 +08:00
public isString(): boolean { return true; }
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
}
2024-01-09 15:33:34 +08:00
public isNumber(): boolean { return true; }
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;
}
2024-01-09 15:33:34 +08:00
public isBool(): boolean { return true; }
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
}
2024-01-09 15:33:34 +08:00
public isVec2(): boolean {
return true;
}
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
}
2024-01-09 15:33:34 +08:00
public isVec3(): boolean {
return true;
}
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
}
2024-01-09 15:33:34 +08:00
public isImage(): boolean { return true; }
2021-04-04 19:21:17 +08:00
}
export class EnumData extends Info {
2024-01-09 12:02:47 +08:00
public values: Array<{ name: string, value: any }> = [];
2021-04-04 19:21:17 +08:00
constructor() {
super();
this.type = DataType.Enum;
}
2024-01-09 12:02:47 +08:00
public isEnum(): boolean {
return 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-12-05 18:21:00 +08:00
public id: string = "";
2021-11-06 20:19:21 +08:00
public name: string = "group";
2021-04-05 18:38:44 +08:00
public data: Array<Property> = [];
2024-01-09 12:02:47 +08:00
constructor(name: string, id?: string) {
2021-04-05 18:38:44 +08:00
this.name = name;
2024-01-09 12:02:47 +08:00
this.id = id || '';
2021-04-05 18:38:44 +08:00
}
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
}
2021-11-20 21:57:54 +08:00
export interface NodeInfoData {
uuid: string;// 节点的uuid
group: Group[];
}