Skip to content

Commit d469718

Browse files
committed
stop breaking the fucking hud!!
1 parent 4764b47 commit d469718

5 files changed

Lines changed: 54 additions & 12 deletions

File tree

‎apps/game/src/game.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,13 +1688,13 @@ export class Game {
16881688
);
16891689
if (active) row.setAttribute("aria-current", "true");
16901690
const image = document.createElement("img");
1691-
const silhouette = assetUrl(`/icons/${weaponIcons[index]}.png`);
1691+
const silhouette = isKnife(index)
1692+
? assetUrl(`/icons/${weaponIcons[index]}.png`)
1693+
: weaponBuyIcon(index);
16921694
image.alt = "";
1693-
image.crossOrigin = "anonymous";
16941695
image.src = silhouette;
16951696
const art = document.createElement("span");
16961697
art.className = "inventory-art";
1697-
art.style.maskImage = `url("${silhouette}")`;
16981698
art.append(image);
16991699
const key = document.createElement("span");
17001700
key.className = "inventory-key";
@@ -1725,7 +1725,10 @@ export class Game {
17251725
if (utility === kind) item.setAttribute("aria-current", "true");
17261726
const art = document.createElement("span");
17271727
art.className = "inventory-art inventory-grenade-art";
1728-
art.style.maskImage = `url("${assetUrl(`/icons/buy/${grenadeIcons[kind]}.svg`)}")`;
1728+
const image = document.createElement("img");
1729+
image.alt = "";
1730+
image.src = assetUrl(`/icons/buy/${grenadeIcons[kind]}.svg`);
1731+
art.append(image);
17291732
item.append(art);
17301733
if (inventory[kind] > 1) {
17311734
const count = document.createElement("small");

‎apps/game/src/main.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
2525
<canvas id="game"></canvas>
2626
${homeMenuMarkup()}
2727
<div id="hud" class="hidden">
28+
<svg class="hud-icon-filter" width="0" height="0" aria-hidden="true"><defs><filter id="hud-icon-tint" color-interpolation-filters="sRGB"><feFlood flood-color="var(--hud-accent)"/><feComposite in2="SourceAlpha" operator="in"/></filter></defs></svg>
2829
<div id="buy-phase-tint" aria-hidden="true"></div>
2930
<div id="scope" class="hidden" aria-label="AWP scope"><div class="scope-lens"><i class="scope-horizontal"></i><i class="scope-vertical"></i></div></div>
3031
<div class="radar-wrap"><div id="location">DUST II</div><canvas id="radar" width="900" height="948" aria-label="Player-centered heading-up radar; hold M for the full north-up map"></canvas><div id="economy-hud"><strong id="money"></strong></div></div>

‎apps/game/src/style.css‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,15 +1074,17 @@ kbd {
10741074
.inventory-art {
10751075
width: 150px;
10761076
height: 32px;
1077-
background: currentColor;
1078-
mask-size: contain;
1079-
mask-repeat: no-repeat;
1080-
mask-position: right center;
1077+
}
1078+
.hud-icon-filter {
1079+
position: absolute;
1080+
pointer-events: none;
10811081
}
10821082
.inventory-art img {
10831083
width: 100%;
10841084
height: 100%;
1085-
opacity: 0;
1085+
object-fit: contain;
1086+
object-position: right center;
1087+
filter: url(#hud-icon-tint);
10861088
}
10871089
.inventory-weapon.active {
10881090
opacity: 1;
@@ -1121,7 +1123,9 @@ kbd {
11211123
display: block;
11221124
width: 26px;
11231125
height: 32px;
1124-
mask-position: center;
1126+
}
1127+
.inventory-grenade-art img {
1128+
object-position: center;
11251129
}
11261130
.inventory-grenade small {
11271131
position: absolute;

‎apps/game/tests/grenade-inventory.spec.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,35 @@ test("owned grenades show icons and counts and cycle in both wheel directions",
3636
expect(purchased).toEqual([true, true, true, true]);
3737
const icons = page.locator("#inventory [data-grenade-kind]");
3838
await expect(icons).toHaveCount(3);
39+
for (const kind of ["he", "flash", "smoke"]) {
40+
const image = page.locator(`#inventory [data-grenade-kind="${kind}"] img`);
41+
await expect(image).toBeVisible();
42+
await expect
43+
.poll(() => image.evaluate((img) => (img as HTMLImageElement).naturalWidth))
44+
.toBeGreaterThan(0);
45+
}
3946
await expect(page.locator('#inventory [data-grenade-kind="flash"]')).toHaveAttribute(
4047
"data-count",
4148
"2",
4249
);
50+
// Images work without CORS headers, unlike the old CSS masks.
51+
await page.route("https://hud-icons.test/**", async (route) => {
52+
const path = new URL(route.request().url()).pathname;
53+
const response = await page.request.get(path);
54+
await route.fulfill({
55+
body: await response.body(),
56+
contentType: response.headers()["content-type"],
57+
});
58+
});
59+
await page.evaluate(async () => {
60+
await Promise.all(
61+
[...document.querySelectorAll<HTMLImageElement>("#inventory img")].map(async (image) => {
62+
image.src = "https://hud-icons.test" + new URL(image.src).pathname;
63+
await image.decode();
64+
}),
65+
);
66+
});
67+
await page.screenshot({ path: "artifacts/hud-icons-cross-origin.png" });
4368
const selected = () => page.evaluate(() => window.__game.utility.selected);
4469
const wheel = async (delta: number) => {
4570
await page.waitForTimeout(120);

‎apps/game/tests/inventory-icons.spec.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@ test("HUD keeps default silhouettes and skin names for painted weapons", async (
3333
for (const { weapon } of choices) {
3434
const art = page.locator(`#inventory [data-weapon-index="${weapon}"] .inventory-art`);
3535
await expect(art).not.toHaveClass(/inventory-finish/);
36-
await expect(art).toHaveCSS("mask-image", /\/icons\//);
36+
await expect(art.locator("img")).toBeVisible();
3737
}
3838
for (const { weapon, name } of choices) {
3939
const row = page.locator(`#inventory [data-weapon-index="${weapon}"]`);
40-
await expect(row.locator("img")).toHaveAttribute("src", /\/icons\/[^/]+\.png$/);
40+
await expect(row.locator("img")).toHaveAttribute(
41+
"src",
42+
/\/icons\/(?:buy\/)?[^/]+\.(?:png|svg)$/,
43+
);
4144
await expect
4245
.poll(() => row.locator("img").evaluate((image) => (image as HTMLImageElement).naturalWidth))
4346
.toBeGreaterThan(0);
4447
await expect(row.locator(".inventory-name")).toContainText(`| ${name}`);
4548
}
4649
await expect(page.locator("#inventory img[src*='/skins/']")).toHaveCount(0);
4750
await expect(page.locator("#inventory [data-grenade-kind]")).toHaveCount(2);
51+
for (const icon of await page.locator("#inventory [data-grenade-kind] img").all()) {
52+
await expect(icon).toBeVisible();
53+
await expect
54+
.poll(() => icon.evaluate((image) => (image as HTMLImageElement).naturalWidth))
55+
.toBeGreaterThan(0);
56+
}
4857
await page.screenshot({ path: "artifacts/inventory-icons-fallback.png" });
4958
expect(errors).toEqual([]);
5059
});

0 commit comments

Comments
 (0)