idz: Use sets for unlocks flags
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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,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
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,6 +7,6 @@ export interface SaveStockerRequest {
|
||||
type: "save_stocker_req";
|
||||
profileId: ExtId<Profile>;
|
||||
selectedCar: CarSelector;
|
||||
backgrounds: BackgroundCode[];
|
||||
backgrounds: Set<BackgroundCode>;
|
||||
chara: Chara;
|
||||
}
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { BackgroundCode } from "../model/base";
|
||||
|
||||
export interface LoadStockerResponse {
|
||||
type: "load_stocker_res";
|
||||
status: number;
|
||||
backgrounds: number[];
|
||||
backgrounds: Set<BackgroundCode>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user