idz: Use sets for unlocks flags

This commit is contained in:
Tau
2019-11-06 17:28:30 -05:00
parent e1e98ed6cf
commit 9a1e38dfb7
9 changed files with 14 additions and 12 deletions
+3 -3
View File
@@ -1,12 +1,12 @@
export function bitmap(buf: Buffer): number[] {
const result = new Array();
export function bitmap<T extends number>(buf: Buffer): Set<T> {
const result = new Set<T>();
for (let byteNo = 0; byteNo < buf.length; byteNo++) {
const byte = buf.readUInt8(byteNo);
for (let bitNo = 0; bitNo < 8; bitNo++) {
if (byte & (1 << bitNo)) {
result.push(8 * byteNo + bitNo);
result.add((8 * byteNo + bitNo) as T);
}
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ export function saveProfile(buf: Buffer): SaveProfileRequest {
dpoint: buf.readUInt32LE(0x0464),
mileage: buf.readUInt32LE(0x0008),
title: buf.readUInt16LE(0x0040) as TitleCode,
titles: bitmap(buf.slice(0x0042, 0x00f6)) as TitleCode[],
titles: bitmap(buf.slice(0x0042, 0x00f6)),
background: buf.readUInt8(0x0750) as BackgroundCode,
coursePlays,
missions: {
+1 -1
View File
@@ -14,7 +14,7 @@ export function saveStocker(buf: Buffer): SaveStockerRequest {
type: "save_stocker_req",
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
backgrounds: bitmap(buf.slice(0x0008, 0x002c)) as BackgroundCode[],
backgrounds: bitmap(buf.slice(0x0008, 0x002c)),
selectedCar: buf.readUInt16LE(0x009c) as CarSelector,
chara: chara(buf.slice(0x009e, 0x00b2)),
};
+1 -1
View File
@@ -1,4 +1,4 @@
export function bitmap(items: number[], nbytes: number): Buffer {
export function bitmap(items: Set<number>, nbytes: number): Buffer {
const buf = Buffer.alloc(nbytes);
for (const item of items) {
+2 -2
View File
@@ -44,9 +44,9 @@ export interface FacetRepository<T> {
}
export interface FlagRepository<T extends number> {
loadAll(profileId: Model.ExtId<Model.Profile>): Promise<T[]>;
loadAll(profileId: Model.ExtId<Model.Profile>): Promise<Set<T>>;
saveAll(profileId: Model.ExtId<Model.Profile>, items: T[]): Promise<void>;
saveAll(profileId: Model.ExtId<Model.Profile>, items: Set<T>): Promise<void>;
}
export interface ProfileRepository {
+1 -1
View File
@@ -16,7 +16,7 @@ export interface SaveProfileRequest {
dpoint: number;
mileage: number;
title: TitleCode;
titles: TitleCode[];
titles: Set<TitleCode>;
background: BackgroundCode;
coursePlays: Map<CourseNo, number>;
missions: MissionState;
+1 -1
View File
@@ -7,6 +7,6 @@ export interface SaveStockerRequest {
type: "save_stocker_req";
profileId: ExtId<Profile>;
selectedCar: CarSelector;
backgrounds: BackgroundCode[];
backgrounds: Set<BackgroundCode>;
chara: Chara;
}
+1 -1
View File
@@ -21,7 +21,7 @@ export interface LoadProfileResponse2 {
teamId?: number;
settings: Settings;
chara: Chara;
titles: TitleCode[];
titles: Set<TitleCode>;
coursePlays: Map<number, number>;
missions: MissionState;
timeAttack: TimeAttackScore[];
+3 -1
View File
@@ -1,5 +1,7 @@
import { BackgroundCode } from "../model/base";
export interface LoadStockerResponse {
type: "load_stocker_res";
status: number;
backgrounds: number[];
backgrounds: Set<BackgroundCode>;
}