Skip to content

Commit c992331

Browse files
committed
feat: backlinks
1 parent de03090 commit c992331

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

src/index.css

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ body {
6363
width: 10px;
6464
height: 10px;
6565
border-radius: 999999px;
66-
background: #e02020;
66+
background: #20e0e0;
6767
}
6868
.warp-oneway {
6969
background: #2020e0;
@@ -78,10 +78,20 @@ body {
7878
background: #20e020;
7979
}
8080

81+
.marker-backlink {
82+
transform: translate(-50%, -50%);
83+
position: absolute;
84+
width: 10px;
85+
height: 10px;
86+
border-radius: 999999px;
87+
background: #e0e020;
88+
}
89+
8190
#element {
91+
padding: 0.5rem;
8292
display: flex;
8393
flex-direction: column;
8494
}
8595
.marker-selected {
86-
filter: brightness(2);
96+
border: 2px solid red;
8797
}

src/index.ts

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,48 @@ for(const rk in allRegions) {
4343
regionNames.set(rk, regions[rk].data.name + ' (' + rk + ')')
4444
}
4545

46+
type TraceData = {
47+
type: 'warp'
48+
data: WarpPoint
49+
} | {
50+
type: 'echo'
51+
data: EchoData
52+
}
53+
type WarpTrace = {
54+
fromRegion: RegionKey
55+
fromRoom: string
56+
from: TraceData
57+
58+
}
59+
60+
const backlinks: Record<RegionKey, Record<string, WarpTrace[]>> = {}
61+
function bfill(toRegion: string | null, toRoom: string | null, trace: WarpTrace) {
62+
if(!toRegion || !toRoom) return
63+
toRegion = toRegion.toLowerCase()
64+
toRoom = toRoom.toLowerCase()
65+
66+
let a = backlinks[toRegion]
67+
if(!a) backlinks[toRegion] = a = {}
68+
let b = a[toRoom]
69+
if(!b) a[toRoom] = b = []
70+
b.push(trace)
71+
}
72+
73+
for(const regK in regions) {
74+
const region = regions[regK]
75+
for(const roomK in region.rooms) {
76+
const room = region.rooms[roomK]
77+
if(!room.data.mapPos) continue
78+
for(const wp of room.data.warpPoints) {
79+
bfill(wp.region, wp.room, { fromRegion: regK, fromRoom: roomK, from: { type: 'warp', data: wp } })
80+
}
81+
for(const wp of room.data.echoSpots) {
82+
bfill(wp.destRegion, wp.destRoom, { fromRegion: regK, fromRoom: roomK, from: { type: 'echo', data: wp } })
83+
}
84+
}
85+
}
86+
console.log(backlinks)
87+
4688
// half height of camera
4789
// const size = 384
4890

@@ -54,7 +96,7 @@ const context = {
5496
camera: {
5597
posX: 0,
5698
posY: 0,
57-
scale: 500,
99+
scale: 300,
58100
},
59101
canvasSize: [1, 1],
60102
sizes: { fontSize: 16, heightCssPx: 1000 },
@@ -127,8 +169,13 @@ type Marker = {
127169
position: [number, number]
128170
data: EchoData
129171
}
172+
| {
173+
type: 'backlink'
174+
position: [number, number]
175+
data: WarpTrace
176+
}
130177

131-
function showRegion(regionName: RegionKey, region: Region, pos?: [number, number]) {
178+
function showRegion(regionName: RegionKey, region: Region, pos?: [number, number], layerI?: number) {
132179
inner.innerHTML = ''
133180
var minX = Infinity
134181
var maxX = -Infinity
@@ -177,15 +224,16 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
177224
lget(layerEls, layer).append(image)
178225
}
179226

227+
const mx = totalX / count
228+
const my = totalY / count
229+
180230
for(let i = 0; i < room.data.warpPoints.length; i++) {
181231
const it = room.data.warpPoints[i]
182232

183233
const v = lget(markerLayerEls, layer)
184234
const m = document.createElement('div')
185235
m.classList.add('marker-warp')
186236
if(it.oneWay) m.classList.add('warp-oneway')
187-
const mx = totalX / count
188-
const my = totalY / count
189237
m.style.left = mx + 'px'
190238
m.style.top = -my + 'px'
191239
v.append(m)
@@ -198,13 +246,22 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
198246
const v = lget(markerLayerEls, layer)
199247
const m = document.createElement('div')
200248
m.classList.add('marker-echo')
201-
const mx = totalX / count
202-
const my = totalY / count
203249
m.style.left = mx + 'px'
204250
m.style.top = -my + 'px'
205251
v.append(m)
206252
markers.push({ type: 'echo', position: [mx, my], data: it, element: m })
207253
}
254+
255+
const backlink = backlinks[regionName.toLowerCase()]?.[k.toLowerCase()]
256+
for(let i = 0; backlink && i < backlink.length; i++) {
257+
const v = lget(markerLayerEls, layer)
258+
const m = document.createElement('div')
259+
m.classList.add('marker-backlink')
260+
m.style.left = mx + 'px'
261+
m.style.top = -my + 'px'
262+
v.append(m)
263+
markers.push({ type: 'backlink', position: [mx, my], data: backlink[i], element: m })
264+
}
208265
}
209266

210267
const layersArr = [...layers]
@@ -219,14 +276,19 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
219276
if(e) inner.append(e)
220277
}
221278

222-
let curLayer = layersArr[0]
279+
let curLayer = layersArr[layerI ?? 0]
223280
function setLayer(l: number) {
224281
curLayer = l
225282
for(const ol of layersArr) {
226283
const el = layerEls.get(ol)
227284
if(!el) continue
228285
el.style.opacity = l == ol ? '1' : '0.2'
229286
}
287+
for(const ol of layersArr) {
288+
const el = markerLayerEls.get(ol)
289+
if(!el) continue
290+
el.style.opacity = l == ol ? '1' : '0.5'
291+
}
230292
}
231293
setLayer(curLayer)
232294

@@ -334,7 +396,7 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
334396
const b = gotoButton(it.region, it.room)
335397
if(b) elementEl.append(b)
336398
}
337-
else {
399+
else if(c[1].type === 'echo') {
338400
const it = c[1].data
339401
elementEl.append(wrap('Echo'))
340402
elementEl.append(wrap('Destination region: ' + (it.destRegion ? regionNames.get(it.destRegion) : it.destRegion)))
@@ -343,8 +405,22 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
343405
const b = gotoButton(it.destRegion, it.destRoom)
344406
if(b) elementEl.append(b)
345407
}
408+
else {
409+
const it = c[1].data
410+
elementEl.append(wrap('Other side of a warp'))
411+
elementEl.append(wrap('From region: ' + (it.fromRegion ? regionNames.get(it.fromRegion) : it.fromRegion)))
412+
elementEl.append(wrap('From room: ' + it.fromRoom))
413+
//elementEl.append(wrap('Destination position: ' + it.destPos))
414+
const b = gotoButton(it.fromRegion, it.fromRoom)
415+
if(b) elementEl.append(b)
416+
}
346417
}
347418
}
348419
}
349420

350421
fillRegions(null)
422+
423+
{
424+
setSelected(regionEls.get('HI'))
425+
showRegion('HI', regions['HI'], [-150, 150], 1)
426+
}

0 commit comments

Comments
 (0)