mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-14 04:13:25 +08:00
Still WIP
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import AttributeInfo from "./AttributeInfo.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import P from "parsernostrum"
|
||||
|
||||
var crypto
|
||||
if (typeof window === "undefined") {
|
||||
@@ -11,39 +10,21 @@ if (typeof window === "undefined") {
|
||||
|
||||
export default class GuidEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
value: AttributeInfo.createValue(""),
|
||||
}
|
||||
static grammar = this.createGrammar()
|
||||
static grammar = P.reg(/[0-9a-fA-F]{32}/).map(v => new this(v))
|
||||
|
||||
static createGrammar() {
|
||||
return Grammar.guid.map(v => new this(v))
|
||||
}
|
||||
|
||||
static generateGuid(random = true) {
|
||||
static generateGuid() {
|
||||
let values = new Uint32Array(4)
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
crypto.getRandomValues(values)
|
||||
let guid = ""
|
||||
values.forEach(n => {
|
||||
guid += ("0".repeat(8) + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return new GuidEntity({ value: guid })
|
||||
return guid
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
if (!values) {
|
||||
values = GuidEntity.generateGuid().value
|
||||
}
|
||||
if (values.constructor !== Object) {
|
||||
values = {
|
||||
value: values,
|
||||
}
|
||||
}
|
||||
super(values)
|
||||
/** @type {String} */ this.value
|
||||
constructor(value = GuidEntity.generateGuid()) {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
|
||||
Reference in New Issue
Block a user