Skip to content

Commit

Permalink
add healthbar support
Browse files Browse the repository at this point in the history
  • Loading branch information
abextm committed Jul 7, 2024
1 parent b5f3927 commit 2bd9d9d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cache2-ts/src/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export class Reader {
return this.i32() & (-1 >>> 1);
}
}
public u32o16n(): number { // rl BigSmart2
if (this.view.getUint8(this.offset) & 0x80) {
return this.i32() & (-1 >>> 1);
} else {
return this.u16n();
}
}
public leVarInt(): number { // rl LEVarInt
let v = 0;
let shift = 0;
Expand Down
70 changes: 70 additions & 0 deletions cache2-ts/src/loaders/HealthBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { PerFileLoadable } from "../Loadable.js";
import { Reader } from "../Reader.js";
import { Typed } from "../reflect.js";
import { HealthBarID, SpriteID } from "../types.js";

export class HealthBar extends PerFileLoadable {
constructor(public id: HealthBarID) {
super();
}

declare public [Typed.type]: Typed.Any;

public static readonly index = 2;
public static readonly archive = 33;

public unused1: number | undefined = undefined;
public sortOrder: number = 255;
public despawnPriority: number = 255;
public fadeOutAt = -1;
public duration = 70;
public unused2: number | undefined = undefined;
public filledSprite = -1 as SpriteID;
public emptySprite = -1 as SpriteID;
public denominator = 30;
public borderSize = 0;

public static decode(r: Reader, id: HealthBarID): HealthBar {
const v = new HealthBar(id);
for (let opcode: number; (opcode = r.u8()) != 0;) {
switch (opcode) {
case 1:
v.unused1 = r.u16();
break;
case 2:
v.sortOrder = r.u8();
break;
case 3:
v.despawnPriority = r.u8();
break;
case 4:
v.fadeOutAt = 0;
break;
case 5:
v.duration = r.u16();
break;
case 6:
v.unused2 = r.u8();
break;
case 7:
v.filledSprite = r.u32o16n() as SpriteID;
break;
case 8:
v.emptySprite = r.u32o16n() as SpriteID;
break;
case 11:
v.fadeOutAt = r.u16();
break;
case 14:
v.denominator = r.u8();
break;
case 15:
v.borderSize = r.u8();
break;
default:
throw new Error(`unknown opcode ${opcode}`);
}
}
return v;
}
}
1 change: 1 addition & 0 deletions cache2-ts/src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./DBRow.js";
export * from "./Enum.js";
export * from "./HealthBar.js";
export * from "./Hitsplat.js";
export * from "./Item.js";
export * from "./NPC.js";
Expand Down
1 change: 1 addition & 0 deletions cache2-ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type DBTableID = NewType<number, "DBTableID">;
export type DBColumnID = NewType<number, "DBColumnID">;
export type EnumID = NewType<number, "EnumID">;
export type FontID = NewType<number, "FontID">;
export type HealthBarID = NewType<number, "HealthBaID">;
export type HitsplatID = NewType<number, "HitsplatID">;
export type ItemID = NewType<number, "ItemID">;
export type MapElementID = NewType<number, "MapElementID">;
Expand Down
3 changes: 3 additions & 0 deletions viewer/src/common/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const lookupTypes = {
DBTableID: "dbtable",
EnumID: "enum",
ItemID: "item",
HealthBarID: "healthbar",
HitsplatID: "hitsplat",
NPCID: "npc",
ObjID: "obj",
Expand All @@ -25,6 +26,7 @@ export type LookupType =
| "enum"
| "index"
| "item"
| "healthbar"
| "hitsplat"
| "npc"
| "obj"
Expand All @@ -37,6 +39,7 @@ const uiNameOverride = {
dbrow: "DBRow",
dbtable: "DBTable",
npc: "NPC",
healthbar: "HealthBar",
} satisfies Partial<Record<LookupType, string>>;
export function uiType(t: LookupType): string {
return uiNameOverride[t as keyof typeof uiNameOverride] ?? capitalize(t);
Expand Down
1 change: 1 addition & 0 deletions viewer/src/main/viewer/Viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ViewType name="obj" bind:key={$key} index={6}/>
<ViewType name="enum" bind:key={$key} index={8}/>
<ViewType name="item" bind:key={$key} index={10}/>
<ViewType name="healthbar" bind:key={$key} index={33}/>
<ViewType name="hitsplat" bind:key={$key} index={32}/>
<ViewType name="npc" bind:key={$key} index={9}/>
<ViewType name="param" bind:key={$key} index={11}/>
Expand Down
1 change: 1 addition & 0 deletions viewer/src/runner/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ let types: Record<LookupType, Filterable<unknown>> = {
dbtable: c2.DBTable,
enum: c2.Enum,
item: c2.Item,
healthbar: c2.HealthBar,
hitsplat: c2.Hitsplat,
npc: c2.NPC,
obj: c2.Obj,
Expand Down

0 comments on commit 2bd9d9d

Please sign in to comment.