Skip to content

Commit db2de51

Browse files
committed
Polish reload switching, buy previews and round highlights
1 parent 432f223 commit db2de51

20 files changed

Lines changed: 525 additions & 24 deletions

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,5 @@ The 25 newly added default models shrink from 72.78 MB to 39.61 MB with meshopt
272272
Startup audio is packed losslessly into `packages/assets/public/audio/startup.bin`: 300 Opus clips share one 3,224,569-byte request, then decode through four bounded jobs. All mandatory effects are ready before Play; music remains streamed on demand. Regenerate after sound imports with `python3 scripts/pack-audio.py`; `packages/assets/public/audio/startup-source.json` records original byte hashes. Source OGG files remain intact.
273273

274274
Weapon appearance now belongs to the [created weapon instance](docs/weapon-appearance.md). Purchases capture the creator's finish, wear and seed; bot-created guns remain default. Drops render their captured finish on the ground, bots carry it after pickup, and subsequent holders retain it. Changing a loadout does not repaint existing guns. The HUD shows finish names and catalog thumbnails for painted weapons. The compact killfeed uses utility/fire icons rather than spelled-out grenade names.
275+
276+
Round-end subtitles use imported CS2 [fun-fact and MVP strings](docs/round-highlights.md), driven by this round's measured events. Magazine reloads can be switched away after the native insertion marker without losing loaded ammo; the remaining reload deadline and weapon deploy time still gate firing. Buy-preview detail labels include the selected finish and its rarity color.

‎apps/game/src/buy-poses.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@ export function poseBuyProp(model: T.Object3D, samples: Pose["weaponBones"]) {
117117
matrix.decompose(bone.position, bone.quaternion, bone.scale);
118118
bone.updateWorldMatrix(false, false);
119119
});
120-
return basis;
120+
// Some grenade clips rotate their weapon root (flash/smoke/decoy),
121+
// while HE/Molotov keep it at identity. Cancel the posed root at the wpn
122+
// attachment, not the unposed bind root, or those canisters rotate twice.
123+
return metricAttachment(model.getObjectByName("weapon")!);
121124
}

‎apps/game/src/buy-preview.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createInspectsWorldKnife } from "./inspects-knife";
99
import { bayonetWorldGrip } from "./knife-motion";
1010
import { createGrenadeModel } from "./grenade-models";
1111
import { type GrenadeKind } from "./utility";
12-
import { unregisterSkinModel } from "./skins";
12+
import { unregisterSkinModel, skinChoices, skinName, skinRarityColor } from "./skins";
1313

1414
/** Uses the game's context and loaded templates; no extra model requests or render loop. */
1515
export class BuyPreview {
@@ -139,7 +139,8 @@ export class BuyPreview {
139139
const kind = card?.dataset.grenade as GrenadeKind | undefined;
140140
const equipment = card?.dataset.equipment;
141141
const index = card?.dataset.weapon === undefined ? selected : Number(card.dataset.weapon);
142-
const identity = kind ?? equipment ?? String(index);
142+
const identity =
143+
kind ?? equipment ?? `${index}:${skinChoices[index].id}:${skinName(skinChoices[index].id)}`;
143144
if (identity !== this.current) {
144145
this.current = identity;
145146
this.item = undefined;
@@ -152,7 +153,7 @@ export class BuyPreview {
152153
this.attachment = applyBuyPose(soldier, token);
153154
document.getElementById(this.stageId)!.dataset.pose = this.attachment.clip;
154155
if (!equipment) {
155-
const itemKey = `${team}:${soldier.animationTeam}:${identity}`;
156+
const itemKey = `${team}:${soldier.animationTeam}:${kind ?? String(index)}`;
156157
let model = this.items.get(itemKey);
157158
if (!model) {
158159
if (kind) {
@@ -186,12 +187,17 @@ export class BuyPreview {
186187
if (this.stageId === "buy-preview-stage") {
187188
document.getElementById("buy-preview-team")!.textContent =
188189
team === "ct" ? "COUNTER-TERRORISTS" : "TERRORISTS";
189-
document.getElementById("buy-preview-name")!.textContent =
190-
card?.querySelector("b")?.textContent ?? weapons[index].name;
190+
const name = document.getElementById("buy-preview-name")!;
191+
const finish = !kind && !equipment ? skinName(skinChoices[index].id) : "";
192+
name.textContent =
193+
(card?.querySelector("b")?.textContent ?? weapons[index].name) +
194+
(finish ? ` | ${finish}` : "");
195+
const rarity = finish ? skinRarityColor(skinChoices[index].id) : "";
196+
name.style.color = /^#[0-9a-f]{6}$/i.test(rarity) ? rarity : "";
191197
document.getElementById("buy-preview-detail")!.textContent =
192198
card?.querySelector("small")?.textContent ?? "Hover an item to inspect it.";
193199
}
194-
document.getElementById(this.stageId)!.dataset.item = identity;
200+
document.getElementById(this.stageId)!.dataset.item = kind ?? equipment ?? String(index);
195201
}
196202
const rect = (this.rect ??= document.getElementById(this.stageId)!.getBoundingClientRect());
197203
if (rect.width < 1 || rect.height < 1) return;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"source": {
3+
"file": "resource/csgo_english.txt",
4+
"build": "26144732",
5+
"sha256": "0d87903259b8fcc17a16b899424df8c25c5db348f9d54d5a0d343e7f34bc6ac5"
6+
},
7+
"strings": {
8+
"winpanel_mvp_award_kills": "MVP: %s1 for most eliminations",
9+
"winpanel_mvp_award_ace": "MVP: %s1 for an ACE round",
10+
"winpanel_mvp_award_bombplant": "MVP: %s1 for planting the bomb",
11+
"winpanel_mvp_award_bombdefuse": "MVP: %s1 for defusing the bomb",
12+
"funfact_short_round:f": {
13+
"one": "That round took only {d1} second!",
14+
"other": "That round took only {d1} seconds!"
15+
},
16+
"funfact_ace:f": "Ace! {player} killed the entire enemy team.",
17+
"funfact_killed_enemies:f": {
18+
"one": "{player} killed {d1} opponent.",
19+
"other": "{player} killed {d1} opponents."
20+
},
21+
"funfact_kills_headshots:f": {
22+
"one": "{player} killed {d1} enemy with headshots that round.",
23+
"other": "{player} killed {d1} enemies with headshots that round."
24+
},
25+
"funfact_knife_kills:f": {
26+
"one": "{player} killed an enemy with the knife.",
27+
"other": "{player} had {d1} knife kills this round."
28+
},
29+
"funfact_kills_grenades:f": {
30+
"one": "{player} killed {d1} enemy with grenades.",
31+
"other": "{player} killed {d1} enemies with grenades."
32+
},
33+
"funfact_first_kill:f": {
34+
"one": "{d1} second into the round, {player} got the first kill.",
35+
"other": "{d1} seconds into the round, {player} got the first kill."
36+
},
37+
"funfact_ct_win_no_kills:f": "Counter-Terrorists won without killing any Terrorists.",
38+
"funfact_t_win_no_kills:f": "Terrorists won without killing any Counter-Terrorists.",
39+
"funfact_t_win_no_casualties:f": "Terrorists won without taking any casualties.",
40+
"funfact_ct_win_no_casualties:f": "Counter-Terrorists won without taking any casualties.",
41+
"funfact_ct_win_time:f": {
42+
"one": "The CT team eliminated the T team in {d1} second.",
43+
"other": "The CT team eliminated the T team in {d1} seconds."
44+
},
45+
"funfact_ter_win_time:f": {
46+
"one": "The Terrorist team eliminated the CT team in {d1} second.",
47+
"other": "The Terrorist team eliminated the CT team in {d1} seconds."
48+
}
49+
}
50+
}

‎apps/game/src/game.ts‎

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import {
8484
nativeInspectDuration,
8585
nativeSoundCues,
8686
nativeReloadPhases,
87+
nativeMagazineInsert,
8788
} from "./weapon-motion";
8889
import { knifeInspectDuration } from "./knife-motion";
8990
import { dustRadarProjection, loadCalloutRadar, radarCrop } from "./radar";
@@ -116,6 +117,7 @@ import { gradeMapColors } from "./map-color";
116117
import { setupUiAudio } from "./ui-audio";
117118
import { MatchNotices } from "./match-notices";
118119
import { roundMvp } from "./round-mvp";
120+
import { roundFact, type RoundActor } from "./round-facts";
119121
import { renderScoreboard } from "./scoreboard";
120122
import { hideRoundBanner, showRoundBanner } from "./round-banner";
121123
import type { LoadProgress } from "./intro";
@@ -303,6 +305,9 @@ export class Game {
303305
roundHistory: { winner: AgentTeam; reason: string }[] = [];
304306
scoreboardSignature = "";
305307
roundStartKills = new Map<number | "player", number>();
308+
roundElapsed = 0;
309+
roundHighlights = new Map<RoundActor, { headshots: number; knives: number; grenades: number }>();
310+
roundFirstKill?: { name: string; seconds: number };
306311
mvpCounts = new Map<number | "player", number>();
307312
notices = new MatchNotices();
308313
roundPause = 0;
@@ -394,6 +399,7 @@ export class Game {
394399
boltTime = 0;
395400
rescope = 0;
396401
weaponCooldowns = weapons.map(() => 0);
402+
reloadLockouts = weapons.map(() => 0);
397403
selected = 2;
398404
primary: number | null = null;
399405
secondary = 2;
@@ -469,6 +475,7 @@ export class Game {
469475
burstRemaining = 0;
470476
shellPhase: "intro" | "loop" | "outro" = "intro";
471477
shellInserted = false;
478+
magazineInserted = false;
472479
knife = 4;
473480
inspectVariant = 2;
474481
knifeTime = 0;
@@ -1267,6 +1274,7 @@ export class Game {
12671274
this.setScope(0);
12681275
this.rescope = this.boltTime = 0;
12691276
this.weaponCooldowns = weapons.map(() => 0);
1277+
this.reloadLockouts.fill(0);
12701278
this.position.set(-17, 0, 17);
12711279
if (this.teamMode && this.dust) {
12721280
this.position.fromArray(this.dust.navigation.data.spawns[this.team][0]);
@@ -1552,9 +1560,14 @@ export class Game {
15521560
this.ammo = this.magazines[index].ammo;
15531561
this.reserve = this.magazines[index].reserve;
15541562
this.reload = 0;
1563+
this.magazineInserted = false;
15551564
this.shots = 0;
15561565
this.drawTime = weaponDrawDuration(this.selected);
1557-
this.cooldown = Math.max(weapons[index].deploy, this.weaponCooldowns[index]);
1566+
this.cooldown = Math.max(
1567+
weapons[index].deploy,
1568+
this.weaponCooldowns[index],
1569+
this.reloadLockouts[index],
1570+
);
15581571
if (weapons[index].unzoomsAfterShot && this.weaponCooldowns[index] > 0)
15591572
this.boltTime = this.weaponCooldowns[index];
15601573
// View models are cached per team and weapon; animateGun fully re-poses them.
@@ -1795,6 +1808,7 @@ export class Game {
17951808
this.burstRemaining = 0;
17961809
this.shellPhase = "intro";
17971810
this.shellInserted = false;
1811+
this.magazineInserted = false;
17981812
this.revolverCharge = 0;
17991813
this.reload = w.reloadStyle === "shell" ? this.shellDuration() : w.reload;
18001814
this.boltTime = 0;
@@ -2309,6 +2323,24 @@ export class Game {
23092323
wallbang = false,
23102324
label?: string,
23112325
) {
2326+
if (this.teamMode && !this.roundPause && !this.freezeTime) {
2327+
const id: RoundActor =
2328+
killer === "YOU" ? "player" : this.bots.findIndex((bot) => bot.name === killer);
2329+
const killerTeam = id === "player" ? this.team : this.bots[id]?.team;
2330+
const victimTeam =
2331+
victim === "YOU" ? this.team : this.bots.find((bot) => bot.name === victim)?.team;
2332+
if (killerTeam && victimTeam && killerTeam !== victimTeam) {
2333+
const stats = this.roundHighlights.get(id) ?? { headshots: 0, knives: 0, grenades: 0 };
2334+
if (head) stats.headshots++;
2335+
if (weapon >= 0 && isKnife(weapon)) stats.knives++;
2336+
if (label) stats.grenades++;
2337+
this.roundHighlights.set(id, stats);
2338+
this.roundFirstKill ??= {
2339+
name: killer === "YOU" ? playerName() : killer,
2340+
seconds: this.roundElapsed,
2341+
};
2342+
}
2343+
}
23122344
const utilityKind = grenadeTypes.find((kind) => grenadeData[kind].name === label);
23132345
const killerInstance =
23142346
killer === "YOU"
@@ -2573,8 +2605,10 @@ export class Game {
25732605
const after = 1 - this.drawTime / weaponDrawDuration(this.selected);
25742606
if (!this.reload) this.animationSounds("draw", before, after);
25752607
}
2576-
for (let i = 0; i < this.weaponCooldowns.length; i++)
2608+
for (let i = 0; i < this.weaponCooldowns.length; i++) {
25772609
this.weaponCooldowns[i] = Math.max(0, this.weaponCooldowns[i] - dt);
2610+
this.reloadLockouts[i] = Math.max(0, this.reloadLockouts[i] - dt);
2611+
}
25782612
if (this.scopeTransition > 0) {
25792613
this.scopeTransition = Math.max(0, this.scopeTransition - dt);
25802614
this.camera.fov =
@@ -2748,15 +2782,26 @@ export class Game {
27482782
}
27492783
} else {
27502784
this.animationSounds("reload", 1 - previous / w.reload, 1 - this.reload / w.reload);
2751-
if (!this.reload) {
2785+
if (
2786+
!this.magazineInserted &&
2787+
this.reloadProgress() >= nativeMagazineInsert(this.selected, this.emptyReload)
2788+
) {
2789+
// The new magazine survives holstering. The remaining reload deadline
2790+
// still gates attacks after drawing, so quick-switching only cancels
2791+
// the visual tail, not the weapon's readiness time.
2792+
this.magazineInserted = true;
2793+
this.reloadLockouts[this.selected] = Math.max(
2794+
this.reloadLockouts[this.selected],
2795+
this.reload,
2796+
);
27522797
const loaded = reloadMagazine(this.selected, this.ammo, this.reserve);
27532798
this.ammo = loaded.ammo;
27542799
this.reserve = loaded.reserve;
27552800
this.updateUI();
27562801
}
27572802
}
27582803
}
2759-
if (!this.reload) this.emptyReload = false;
2804+
if (!this.reload) this.emptyReload = this.magazineInserted = false;
27602805
const crouch = this.updateDuckInput(dt),
27612806
walk = this.keys.has("ShiftLeft") || this.keys.has("ShiftRight"),
27622807
maxSpeed =
@@ -3164,6 +3209,9 @@ export class Game {
31643209
beepPulse: 0,
31653210
};
31663211
this.bombMesh.visible = false;
3212+
this.roundElapsed = 0;
3213+
this.roundHighlights.clear();
3214+
this.roundFirstKill = undefined;
31673215
this.roundStartKills = new Map<number | "player", number>([
31683216
["player", this.kills],
31693217
...this.bots.map((bot, id) => [id, bot.kills] as [number, number]),
@@ -3222,7 +3270,23 @@ export class Game {
32223270
this.bomb.defuser = null;
32233271
this.bomb.plantProgress = this.bomb.progress = 0;
32243272
}
3225-
showRoundBanner(winner, this.team, reason, mvp);
3273+
const winners = players.filter((player) => player.team === winner);
3274+
const fact = roundFact({
3275+
winner,
3276+
reason,
3277+
seconds: this.roundElapsed,
3278+
enemyCount: players.length - winners.length,
3279+
winningDeaths: winners.filter((player) =>
3280+
player.id === "player" ? this.dead > 0 : this.bots[player.id].health <= 0,
3281+
).length,
3282+
players: winners.map((player) => ({
3283+
name: player.name,
3284+
kills: Math.max(0, player.kills - (this.roundStartKills.get(player.id) ?? player.kills)),
3285+
...(this.roundHighlights.get(player.id) ?? { headshots: 0, knives: 0, grenades: 0 }),
3286+
})),
3287+
firstKill: this.roundFirstKill,
3288+
});
3289+
showRoundBanner(winner, this.team, reason, mvp, fact);
32263290
this.updateUI();
32273291
if (this.teamScores[winner] >= this.winTarget || (this.competitive && this.round >= 24))
32283292
this.finish();
@@ -3327,6 +3391,7 @@ export class Game {
33273391
this.updateBotPurchases(dt * 8, this.tick++ % 8);
33283392
return;
33293393
}
3394+
this.roundElapsed += dt;
33303395
this.time = Math.max(0, this.time - dt);
33313396
const bomb = this.bomb!;
33323397
const stationary = !["KeyW", "KeyA", "KeyS", "KeyD", "Space"].some((key) => this.keys.has(key));
@@ -3541,6 +3606,7 @@ export class Game {
35413606
this.kick = this.damage = this.hit = 0;
35423607
this.weaponAudio.stop();
35433608
this.weaponCooldowns.fill(0);
3609+
this.reloadLockouts.fill(0);
35443610
this.weaponCooldowns[weapon] = Math.max(0, bot.shot);
35453611
this.primary = weaponSlot(weapon) === 1 ? weapon : null;
35463612
this.secondary = weaponSlot(weapon) === 2 ? weapon : this.team === "t" ? 7 : 2;

‎apps/game/src/round-banner.css‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
align-items: center;
2929
justify-content: space-between;
3030
width: calc(400 * var(--round-unit));
31-
height: calc(80 * var(--round-unit));
31+
height: auto;
32+
min-height: calc(104 * var(--round-unit));
3233
margin: 0 auto calc(16 * var(--round-unit));
33-
padding: 0 calc(12 * var(--round-unit));
34+
padding: calc(10 * var(--round-unit)) calc(36 * var(--round-unit));
3435
border-inline: calc(4 * var(--round-unit)) solid var(--result-color);
3536
border-radius: 3px;
3637
background: var(--result-bg);
@@ -63,9 +64,11 @@
6364
#round-banner-reason {
6465
display: block;
6566
margin-top: calc(4 * var(--round-unit));
66-
font-size: calc(11 * var(--round-unit));
67+
font-size: calc(14 * var(--round-unit));
6768
color: #ddd;
68-
white-space: nowrap;
69+
white-space: normal;
70+
overflow-wrap: anywhere;
71+
line-height: 1.2;
6972
}
7073
.round-chevron {
7174
position: absolute;
@@ -117,6 +120,9 @@
117120
}
118121
#round-mvp-name {
119122
display: block;
123+
white-space: nowrap;
124+
overflow: hidden;
125+
text-overflow: ellipsis;
120126
font:
121127
900 calc(28 * var(--round-unit))/1.3 "Stratum2 Condensed",
122128
sans-serif;

‎apps/game/src/round-banner.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ export function showRoundBanner(
2020
playerTeam: "ct" | "t",
2121
reason: string,
2222
mvp?: { name: string; reason: string },
23+
fact?: string,
2324
) {
2425
const node = banner();
2526
node.dataset.winner = winner;
2627
node.dataset.result = winner === playerTeam ? "won" : "lost";
2728
document.getElementById("round-banner-title")!.textContent =
2829
winner === playerTeam ? "ROUND WON" : "ROUND LOST";
2930
document.getElementById("round-banner-reason")!.textContent =
30-
`${winner === "ct" ? "Counter-Terrorists" : "Terrorists"} win · ${reason}`;
31+
fact || `${winner === "ct" ? "Counter-Terrorists" : "Terrorists"} win · ${reason}`;
32+
node.title = `${winner === "ct" ? "Counter-Terrorists" : "Terrorists"} win · ${reason}`;
3133
document.getElementById("round-mvp")!.hidden = !mvp;
3234
if (mvp) {
3335
(document.getElementById("round-mvp-avatar") as HTMLImageElement).src = assetUrl(

0 commit comments

Comments
 (0)