mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-28 03:24:43 +08:00
Entities cleanup, Primitive concept introduced
This commit is contained in:
32
js/entity/primitive/Guid.js
Normal file
32
js/entity/primitive/Guid.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import Primitive from "./Primitive";
|
||||
|
||||
export default class Guid extends Primitive {
|
||||
|
||||
static generateGuid(random) {
|
||||
let values = new Uint32Array(4);
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
let result = ""
|
||||
values.forEach(n => {
|
||||
result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
super()
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (guid?.constructor === Boolean) {
|
||||
guid = Guid.generateGuid(guid == true)
|
||||
}
|
||||
if (guid instanceof Guid) {
|
||||
guid = guid.value
|
||||
}
|
||||
this.value = guid
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
25
js/entity/primitive/Integer.js
Normal file
25
js/entity/primitive/Integer.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class Integer extends Primitive {
|
||||
|
||||
constructor(value) {
|
||||
super()
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (value?.constructor === String) {
|
||||
value = Number(value)
|
||||
}
|
||||
if (value?.constructor === Number) {
|
||||
value = Math.round(value)
|
||||
}
|
||||
/** @type {number} */
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
22
js/entity/primitive/LocalizedTextEntity.js
Normal file
22
js/entity/primitive/LocalizedTextEntity.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class LocalizedTextEntity extends Primitive {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @param {String} key
|
||||
* @param {String} value
|
||||
*/
|
||||
constructor(namespace, key, value) {
|
||||
super()
|
||||
this.namespace = namespace
|
||||
this.key = key
|
||||
this.value = value
|
||||
}
|
||||
|
||||
toString() {
|
||||
"NSLOCTEXT(" + `"${this.namespace}"` + ", " + `"${this.key}"` + ", " + `"${this.value}"` + ")"
|
||||
}
|
||||
|
||||
}
|
||||
23
js/entity/primitive/ObjectReference.js
Normal file
23
js/entity/primitive/ObjectReference.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class ObjectReference extends Primitive {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {String} path
|
||||
*/
|
||||
constructor(type, path) {
|
||||
super()
|
||||
this.type = type
|
||||
this.path = path
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (this.type ?? "") + (
|
||||
this.path
|
||||
? this.type ? `'"${this.path}"'` : this.path
|
||||
: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
5
js/entity/primitive/Primitive.js
Normal file
5
js/entity/primitive/Primitive.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default class Primitive {
|
||||
toString() {
|
||||
return "Unimplemented for " + this.constructor.name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user