mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Remove beginRoundedRect utility
No longer needed, as CanvasRenderingContext2D#roundRect is a built-in way to achieve the same result now.
This commit is contained in:
parent
aff7a4e0a5
commit
bd4e31653c
@ -10,29 +10,6 @@ import { Rectangle } from "./rectangle";
|
||||
const logger = createLogger("draw_utils");
|
||||
|
||||
export function initDrawUtils() {
|
||||
CanvasRenderingContext2D.prototype.beginRoundedRect = function (x, y, w, h, r) {
|
||||
this.beginPath();
|
||||
|
||||
if (r < 0.05) {
|
||||
this.rect(x, y, w, h);
|
||||
return;
|
||||
}
|
||||
|
||||
if (w < 2 * r) {
|
||||
r = w / 2;
|
||||
}
|
||||
|
||||
if (h < 2 * r) {
|
||||
r = h / 2;
|
||||
}
|
||||
|
||||
this.moveTo(x + r, y);
|
||||
this.arcTo(x + w, y, x + w, y + h, r);
|
||||
this.arcTo(x + w, y + h, x, y + h, r);
|
||||
this.arcTo(x, y + h, x, y, r);
|
||||
this.arcTo(x, y, x + w, y, r);
|
||||
};
|
||||
|
||||
CanvasRenderingContext2D.prototype.beginCircle = function (x, y, r) {
|
||||
this.beginPath();
|
||||
|
||||
|
||||
@ -1321,7 +1321,8 @@ export class BeltPath extends BasicSerializableObject {
|
||||
const nextDistanceAndItem = this.items[i];
|
||||
const worldPos = this.computePositionFromProgress(progress).toWorldSpaceCenterOfTile();
|
||||
parameters.context.fillStyle = "#268e4d";
|
||||
parameters.context.beginRoundedRect(worldPos.x - 5, worldPos.y - 5, 10, 10, 3);
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(worldPos.x - 5, worldPos.y - 5, 10, 10, 3);
|
||||
parameters.context.fill();
|
||||
parameters.context.font = "6px GameFont";
|
||||
parameters.context.fillStyle = "#111";
|
||||
|
||||
@ -371,7 +371,8 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
parameters.context.fillStyle = "rgba(255, 0, 0, 0.2)";
|
||||
}
|
||||
|
||||
parameters.context.beginRoundedRect(
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(
|
||||
entityBounds.x * globalConfig.tileSize - drawBorder,
|
||||
entityBounds.y * globalConfig.tileSize - drawBorder,
|
||||
entityBounds.w * globalConfig.tileSize + 2 * drawBorder,
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
import { clamp, makeDiv, smoothPulse } from "../../../core/utils";
|
||||
import { GameRoot } from "../../root";
|
||||
import { MinerComponent } from "../../components/miner";
|
||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||
import { TrackedState } from "../../../core/tracked_state";
|
||||
import { T } from "../../../translations";
|
||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../../components/item_processor";
|
||||
import { ShapeItem } from "../../items/shape_item";
|
||||
import { WireComponent } from "../../components/wire";
|
||||
import { LeverComponent } from "../../components/lever";
|
||||
import { DrawParameters } from "../../../core/draw_parameters";
|
||||
import { globalConfig } from "../../../core/config";
|
||||
import { Vector } from "../../../core/vector";
|
||||
import { MetaMinerBuilding } from "../../buildings/miner";
|
||||
import { DrawParameters } from "../../../core/draw_parameters";
|
||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||
import { MetaBeltBuilding } from "../../buildings/belt";
|
||||
import { MetaTrashBuilding } from "../../buildings/trash";
|
||||
import { TrackedState } from "../../../core/tracked_state";
|
||||
import { clamp, makeDiv, smoothPulse } from "../../../core/utils";
|
||||
import { Vector } from "../../../core/vector";
|
||||
import { SOUNDS } from "../../../platform/sound";
|
||||
import { T } from "../../../translations";
|
||||
import { MetaBeltBuilding } from "../../buildings/belt";
|
||||
import { MetaMinerBuilding } from "../../buildings/miner";
|
||||
import { MetaTrashBuilding } from "../../buildings/trash";
|
||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../../components/item_processor";
|
||||
import { LeverComponent } from "../../components/lever";
|
||||
import { MinerComponent } from "../../components/miner";
|
||||
import { WireComponent } from "../../components/wire";
|
||||
import { ShapeItem } from "../../items/shape_item";
|
||||
import { GameRoot } from "../../root";
|
||||
import { THEME } from "../../theme";
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||
|
||||
// @todo: Make dictionary
|
||||
const tutorialsByLevel = [
|
||||
@ -257,7 +257,8 @@ export class HUDInteractiveTutorial extends BaseHUDPart {
|
||||
parameters.context.fillStyle = "rgba(74, 237, 134, " + (0.5 - animation * 0.2) + ")";
|
||||
parameters.context.strokeStyle = "rgb(74, 237, 134)";
|
||||
parameters.context.lineWidth = 2;
|
||||
parameters.context.beginRoundedRect(
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(
|
||||
closest.x * globalConfig.tileSize - 2 * animation,
|
||||
closest.y * globalConfig.tileSize - 2 * animation,
|
||||
globalConfig.tileSize + 4 * animation,
|
||||
@ -423,7 +424,8 @@ export class HUDInteractiveTutorial extends BaseHUDPart {
|
||||
parameters.context.fillStyle = "rgba(74, 237, 134, " + (0.5 - animation * 0.2) + ")";
|
||||
parameters.context.strokeStyle = "rgb(74, 237, 134)";
|
||||
parameters.context.lineWidth = 2;
|
||||
parameters.context.beginRoundedRect(
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(
|
||||
slot.x - 2 * animation,
|
||||
slot.y - 2 * animation,
|
||||
globalConfig.tileSize + 4 * animation,
|
||||
|
||||
@ -59,7 +59,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
|
||||
const entity = connectedEntities[i];
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
parameters.context.beginRoundedRect(
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(
|
||||
staticComp.origin.x * globalConfig.tileSize + 5,
|
||||
staticComp.origin.y * globalConfig.tileSize + 5,
|
||||
globalConfig.tileSize - 10,
|
||||
@ -81,7 +82,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
|
||||
|
||||
// Background
|
||||
parameters.context.fillStyle = THEME.map.connectedMiners.background;
|
||||
parameters.context.beginRoundedRect(
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(
|
||||
tooltipLocation.x + 5 * scale,
|
||||
tooltipLocation.y - 3 * scale,
|
||||
(isCapped ? 100 : 65) * scale,
|
||||
|
||||
@ -589,7 +589,8 @@ export class HUDWaypoints extends BaseHUDPart {
|
||||
// Render the background rectangle
|
||||
parameters.context.globalAlpha = this.currentMarkerOpacity * (isSelected ? 1 : 0.7);
|
||||
parameters.context.fillStyle = "rgba(255, 255, 255, 0.7)";
|
||||
parameters.context.beginRoundedRect(bounds.x, bounds.y, bounds.w, bounds.h, 6);
|
||||
parameters.context.beginPath();
|
||||
parameters.context.roundRect(bounds.x, bounds.y, bounds.w, bounds.h, 6);
|
||||
parameters.context.fill();
|
||||
|
||||
// Render the text
|
||||
|
||||
1
src/js/globals.d.ts
vendored
1
src/js/globals.d.ts
vendored
@ -40,7 +40,6 @@ declare interface ImportMeta {
|
||||
}
|
||||
|
||||
declare interface CanvasRenderingContext2D {
|
||||
beginRoundedRect(x: number, y: number, w: number, h: number, r: number): void;
|
||||
beginCircle(x: number, y: number, r: number): void;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user