Grammar refactoring WIP

This commit is contained in:
barsdeveloper
2021-10-22 00:01:24 +02:00
parent 9caea42101
commit 051eed061d
21 changed files with 968 additions and 354 deletions

62
js/entity/Entity.js Normal file
View File

@@ -0,0 +1,62 @@
import TypeInitialization from "./TypeInitialization"
import Utility from "../Utility"
export default class Entity {
constructor(options = {}) {
/**
*
* @param {String[]} prefix
* @param {Object} target
* @param {Object} properties
*/
const defineAllAttributes = (prefix, target, properties, propertySetter = (t, p, v) => t[p] = v) => {
let fullKey = prefix.concat("")
const last = fullKey.length - 1
for (let property in properties) {
fullKey[last] = property
// Not instanceof because all objects are instenceof Object
if (properties[property]?.constructor === Object) {
propertySetter(target, property, {})
defineAllAttributes(fullKey, target[property], properties[property])
continue
}
/*
* The value can either be:
* - Array: can contain multiple values, its property is assigned multiple times like (X=1, X=4, X="Hello World")
* - TypeInitialization: contains the maximum amount of information about the attribute.
* - A type: the default value will be default constructed object without arguments.
* - A proper value.
*/
const value = Utility.objectGet(options, fullKey)
if (value !== null) {
propertySetter(target, property, value)
continue
}
let defaultValue = properties[property]
if (defaultValue instanceof Array) {
propertySetter(target, property, [])
defineAllAttributes(
fullKey,
target[property],
defaultValue,
(t, _, v) => {
console.log(v)
t.push(v)
})
continue
}
if (defaultValue instanceof TypeInitialization) {
if (!defaultValue.showDefault) {
continue
}
defaultValue = defaultValue.value
}
if (defaultValue instanceof Function) {
defaultValue = Utility.sanitize(new defaultValue())
}
propertySetter(target, property, defaultValue)
}
}
defineAllAttributes([], this, this.getAttributes())
}
}

View File

@@ -0,0 +1,16 @@
import Entity from "./Entity"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
export default class FunctionReferenceEntity extends Entity {
static attributes = {
MemberParent: new ObjectReferenceEntity({
type: "Class",
path: "/Script/Engine.GameplayStatics"
}),
MemberName: ""
}
getAttributes() {
return FunctionReferenceEntity.attributes
}
}

8
js/entity/Integer.js Normal file
View File

@@ -0,0 +1,8 @@
import Entity from "./Entity"
export default class Integer extends Entity {
constructor(value) {
super()
this.value = Math.round(new Number(value).valueOf())
}
}

View File

@@ -1,3 +1,28 @@
export default class ObjectEntity {
import Entity from "./Entity"
import FunctionReferenceEntity from "./FunctionReferenceEntity"
import Guid from "../Guid"
import Integer from "./Integer"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
import PinEntity from "./PinEntity"
import TypeInitialization from "./TypeInitialization"
import VariableReferenceEntity from "./VariableReferenceEntity"
export default class ObjectEntity extends Entity {
static attributes = {
Class: "",
Name: "",
bIsPureFunc: new TypeInitialization(false, false),
VariableReference: new TypeInitialization(new VariableReferenceEntity(), false),
FunctionReference: new TypeInitialization(new FunctionReferenceEntity(), false),
TargetType: new TypeInitialization(new ObjectReferenceEntity(), false),
NodePosX: Integer,
NodePosY: Integer,
NodeGuid: Guid,
CustomProperties: [PinEntity]
}
getAttributes() {
return ObjectEntity.attributes
}
}

View File

@@ -0,0 +1,17 @@
import Entity from "./Entity"
export default class ObjectReferenceEntity extends Entity {
static attributes = {
type: "None",
path: ""
}
getAttributes() {
return ObjectReferenceEntity.attributes
}
toString() {
return this.type + (this.path ? `'"${this.path}"'` : "")
}
}

3
js/entity/Path.js Normal file
View File

@@ -0,0 +1,3 @@
export default class Path {
}

View File

@@ -1,38 +1,39 @@
import Entity from "./Entity";
import Guid from "../Guid";
import ReferenceTypeName from "../serialization/ReferenceTypeName";
import Utility from "../Utility"
import ObjectReferenceEntity from "./ObjectReferenceEntity";
import TypeInitialization from "./TypeInitialization";
export default class PinEntity {
static optionalKeys = ['Direction']
constructor(options = {}) {
const getOrFalse = (keys) => Utility.objectGet(keys, false, options)
const getOrEmptyString = (keys) => Utility.objectGet(keys, "", options)
this.PinId = new Guid(Utility.objectGet(["PinId"], true, options))
this.PinName = getOrEmptyString(["PinName"])
this.PinToolTip = getOrEmptyString(["PinToolTip"])
this.Direction = getOrEmptyString(["Direction"])
this.PinType = {
PinCategory: getOrEmptyString(["PinType", "PinCategory"]),
PinSubCategory: getOrEmptyString(["PinType", "PinSubCategory"]),
PinSubCategoryObject: Utility.objectGet(["PinType", "PinSubCategoryObject"], ReferenceTypeName.None, options),
PinSubCategoryMemberReference: Utility.objectGet(["PinType", "PinSubCategoryMemberReference"], null, options),
PinValueType: getOrFalse(["PinType", "PinValueType"]),
ContainerType: Utility.objectGet(["PinType", "ContainerType"], ReferenceTypeName.None, options),
bIsReference: getOrFalse(["PinType", "bIsReference"]),
bIsConst: getOrFalse(["PinType", "bIsConst"]),
bIsWeakPointer: getOrFalse(["PinType", "bIsWeakPointer"]),
bIsUObjectWrapper: getOrFalse(["PinType", "bIsUObjectWrapper"])
}
this.LinkedTo = Utility.objectGet(["LinkedTo"], null, options)
this.DefaultValue = getOrFalse(["DefaultValue"])
this.AutogeneratedDefaultValue = getOrFalse(["AutogeneratedDefaultValue"])
this.PersistentGuid = new Guid(getOrFalse(["PersistentGuid"]))
this.bHidden = getOrFalse(["bHidden"])
this.bNotConnectable = getOrFalse(["bNotConnectable"])
this.bDefaultValueIsReadOnly = getOrFalse(["bDefaultValueIsReadOnly"])
this.bDefaultValueIsIgnored = getOrFalse(["bDefaultValueIsIgnored"])
this.bAdvancedView = getOrFalse(["bAdvancedView"])
this.bOrphanedPin = getOrFalse(["bOrphanedPin"])
export default class PinEntity extends Entity {
static attributes = {
PinId: Guid,
PinName: [new TypeInitialization(5, true), "ciao"],
PinToolTip: "",
Direction: new TypeInitialization("", false),
PinType: {
PinCategory: "",
PinSubCategory: "",
PinSubCategoryObject: ObjectReferenceEntity,
PinSubCategoryMemberReference: null,
PinValueType: null,
ContainerType: ObjectReferenceEntity,
bIsReference: false,
bIsConst: false,
bIsWeakPointer: false,
bIsUObjectWrapper: false
},
LinkedTo: Guid,
DefaultValue: "",
AutogeneratedDefaultValue: "",
PersistentGuid: Guid,
bHidden: false,
bNotConnectable: false,
bDefaultValueIsReadOnly: false,
bDefaultValueIsIgnored: false,
bAdvancedView: false,
bOrphanedPin: false,
}
getAttributes() {
return PinEntity.attributes
}
}

View File

@@ -0,0 +1,12 @@
import Utility from "../Utility"
export default class TypeInitialization {
constructor(value, showDefault = true, type = Utility.getType(value)) {
if (type.prototype.constructor.name != value.constructor.name) {
throw new Error("Default value expected to be of the same type.")
}
this.value = value
this.showDefault = showDefault
this.type = type
}
}

View File

@@ -0,0 +1,15 @@
import Guid from "../Guid"
import Entity from "./Entity"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
export default class VariableReferenceEntity extends Entity {
static attributes = {
MemberName: "",
MemberGuid: Guid,
bSelfContext: true
}
getAttributes() {
return VariableReferenceEntity.attributes
}
}