From 17554712349da6075386da08476e81814717f609 Mon Sep 17 00:00:00 2001 From: Ben Creech Date: Sun, 11 Feb 2024 20:00:11 -0500 Subject: [PATCH] Abstract Display --- src/display.ts | 42 +++++++++++++++++++++++++++++++++++++----- src/main.ts | 4 ++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/display.ts b/src/display.ts index 9c94cb7..768955b 100644 --- a/src/display.ts +++ b/src/display.ts @@ -1,6 +1,42 @@ import { Point } from "./point.ts"; -export class Display { +export interface Display { + readonly canvasSize: Point; + + clearRect(corner: Point, size: Point): void; + + strokeRect(corner: Point, size: Point): void; + + translate(dist: Point): void; + + scale(amount: Point): void; + + restore(): void; + + save(): void; + + stroke(): void; + + beginPath(): void; + + closePath(): void; + + moveTo(point: Point): void; + + lineTo(point: Point): void; + + fill(): void; + + bezierCurveTo(cp1: Point, cp2: Point, ep: Point): void; + + quadraticCurveTo(cp: Point, ep: Point): void; + + set lineWidth(width: number); + + set strokeStyle(style: string); +} + +export class DisplayImpl implements Display { constructor( public readonly canvasSize: Point, private readonly context: CanvasRenderingContext2D, @@ -18,10 +54,6 @@ export class Display { this.context.translate(dist.x, dist.y); } - rotate(rads: number) { - this.context.rotate(rads); - } - scale(amount: Point) { this.context.scale(amount.x, amount.y); } diff --git a/src/main.ts b/src/main.ts index d61dd5e..f0c0357 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import { Game } from "./game.ts"; -import { Display } from "./display.ts"; +import { DisplayImpl } from "./display.ts"; import { GameTextImpl } from "./gametext.ts"; import { KeyboardImpl } from "./keyboard.ts"; import { Point } from "./point.ts"; @@ -13,7 +13,7 @@ const canvas: HTMLCanvasElement = document.getElementById( "canvas", )! as HTMLCanvasElement; -const display = new Display( +const display = new DisplayImpl( new Point(canvas.width, canvas.height), canvas.getContext("2d")!, );