Still WIP

This commit is contained in:
barsdeveloper
2024-05-28 16:44:39 +02:00
parent 70b4cabb97
commit 1c2778fbf8
62 changed files with 2480 additions and 2853 deletions

View File

@@ -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() {