264 lines
5.0 KiB
TypeScript
Raw Normal View History

2021-04-04 19:21:17 +08:00
export enum DataType {
Number,
String,
Text,
Vec2,
Vec3,
Enum,
Bool,
Color,
2021-04-05 19:31:34 +08:00
NullOrUndefined,
Array, // 暂时在控制台打印下
Object,
2021-06-14 19:41:58 +08:00
Image, // 图片
2021-04-04 19:21:17 +08:00
}
2021-05-08 17:52:29 +08:00
export class Info {
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-04-04 19:21:17 +08:00
}
export class TextData extends Info {
constructor() {
super();
this.type = DataType.Text;
}
}
2021-04-05 19:31:34 +08:00
export class ArrayData extends Info {
constructor() {
super();
this.type = DataType.Array;
}
}
export class ObjectData extends Info {
constructor() {
super();
this.type = DataType.Object;
}
}
export class NullOrUndefinedData extends Info {
constructor() {
super();
this.type = DataType.NullOrUndefined;
}
}
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-05-08 17:52:29 +08:00
uuid: string = '';
name: string = '';
children: Array<TreeData> = [];
2021-04-04 19:21:17 +08:00
}
2021-04-05 18:38:44 +08:00
export class Property {
public name: string = 'property';
public value: Info = new Info();
constructor(name: string, info: Info) {
this.name = name;
this.value = info;
}
}
export class Group {
public name: string = 'group';
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-05-11 22:15:29 +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-04-04 19:21:17 +08:00
export const testData = [
{
name: "group1",
2021-04-07 17:26:16 +08:00
uuid: 'node/comp uuid',
2021-04-04 19:21:17 +08:00
data: [
2021-04-07 17:26:16 +08:00
{name: "uuid", value: {type: DataType.String, data: 'abc', path: 'uuid'}},
2021-04-04 19:21:17 +08:00
{name: "opacity", value: {type: DataType.Number, data: 100}},
{
name: "size",
value: {
type: DataType.Vec2,
data: [
{name: "X", value: {type: DataType.Number, data: 100}},
{name: "Y", value: {type: DataType.Number, data: 200}},
]
}
},
{
name: "position",
value: {
type: DataType.Vec3,
data: [
{name: "X", value: {type: DataType.Number, data: 100}},
{name: "Y", value: {type: DataType.Number, data: 200}},
{name: "Z", value: {type: DataType.Number, data: 300}},
]
}
},
{
name: "layout",
value: {
type: DataType.Enum,
data: 1,
values: [
{name: "horizontal", value: 1},
{name: "vertical", value: 2},
]
}
},
{
name: "text",
value: {
type: DataType.Text,
data: 'aaaaaaaaafsf',
}
}
]
},
{
name: "group2",
data: [
{
name: "bool", value: {
type: DataType.Bool,
data: true,
}
},
{
name: 'color',
value: {
type: DataType.Color,
data: '#ff0000'
}
2021-04-06 18:41:54 +08:00
},
{
name: 'array',
value: {
type: DataType.Array,
data: [1, 2, 3, 4]
}
}, {
name: 'object',
value: {
type: DataType.Object,
data: {a: '11111111111111111111111111111111111111111111111111111111111', b: 2, c: 3}
}
2021-04-04 19:21:17 +08:00
}
]
},
];