Skip to content

Commit

Permalink
add pickup filters
Browse files Browse the repository at this point in the history
  • Loading branch information
vanaigr committed Oct 10, 2024
1 parent 8229582 commit 5dfddd2
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 63 deletions.
77 changes: 48 additions & 29 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,18 @@ const filters = [
],
],
],
['ScarabPickup', 'Show scarabs', true, 'filters', []],
['Pickup', 'Show pickups', true, 'filters', []],
['Pickup', 'Show pickups', true, 'filters', [
['CrystalKey', 'Show regular keys', true, 'filters', []],
['BossKey', 'Show boss keys', true, 'filters', []],
['CrystalBoss', 'Show boss drop keys', true, 'filters', []],
['KeyUnique', 'Show unique keys', true, 'filters', []],
['ModulePickup', 'Show module pickups', true, 'filters', []],
['SkillPickup', 'Show skill pickups', true, 'filters', []],
['StatsPickup', 'Show stats pickups', true, 'filters', []],
['ScarabPickup', 'Show scarabs', true, 'filters', []],
['LorePickup', 'Show lore tablets', true, 'filters', []],
['MapPickup', 'Show map pieces', true, 'filters', []],
]],
['Unlocker', 'Show unlockers', true, 'filters', []],
['UnlockerTrigger', 'Show unlockr triggers', true, 'filters', []],
['Torch', 'Show torches', true, 'filters', []],
Expand Down Expand Up @@ -235,6 +245,40 @@ const filters = [
]
]

function prepFiltersFilter(filter, res) {
const propFilters = []
const fieldFilters = filter[4]
for(let j = 0; j < fieldFilters.length; j++) {
const fieldFilter = fieldFilters[j]
if(!fieldFilter[2]) continue
else if(fieldFilter[3] === 'filters') {
prepFiltersFilter(fieldFilter, res)
continue
}

let values = []
if(fieldFilter[3] === 'enum') {
const filterValues = fieldFilter[4]
for(let k = 0; k < filterValues.length; k++) {
const filterValue = filterValues[k]
if(!filterValue[2]) continue
values.push(filterValue[0])
}
}
else if(fieldFilter[3] === 'boolean') {
if(fieldFilter[4][0]) values.push(false)
if(fieldFilter[4][1]) values.push(true)
}
else {
values.push(fieldFilter[4])
}

propFilters.push([fieldFilter[0], values])
}

res.push([filter[0], propFilters])
}

function extractMarkerFilters(filters) {
const res = []
if(!filters[0][2]) return res
Expand All @@ -249,34 +293,9 @@ function extractMarkerFilters(filters) {
continue
}

const propFilters = []
const fieldFilters = filter[4]
for(let j = 0; j < fieldFilters.length; j++) {
const fieldFilter = fieldFilters[j]
if(!fieldFilter[2]) continue

let values = []
if(fieldFilter[3] === 'enum') {
const filterValues = fieldFilter[4]
for(let k = 0; k < filterValues.length; k++) {
const filterValue = filterValues[k]
if(!filterValue[2]) continue
values.push(filterValue[0])
}
}
else if(fieldFilter[3] === 'boolean') {
if(fieldFilter[4][0]) values.push(false)
if(fieldFilter[4][1]) values.push(true)
}
else {
values.push(fieldFilter[4])
}

propFilters.push([fieldFilter[0], values])
}

res.push([filter[0], propFilters])
prepFiltersFilter(filter, res)
}
console.log(res)
return res
}

Expand Down
77 changes: 43 additions & 34 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,37 @@ function createOneTex(comp) {

var lastMarkerFilters

/** @type {{ [schemaI: number]: (component: any, actualComponent: any) => [textureI: number, size?: number] }} */
const displayFuncs = {
[ti.Enemy]: (it, comp) => {
const size = comp._schema === ti.Boss ? 3 : 1 + 0.33 * it.size
return [it.spriteI, size]
},
[ti.Jar]: (it, comp) => {
return [it.spriteI]
},
[ti.CrystalDestroyable]: (it, comp) => {
const ti = meta.crystalDestroyableTextures[it.dropXp ? 1 : 0]
return [ti, 1 + 0.5 * it.size]
},
[ti.ScarabPickup]: (it, comp) => {
return createOneTex(it)
},
[ti.Pickup]: (it, comp) => {
return [it.spriteI]
},
[ti.Npc]: (it, comp) => {
return [it.spriteI, 1.5]
},
[ti.Tunnel]: (it, comp) => {
return [it.spriteI, 1.5]
},
[ti.Torch]: (it, comp) => {
return [it.spriteI, 1.2]
},
}
/** @typedef {(component: any, actualComponent: any) => [textureI: number, size?: number]} DisplayFunc */
/** @type {Map<number, DisplayFunc>} */
const displayFuncs = new Map()
/**
@param {number} schemaI
@param {DisplayFunc} func
*/
function a(schemaI, func) { displayFuncs.set(schemaI, func) }

a(ti.Enemy, (it, comp) => {
const size = comp._schema === ti.Boss ? 3 : 1 + 0.33 * it.size
return [it.spriteI, size]
})

a(ti.Jar, (it, comp) => [it.spriteI])
a(ti.CrystalDestroyable, (it, comp) => {
const ti = meta.crystalDestroyableTextures[it.dropXp ? 1 : 0]
return [ti, 1 + 0.5 * it.size]
})
a(ti.ScarabPickup, (it, comp) => createOneTex(it)) // Note: flaky texture lookup in retrieve_objects.cs
;([
ti.CrystalBoss, ti.CrystalKey, ti.KeyUnique, ti.BossKey, ti.ModulePickup,
ti.SkillPickup, ti.StatsPickup, ti.LorePickup, ti.MapPickup
]).forEach(s => {
const steps = stepsToBase(s, ti.Pickup)
a(s, (it, comp) => [getBase(it, steps).spriteI])
})
a(ti.Pickup, (it, comp) => [it.spriteI])
a(ti.Npc, (it, comp) => [it.spriteI, 1.5])
a(ti.Tunnel, (it, comp) => [it.spriteI, 1.5])
a(ti.Torch, (it, comp) => [it.spriteI, 1.2])

/** @typedef {[textureI: number, x: number, y: number, size: number]} RegularDisplay */
/** @typedef {{ object: any, component: any }} MarkerInfo */
Expand Down Expand Up @@ -197,19 +199,25 @@ const objectsProcessedP = objectsLoadedP.then(objects => {
/** @type {object[]} */
const restMarkers = []

const displayKeys = [...displayFuncs.keys()]

for(const schemaI of displayKeys) {
console.log(meta.schemas[schemaI][1])
}

/** @type {[baseSteps: number, funcI: number, priority: number][]} */
const schemaDisplayFuncI = Array(meta.schemas.length)
for(let i = 0; i < meta.schemas.length; i++) {
let added = false
let si = 0
for(const schemaI in displayFuncs) {
let si = 0;
for(; si < displayKeys.length; si++) {
const schemaI = displayKeys[si]
const s = stepsToBase(i, schemaI)
if(s != null) {
schemaDisplayFuncI[i] = [s, parseInt(schemaI), si]
schemaDisplayFuncI[i] = [s, schemaI, si]
added = true
break
}
si++
}
if(!added) {
let s = stepsToBase(i, ti.Transition)
Expand Down Expand Up @@ -267,7 +275,8 @@ const objectsProcessedP = objectsLoadedP.then(objects => {
obj._markerI = regularMarkers.length
obj._markerType = 0
regularMarkers.push({ object: obj, component: it })
const r = displayFuncs[funcI](it, comp)
// @ts-ignore
const r = displayFuncs.get(funcI)(it, comp)
regularDisplays.push([r[0], obj.pos[0], obj.pos[1], r[1] ?? 1])
}
}
Expand Down

0 comments on commit 5dfddd2

Please sign in to comment.