mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Add reference node and schema registry
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { DataModel } from '../model/DataModel'
|
||||
import { TreeView } from '../view/TreeView'
|
||||
import { SourceView } from '../view/SourceView'
|
||||
import { PredicateSchema } from '../schemas/PredicateSchema'
|
||||
import { ConditionSchema } from '../schemas/ConditionSchema'
|
||||
import { SandboxSchema } from '../schemas/SandboxSchema'
|
||||
|
||||
const predicateModel = new DataModel(PredicateSchema)
|
||||
const predicateModel = new DataModel(ConditionSchema)
|
||||
const sandboxModel = new DataModel(SandboxSchema)
|
||||
|
||||
let model = predicateModel
|
||||
|
||||
@@ -69,7 +69,7 @@ export abstract class AbstractNode<T> implements INode<T> {
|
||||
|
||||
transform(path: Path, value: T) {
|
||||
if (!this.enabled(path)) return undefined
|
||||
if (this.force()) value = this.default(value)!
|
||||
if (value === undefined && this.force()) value = this.default(value)!
|
||||
return this.transformMod(value)
|
||||
}
|
||||
|
||||
|
||||
33
src/nodes/ReferenceNode.ts
Normal file
33
src/nodes/ReferenceNode.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { AbstractNode, NodeChildren, NodeMods, RenderOptions, INode } from './AbstractNode'
|
||||
import { TreeView } from '../view/TreeView'
|
||||
import { Path } from '../model/Path'
|
||||
import { SchemaRegistry } from '../schemas/SchemaRegistry'
|
||||
|
||||
export class ReferenceNode extends AbstractNode<any> {
|
||||
protected reference: string
|
||||
|
||||
constructor(reference: string, mods?: NodeMods<any>) {
|
||||
super(mods)
|
||||
this.reference = reference
|
||||
}
|
||||
|
||||
get(): INode<any> {
|
||||
return SchemaRegistry.get(this.reference)
|
||||
}
|
||||
|
||||
default(value?: any) {
|
||||
return this.get().default(value)
|
||||
}
|
||||
|
||||
transform(path: Path, value: any) {
|
||||
return this.get().transform(path, value)
|
||||
}
|
||||
|
||||
render(path: Path, value: any, view: TreeView, options?: RenderOptions) {
|
||||
return this.get().render(path, value, view, options)
|
||||
}
|
||||
|
||||
renderRaw(path: Path, value: any, view: TreeView, options?: RenderOptions) {
|
||||
return this.get().renderRaw(path, value, view, options)
|
||||
}
|
||||
}
|
||||
59
src/schemas/Collections.ts
Normal file
59
src/schemas/Collections.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
export const conditions = [
|
||||
'alternative',
|
||||
'requirements',
|
||||
'inverted',
|
||||
'reference',
|
||||
'entity_properties',
|
||||
'block_state_property',
|
||||
'match_tool',
|
||||
'damage_source_properties',
|
||||
'location_check',
|
||||
'weather_check',
|
||||
'time_check',
|
||||
'entity_scores',
|
||||
'random_chance',
|
||||
'random_chance_with_looting',
|
||||
'table_bonus',
|
||||
'killed_by_player',
|
||||
'survives_explosion'
|
||||
]
|
||||
|
||||
export const enchantments = [
|
||||
'aqua_affinity',
|
||||
'bane_of_arthropods',
|
||||
'blast_protection',
|
||||
'channeling',
|
||||
'binding_curse',
|
||||
'vanishing_curse',
|
||||
'depth_strider',
|
||||
'efficiency',
|
||||
'feather_falling',
|
||||
'fire_aspect',
|
||||
'fire_protection',
|
||||
'flame',
|
||||
'fortune',
|
||||
'frost_walker',
|
||||
'impaling',
|
||||
'infinity',
|
||||
'knockback',
|
||||
'looting',
|
||||
'loyalty',
|
||||
'luck_of_the_sea',
|
||||
'lure',
|
||||
'mending',
|
||||
'multishot',
|
||||
'piercing',
|
||||
'power',
|
||||
'projectile_protection',
|
||||
'protection',
|
||||
'punch',
|
||||
'quick_charge',
|
||||
'respiration',
|
||||
'riptide',
|
||||
'sharpness',
|
||||
'silk_touch',
|
||||
'smite',
|
||||
'sweeping',
|
||||
'thorns',
|
||||
'unbreaking'
|
||||
]
|
||||
@@ -7,76 +7,20 @@ import { ListNode } from '../nodes/ListNode';
|
||||
import { RangeNode } from '../nodes/custom/RangeNode';
|
||||
import { MapNode } from '../nodes/MapNode';
|
||||
import { StringNode } from '../nodes/StringNode';
|
||||
import { INode } from '../nodes/AbstractNode';
|
||||
import { ReferenceNode } from '../nodes/ReferenceNode';
|
||||
import { SchemaRegistry } from './SchemaRegistry';
|
||||
|
||||
const conditions = [
|
||||
'alternative',
|
||||
'requirements',
|
||||
'inverted',
|
||||
'reference',
|
||||
'entity_properties',
|
||||
'block_state_property',
|
||||
'match_tool',
|
||||
'damage_source_properties',
|
||||
'location_check',
|
||||
'weather_check',
|
||||
'time_check',
|
||||
'entity_scores',
|
||||
'random_chance',
|
||||
'random_chance_with_looting',
|
||||
'table_bonus',
|
||||
'killed_by_player',
|
||||
'survives_explosion'
|
||||
]
|
||||
|
||||
const enchantments = [
|
||||
'aqua_affinity',
|
||||
'bane_of_arthropods',
|
||||
'blast_protection',
|
||||
'channeling',
|
||||
'binding_curse',
|
||||
'vanishing_curse',
|
||||
'depth_strider',
|
||||
'efficiency',
|
||||
'feather_falling',
|
||||
'fire_aspect',
|
||||
'fire_protection',
|
||||
'flame',
|
||||
'fortune',
|
||||
'frost_walker',
|
||||
'impaling',
|
||||
'infinity',
|
||||
'knockback',
|
||||
'looting',
|
||||
'loyalty',
|
||||
'luck_of_the_sea',
|
||||
'lure',
|
||||
'mending',
|
||||
'multishot',
|
||||
'piercing',
|
||||
'power',
|
||||
'projectile_protection',
|
||||
'protection',
|
||||
'punch',
|
||||
'quick_charge',
|
||||
'respiration',
|
||||
'riptide',
|
||||
'sharpness',
|
||||
'silk_touch',
|
||||
'smite',
|
||||
'sweeping',
|
||||
'thorns',
|
||||
'unbreaking'
|
||||
]
|
||||
import { conditions, enchantments } from './Collections'
|
||||
|
||||
const entitySources = ['this', 'killer', 'killer_player']
|
||||
|
||||
export let PredicateSchema: FilteredNode
|
||||
PredicateSchema = new FilteredNode('condition', {
|
||||
export const ConditionSchema = new FilteredNode('condition', {
|
||||
condition: new EnumNode(conditions, 'random_chance'),
|
||||
[Switch]: {
|
||||
'alternative': {
|
||||
// terms: new ListNode(PredicateSchema()),
|
||||
terms: new ListNode(
|
||||
new ReferenceNode('condition')
|
||||
),
|
||||
},
|
||||
'block_state_property': {
|
||||
block: new ResourceNode(),
|
||||
@@ -100,7 +44,7 @@ PredicateSchema = new FilteredNode('condition', {
|
||||
)
|
||||
},
|
||||
'inverted': {
|
||||
// term: PredicateSchema,
|
||||
term: new ReferenceNode('condition')
|
||||
},
|
||||
'killed_by_player': {
|
||||
inverse: new BooleanNode()
|
||||
@@ -121,6 +65,11 @@ PredicateSchema = new FilteredNode('condition', {
|
||||
chance: new NumberNode({min: 0, max: 1}),
|
||||
looting_multiplier: new NumberNode(),
|
||||
},
|
||||
'requirements': {
|
||||
terms: new ListNode(
|
||||
new ReferenceNode('condition')
|
||||
),
|
||||
},
|
||||
'reference': {
|
||||
name: new StringNode(),
|
||||
},
|
||||
@@ -145,3 +94,5 @@ PredicateSchema = new FilteredNode('condition', {
|
||||
chance: 0.5
|
||||
})
|
||||
})
|
||||
|
||||
SchemaRegistry.register('condition', ConditionSchema)
|
||||
17
src/schemas/SchemaRegistry.ts
Normal file
17
src/schemas/SchemaRegistry.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { INode } from "../nodes/AbstractNode";
|
||||
|
||||
type Registry = {
|
||||
[id: string]: INode<any>
|
||||
}
|
||||
|
||||
export class SchemaRegistry {
|
||||
private static registery: Registry = {}
|
||||
|
||||
static register(id: string, node: INode<any>) {
|
||||
SchemaRegistry.registery[id] = node
|
||||
}
|
||||
|
||||
static get(id: string): INode<any> {
|
||||
return SchemaRegistry.registery[id]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user