remove old parser

This commit is contained in:
Rowan 2024-11-20 14:59:03 -06:00
parent 7bbc6008f5
commit 18a0f8656b

View file

@ -1,49 +0,0 @@
import { defineQuery, hasComponent } from 'bitecs'
/// danm this rules !!!
const re = /\((?<fromName>\w+)?:(?<fromLabel>\w+)\)(-\[(?<edgeName>\w+)?:(?<edgeLabel>\w+)\]->\((?<toName>\w+)?:(?<toLabel>\w+)\))*/
const node = (name, label) => ({ name, label })
const parse = s => {
const result = s.match(re)
const groups = result.groups
return {
from: node(groups.fromName || 'a', groups.fromLabel),
to: node(groups.toName || 'b', groups.toLabel),
edge: node(groups.edgeName, groups.edgeLabel)
}
}
export const query = (world, s) => {
const meta = parse(s)
const from = world.components[meta.from.label]
const to = world.components[meta.to.label]
const edge = world.components[meta.edge.label]
const fromQuery = defineQuery([from])
const toQuery = defineQuery([to])
const edgeQuery = defineQuery([edge])
return (world) => {
const result = []
const fq = fromQuery(world)
const tq = toQuery(world)
const eq = edgeQuery(world)
for(const feid of fq) {
const targets = []
for(const eeid of eq) {
if(edge.from[eeid] === feid && hasComponent(world, to, edge.to[eeid])) {
targets.push(edge.to[eeid])
}
}
result.push({ [feid]: targets })
}
return result
}
}