Skip to content

Commit

Permalink
visions: add portals
Browse files Browse the repository at this point in the history
  • Loading branch information
macabeus committed Jun 22, 2019
1 parent 3e1127c commit 904c6c2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
28 changes: 28 additions & 0 deletions brush/src/components/Map/Point/PortalPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Star } from 'react-konva'

const SIZE = 4
const SCALE = 8

const PortalPoint = ({ x, y }) => (
<Star
stroke="blue"
strokeWidth={2}
height={SIZE * 4}
width={SIZE * 4}
x={
((x * SIZE) / SCALE) - (SIZE - 8)
}
y={
((y * SIZE) / SCALE) - SIZE
}
/>
)

PortalPoint.propTypes = {
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
}

export default PortalPoint
34 changes: 34 additions & 0 deletions brush/src/components/Map/PortalsLayer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Layer } from 'react-konva'
import PortalPoint from '../Point/PortalPoint'

const PortalsLayer = ({ vision }) => {
const { portals } = vision

const portalList = portals
.map(portalEntry => portalEntry.data)
.map(portalData => (
<PortalPoint
key={`${portalData.x} ${portalData.y}`}
x={portalData.x}
y={portalData.y}
/>
))

return (
<Layer>
{portalList}
</Layer>
)
}

PortalsLayer.propTypes = {
vision: PropTypes.shape({
portals: PropTypes.arrayOf(PropTypes.shape({
data: PropTypes.object.isRequired,
})).isRequired,
}).isRequired,
}

export default PortalsLayer
2 changes: 2 additions & 0 deletions brush/src/components/Map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import VisionContext from '../../context/VisionContext'
import TilemapLayer from './TilemapLayer'
import DrawingLayer from './DrawingLayer'
import OAMLayer from './OAMLayer'
import PortalsLayer from './PortalsLayer'
import GridLayer from './GridLayer'
import useWhenVisionChanges from '../../hooks/useWhenVisionChanges'

Expand Down Expand Up @@ -51,6 +52,7 @@ const Map = ({
totalStages={totalStages}
vision={vision}
/>}
<PortalsLayer vision={vision} />
<Layer>
<HighlightCoordinates
coordinates={highlightCoordinates}
Expand Down
16 changes: 16 additions & 0 deletions scissors/src/visionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ const extractOAM = (romBuffer, [addressStart, addressEnd]) =>
|> filter(({ data }) =>
data.kind !== null)

const extractPortals = (romBuffer, [addressStart, addressEnd]) =>
romBuffer.slice(addressStart, addressEnd)
|> splitEvery(8)
|> map(memory => ({
data: binary.parse(memory)
.word16lu('x')
.word16lu('y')
.skip(4)
.vars,
memory,
}))
|> filter(({ data }) =>
data.kind !== null)

const getVision = (romBuffer, world, vision) => {
const infos = require(`./visions/${world}-${vision}.js`).default // eslint-disable-line

Expand Down Expand Up @@ -88,10 +102,12 @@ const getVision = (romBuffer, world, vision) => {
})

const oam = extractOAM(romBuffer, infos.rom.oam)
const portals = extractPortals(romBuffer, infos.rom.portals)

return {
infos,
oam,
portals,
tilemap: tilemapProxy,
}
}
Expand Down
1 change: 1 addition & 0 deletions scissors/src/visions/1-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
rom: {
tilemap: [0x1B27FC, 0x1B36F3],
oam: [0xE2B90, 0xE2F59],
portals: [0xD48C8, 0xD48EF],
},
tilemap: {
totalStages: 3,
Expand Down
1 change: 1 addition & 0 deletions scissors/src/visions/1-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
rom: {
tilemap: [0x1B3E5C, 0x1B4AC3],
oam: [0xE3CC0, 0xE3FAC],
portals: [0xD4970, 0xD499F],
},
tilemap: {
totalStages: 3,
Expand Down
1 change: 1 addition & 0 deletions scissors/src/visions/1-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
rom: {
tilemap: [0x1B50AC, 0x1B5ECC],
oam: [0xE4DF0, 0xE5109],
portals: [0xD4A18, 0xD4A5F],
},
tilemap: {
totalStages: 5,
Expand Down

0 comments on commit 904c6c2

Please sign in to comment.