move more code to Graphics

This commit is contained in:
Zutatensuppe 2020-11-09 20:30:37 +01:00
parent 73872ebb6f
commit 1605fdfc99
2 changed files with 27 additions and 21 deletions

View file

@ -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,
} }

View file

@ -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(
board,
board.getBoundingRect(),
puzzleTable,
new BoundingRectangle(
boardPos.x, boardPos.x,
boardPos.x + board.width - 1, boardPos.x + board.width - 1,
boardPos.y, boardPos.y,
boardPos.y + board.height - 1, boardPos.y + board.height - 1,
), rectTable.get()) ),
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')