move more code to Graphics
This commit is contained in:
parent
73872ebb6f
commit
1605fdfc99
2 changed files with 27 additions and 21 deletions
|
|
@ -212,6 +212,16 @@ function mapBitmapToAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawBitmap(adapter, bitmap, pos) {
|
||||||
|
const rect = bitmap.getBoundingRect()
|
||||||
|
mapBitmapToAdapter(
|
||||||
|
bitmap,
|
||||||
|
rect,
|
||||||
|
adapter,
|
||||||
|
rect.moved(pos.x, pos.y)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
createCanvas,
|
createCanvas,
|
||||||
dataToBitmap,
|
dataToBitmap,
|
||||||
|
|
@ -225,4 +235,5 @@ export default {
|
||||||
fillBitmapCapped,
|
fillBitmapCapped,
|
||||||
mapBitmapToAdapter,
|
mapBitmapToAdapter,
|
||||||
mapBitmapToAdapterCapped,
|
mapBitmapToAdapterCapped,
|
||||||
|
drawBitmap,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import Bitmap from './Bitmap.js'
|
||||||
import {run} from './gameloop.js'
|
import {run} from './gameloop.js'
|
||||||
import Camera from './Camera.js'
|
import Camera from './Camera.js'
|
||||||
import EventAdapter from './EventAdapter.js'
|
import EventAdapter from './EventAdapter.js'
|
||||||
import WsClient from './WsClient.js'
|
|
||||||
import Graphics from './Graphics.js'
|
import Graphics from './Graphics.js'
|
||||||
import Debug from './Debug.js'
|
import Debug from './Debug.js'
|
||||||
import Communication from './Communication.js'
|
import Communication from './Communication.js'
|
||||||
|
|
@ -635,12 +634,18 @@ async function main () {
|
||||||
if (DEBUG) Debug.checkpoint('after fill')
|
if (DEBUG) Debug.checkpoint('after fill')
|
||||||
|
|
||||||
// draw the puzzle board on the table
|
// draw the puzzle board on the table
|
||||||
Graphics.mapBitmapToBitmapCapped(board, board.getBoundingRect(), puzzleTable, new BoundingRectangle(
|
Graphics.mapBitmapToBitmapCapped(
|
||||||
boardPos.x,
|
board,
|
||||||
boardPos.x + board.width - 1,
|
board.getBoundingRect(),
|
||||||
boardPos.y,
|
puzzleTable,
|
||||||
boardPos.y + board.height - 1,
|
new BoundingRectangle(
|
||||||
), rectTable.get())
|
boardPos.x,
|
||||||
|
boardPos.x + board.width - 1,
|
||||||
|
boardPos.y,
|
||||||
|
boardPos.y + board.height - 1,
|
||||||
|
),
|
||||||
|
rectTable.get()
|
||||||
|
)
|
||||||
|
|
||||||
if (DEBUG) Debug.checkpoint('imgtoimg')
|
if (DEBUG) Debug.checkpoint('imgtoimg')
|
||||||
|
|
||||||
|
|
@ -704,20 +709,10 @@ async function main () {
|
||||||
|
|
||||||
if (rerenderPlayer) {
|
if (rerenderPlayer) {
|
||||||
for (let id of Object.keys(players)) {
|
for (let id of Object.keys(players)) {
|
||||||
let p = players[id]
|
const p = players[id]
|
||||||
let cursor = p.down ? cursorGrab : cursorHand
|
const cursor = p.down ? cursorGrab : cursorHand
|
||||||
let back = viewport.worldToViewport(p)
|
const pos = viewport.worldToViewport(p)
|
||||||
Graphics.mapBitmapToAdapter(
|
Graphics.drawBitmap(adapter, cursor, pos)
|
||||||
cursor,
|
|
||||||
cursor.getBoundingRect(),
|
|
||||||
adapter,
|
|
||||||
new BoundingRectangle(
|
|
||||||
back.x - (cursor.width / 2),
|
|
||||||
back.x - (cursor.width / 2) + cursor.width - 1,
|
|
||||||
back.y - (cursor.width / 2),
|
|
||||||
back.y - (cursor.width / 2) + cursor.height - 1,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG) Debug.checkpoint('after_players')
|
if (DEBUG) Debug.checkpoint('after_players')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue