-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MeshJS/feature/blueprint-utils
feat: wip
- Loading branch information
Showing
12 changed files
with
1,191 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable max-classes-per-file */ | ||
|
||
import { BuiltinByteString, ConStr, Integer } from '../type'; | ||
|
||
export class ByteArray { | ||
public bytes: string = ''; | ||
|
||
constructor(bytes?: string) { | ||
if (bytes) this.bytes = bytes; | ||
} | ||
|
||
public toObject(): BuiltinByteString { | ||
return { | ||
bytes: this.bytes, | ||
}; | ||
} | ||
} | ||
|
||
export class Int { | ||
public int: number = 0; | ||
|
||
constructor(int?: number) { | ||
if (int) this.int = int; | ||
} | ||
|
||
public toObject(): Integer { | ||
return { | ||
int: this.int, | ||
}; | ||
} | ||
} | ||
|
||
export class Constructor { | ||
public conStr: number = 0; | ||
|
||
public fields: any[] = []; | ||
|
||
constructor(conStr: number, fields: any[]) { | ||
if (conStr) this.conStr = conStr; | ||
if (fields) this.fields = fields; | ||
} | ||
|
||
public toObject(): ConStr { | ||
return { | ||
constructor: this.conStr, | ||
fields: this.fields, | ||
}; | ||
} | ||
} | ||
|
||
export type BlueprintDefinition = Constructor | ByteArray | Int; | ||
|
||
export const parseBlueprintDefinition = (item: any, args = []): Constructor | ByteArray | Int => { | ||
switch (item.dataType) { | ||
case 'bytes': | ||
return new ByteArray(...args); | ||
case 'integer': | ||
return new Int(...args); | ||
// case 'constructor': | ||
// return Constructor; | ||
default: | ||
throw new Error(`Unknown data type: ${item.dataType}`); | ||
} | ||
}; | ||
|
||
// export class MeshBlueprint { | ||
// constructor() {} | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.