@beetpx/beetpx
Version:
A TypeScript framework for pixel art browser games.
65 lines • 2.1 kB
JavaScript
import { $v } from "../../shorthands";
export class DrawLine {
constructor(canvas) {
this.
}
draw(xy, wh, color, pattern) {
const xyStart = xy.round();
const xyEnd = xy.add(wh).round();
if (xyEnd.x - xyStart.x === 0 || xyEnd.y - xyStart.y === 0) {
return;
}
wh = xyEnd.sub(xyStart);
const whSub1 = wh.sub(wh.sign());
const c1 = color.type === "pattern" ? color.primary : color;
const c2 = color.type === "pattern" ? color.secondary : null;
const sn = c1?.type === "canvas_snapshot_mapping"
? this.
: null;
const fp = pattern;
let dXy = whSub1.abs().mul($v(1, -1));
let currentXy = xyStart;
const targetXy = xyStart.add(whSub1);
const step = whSub1.sign();
let err = dXy.x + dXy.y;
while (true) {
this.
if (currentXy.eq(targetXy))
break;
const errBeforeStep = err;
if (2 * errBeforeStep >= dXy.y) {
currentXy = currentXy.add($v(step.x, 0));
err += dXy.y;
}
if (2 * errBeforeStep <= dXy.x) {
currentXy = currentXy.add($v(0, step.y));
err += dXy.x;
}
}
}
if (!this.
return;
}
if (pattern.hasPrimaryColorAt(x, y)) {
if (!c1) {
}
else if (c1.type === "rgb") {
this.
}
else {
const mapped = c1.getMappedColor(snapshot, x, y);
if (mapped) {
this.
}
}
}
else {
if (c2 != null) {
this.
}
}
}
}
//# sourceMappingURL=DrawLine.js.map