idz: Rename model Id<> to ExtId<>

This commit is contained in:
Tau
2019-04-28 21:52:50 -04:00
parent 84541e245c
commit 6516dc812d
28 changed files with 75 additions and 72 deletions

View File

@@ -1,7 +1,7 @@
import iconv = require("iconv-lite");
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { CreateTeamRequest } from "../request/createTeam";
@@ -11,7 +11,7 @@ createTeam.msgLen = 0x0050;
export function createTeam(buf: Buffer): CreateTeamRequest {
return {
type: "create_team_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
teamName: iconv.decode(buf.slice(0x0008, 0x0028), "shift_jis"),
field_0028: buf.readUInt16LE(0x0028),
field_002C: buf.readUInt32LE(0x002c),

View File

@@ -1,5 +1,5 @@
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { LoadGarageRequest } from "../request/loadGarage";
@@ -9,7 +9,7 @@ loadGarage.msgLen = 0x0010;
export function loadGarage(buf: Buffer): LoadGarageRequest {
return {
type: "load_garage_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
fetchOffset: buf.readUInt8(0x0008),
field_000A: buf.readUInt16LE(0x000a),
};

View File

@@ -1,5 +1,5 @@
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { LoadStockerRequest } from "../request/loadStocker";
@@ -9,6 +9,6 @@ loadStocker.msgLen = 0x0010;
export function loadStocker(buf: Buffer): LoadStockerRequest {
return {
type: "load_stocker_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
};
}

View File

@@ -1,5 +1,5 @@
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { Team } from "../model/team";
import { LoadTopTenRequest } from "../request/loadTopTen";
@@ -27,7 +27,7 @@ export function loadTopTen(buf: Buffer): LoadTopTenRequest {
field_C4: buf.readUInt8(0x00c4), // Boolean, true if profile ID is set
field_C5: buf.readUInt8(0x00c5), // Always zero
field_C6: buf.readUInt16LE(0x00c6),
profileId: profileId !== 0 ? (profileId as Id<Profile>) : undefined,
teamId: teamId !== 0xffffffff ? (teamId as Id<Team>) : undefined,
profileId: profileId !== 0 ? (profileId as ExtId<Profile>) : undefined,
teamId: teamId !== 0xffffffff ? (teamId as ExtId<Team>) : undefined,
};
}

View File

@@ -1,6 +1,6 @@
import { car } from "./_car";
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { SaveNewCarRequest } from "../request/saveNewCar";
@@ -10,7 +10,7 @@ saveNewCar.msgLen = 0x0090;
export function saveNewCar(buf: Buffer): SaveNewCarRequest {
return {
type: "save_new_car_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
luid: buf.slice(0x0008, buf.indexOf(0, 0x0008)).toString("ascii"),
car: car(buf.slice(0x0020, 0x0080)),
field_0080: buf.readUInt32LE(0x0080),

View File

@@ -1,7 +1,7 @@
import { car } from "./_car";
import { mission } from "./_mission";
import { RequestCode } from "./_defs";
import { BackgroundCode, Id, TitleCode } from "../model/base";
import { BackgroundCode, ExtId, TitleCode } from "../model/base";
import { Profile } from "../model/profile";
import { SaveProfileRequest } from "../request/saveProfile";
import { bitmap } from "./_bitmap";
@@ -46,7 +46,7 @@ export function saveProfile(buf: Buffer): SaveProfileRequest {
return {
type: "save_profile_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
lv: buf.readUInt16LE(0x0026),
exp: buf.readUInt32LE(0x0028),
fame: buf.readUInt32LE(0x0468),

View File

@@ -1,5 +1,5 @@
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { SaveSettingsRequest } from "../request/saveSettings";
@@ -13,7 +13,7 @@ export function saveSettings(buf: Buffer): SaveSettingsRequest {
return {
type: "save_settings_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
dpoint: buf.readUInt32LE(0x0008),
settings: {
music: buf.readUInt16LE(0x0002),

View File

@@ -1,7 +1,7 @@
import { bitmap } from "./_bitmap";
import { chara } from "./_chara";
import { RequestCode } from "./_defs";
import { BackgroundCode, Id } from "../model/base";
import { BackgroundCode, ExtId } from "../model/base";
import { CarSelector } from "../model/car";
import { Profile } from "../model/profile";
import { SaveStockerRequest } from "../request/saveStocker";
@@ -12,7 +12,7 @@ saveStocker.msgLen = 0x00c0;
export function saveStocker(buf: Buffer): SaveStockerRequest {
return {
type: "save_stocker_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
backgrounds: bitmap(buf.slice(0x0008, 0x002c)) as BackgroundCode[],
selectedCar: buf.readUInt16LE(0x009c) as CarSelector,

View File

@@ -1,5 +1,5 @@
import { RequestCode } from "./_defs";
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { SaveTimeAttackRequest } from "../request/saveTimeAttack";
@@ -9,7 +9,7 @@ saveTimeAttack.msgLen = 0x0080;
export function saveTimeAttack(buf: Buffer): SaveTimeAttackRequest {
return {
type: "save_time_attack_req",
profileId: buf.readUInt32LE(0x0004) as Id<Profile>,
profileId: buf.readUInt32LE(0x0004) as ExtId<Profile>,
dayNight: buf.readUInt8(0x0054) & 1,
payload: {
courseId: buf.readUInt8(0x0054) >> 1,

View File

@@ -1,4 +1,4 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Team } from "../model/team";
import { JoinAutoTeamRequest } from "../request/joinAutoTeam";
import { LoadTeamRequest } from "../request/loadTeam";
@@ -12,7 +12,7 @@ export function _team(
): JoinAutoTeamResponse | LoadTeamResponse {
const bits = {
team: {
id: 2 as Id<Team>,
id: 2 as ExtId<Team>,
name: " ",
},
members: [],

View File

@@ -1,4 +1,4 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { MissionState } from "../model/mission";
import { Profile } from "../model/profile";
import { Settings } from "../model/settings";
@@ -17,7 +17,7 @@ export async function createProfile(
const profile: Profile = {
id: profileId,
teamId: 2 as Id<Team>, // TODO
teamId: 2 as ExtId<Team>, // TODO
name: req.name,
lv: 1,
exp: 0,

View File

@@ -1,4 +1,4 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Team } from "../model/team";
import { CreateTeamRequest } from "../request/createTeam";
import { CreateTeamResponse } from "../response/createTeam";
@@ -11,6 +11,6 @@ export function createTeam(
return {
type: "create_team_res",
status: 0,
teamId: 3 as Id<Team>,
teamId: 3 as ExtId<Team>,
};
}

View File

@@ -2,5 +2,5 @@
// exist at run time, we just pretend they do.
export type BackgroundCode = number & { __brand: "backgroundCode" };
export type Id<T> = number & { __id: T };
export type ExtId<T> = number & { __extId: T };
export type TitleCode = number & { __brand: "titleCode" };

View File

@@ -1,4 +1,4 @@
export { BackgroundCode, Id, TitleCode } from "./base";
export { BackgroundCode, ExtId, TitleCode } from "./base";
export { Car, CarSelector } from "./car";
export { Chara } from "./chara";
export { MissionState, MissionGrid } from "./mission";

View File

@@ -1,9 +1,9 @@
import { Id } from "./base";
import { ExtId } from "./base";
import { Team } from "./team";
export interface Profile {
id: Id<Profile>;
teamId?: Id<Team>;
id: ExtId<Profile>;
teamId?: ExtId<Team>;
name: string;
lv: number;
exp: number;

View File

@@ -1,6 +1,6 @@
import { Id } from "./base";
import { ExtId } from "./base";
export interface Team {
id: Id<Team>;
id: ExtId<Team>;
name: string;
}

View File

@@ -2,66 +2,69 @@ import * as Model from "./model";
import { AimeId } from "../model";
export interface CarRepository {
countCars(profileId: Model.Id<Model.Profile>): Promise<number>;
countCars(profileId: Model.ExtId<Model.Profile>): Promise<number>;
loadAllCars(profileId: Model.Id<Model.Profile>): Promise<Model.Car[]>;
loadAllCars(profileId: Model.ExtId<Model.Profile>): Promise<Model.Car[]>;
loadSelectedCar(profileId: Model.Id<Model.Profile>): Promise<Model.Car>;
loadSelectedCar(profileId: Model.ExtId<Model.Profile>): Promise<Model.Car>;
saveCar(profileId: Model.Id<Model.Profile>, car: Model.Car): Promise<void>;
saveCar(
profileId: Model.ExtId<Model.Profile>,
car: Model.Car
): Promise<void>;
saveSelection(
profileId: Model.Id<Model.Profile>,
profileId: Model.ExtId<Model.Profile>,
selector: Model.CarSelector
): Promise<void>;
}
export interface CoursePlaysRepository {
loadAll(profileId: Model.Id<Model.Profile>): Promise<Map<number, number>>;
loadAll(profileId: Model.ExtId<Model.Profile>): Promise<Map<number, number>>;
saveAll(
profileId: Model.Id<Model.Profile>,
profileId: Model.ExtId<Model.Profile>,
counts: Map<number, number>
): Promise<void>;
}
export interface FacetRepository<T> {
load(profileId: Model.Id<Model.Profile>): Promise<T>;
load(profileId: Model.ExtId<Model.Profile>): Promise<T>;
save(profileId: Model.Id<Model.Profile>, facet: T): Promise<void>;
save(profileId: Model.ExtId<Model.Profile>, facet: T): Promise<void>;
}
export interface FlagRepository<T extends number> {
loadAll(profileId: Model.Id<Model.Profile>): Promise<T[]>;
loadAll(profileId: Model.ExtId<Model.Profile>): Promise<T[]>;
saveAll(profileId: Model.Id<Model.Profile>, items: T[]): Promise<void>;
saveAll(profileId: Model.ExtId<Model.Profile>, items: T[]): Promise<void>;
}
export interface ProfileRepository {
// Might want to come up with something better here
generateId(): Promise<Model.Id<Model.Profile>>;
generateId(): Promise<Model.ExtId<Model.Profile>>;
discoverByAimeId(id: AimeId): Promise<boolean>;
loadByAimeId(id: AimeId): Promise<Model.Profile>;
load(id: Model.Id<Model.Profile>): Promise<Model.Profile>;
load(id: Model.ExtId<Model.Profile>): Promise<Model.Profile>;
save(id: Model.Id<Model.Profile>, profile: Model.Profile): Promise<void>;
save(id: Model.ExtId<Model.Profile>, profile: Model.Profile): Promise<void>;
}
export interface TimeAttackRepository {
loadAll(
profileId: Model.Id<Model.Profile>
profileId: Model.ExtId<Model.Profile>
): Promise<Model.TimeAttackScore[]>;
load(
profileId: Model.Id<Model.Profile>,
profileId: Model.ExtId<Model.Profile>,
courseId: number
): Promise<Model.TimeAttackScore | undefined>;
save(
profileId: Model.Id<Model.Profile>,
profileId: Model.ExtId<Model.Profile>,
score: Model.TimeAttackScore
): Promise<void>;
}

View File

@@ -1,9 +1,9 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
export interface CreateTeamRequest {
type: "create_team_req";
profileId: Id<Profile>; // u32
profileId: ExtId<Profile>; // u32
teamName: string; // len 0x20
field_0028: number; // u16
field_002C: number; // u32 (but only holds a u8)

View File

@@ -1,9 +1,9 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
export interface LoadGarageRequest {
type: "load_garage_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
fetchOffset: number;
field_000A: number;
}

View File

@@ -1,7 +1,7 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
export interface LoadStockerRequest {
type: "load_stocker_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
}

View File

@@ -1,4 +1,4 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { Team } from "../model/team";
@@ -14,6 +14,6 @@ export interface LoadTopTenRequest {
field_C4: number;
field_C5: number;
field_C6: number;
profileId?: Id<Profile>;
teamId?: Id<Team>;
profileId?: ExtId<Profile>;
teamId?: ExtId<Team>;
}

View File

@@ -1,10 +1,10 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Car } from "../model/car";
import { Profile } from "../model/profile";
export interface SaveNewCarRequest {
type: "save_new_car_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
luid: string;
car: Car;
field_0080: number;

View File

@@ -1,4 +1,4 @@
import { BackgroundCode, Id, TitleCode } from "../model/base";
import { BackgroundCode, ExtId, TitleCode } from "../model/base";
import { Car } from "../model/car";
import { MissionState } from "../model/mission";
import { Profile } from "../model/profile";
@@ -9,7 +9,7 @@ import { Unlocks } from "../model/unlocks";
export interface SaveProfileRequest {
type: "save_profile_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
lv: number;
exp: number;
fame: number;

View File

@@ -1,10 +1,10 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { Settings } from "../model/settings";
export interface SaveSettingsRequest {
type: "save_settings_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
dpoint: number; // ?? why
settings: Settings;
field_0010: number;

View File

@@ -1,11 +1,11 @@
import { BackgroundCode, Id } from "../model/base";
import { BackgroundCode, ExtId } from "../model/base";
import { CarSelector } from "../model/car";
import { Chara } from "../model/chara";
import { Profile } from "../model/profile";
export interface SaveStockerRequest {
type: "save_stocker_req";
profileId: Id<Profile>;
profileId: ExtId<Profile>;
selectedCar: CarSelector;
backgrounds: BackgroundCode[];
chara: Chara;

View File

@@ -1,10 +1,10 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Profile } from "../model/profile";
import { TimeAttackScore } from "../model/timeAttack";
export interface SaveTimeAttackRequest {
type: "save_time_attack_req";
profileId: Id<Profile>; // u32
profileId: ExtId<Profile>; // u32
dayNight: number;
payload: TimeAttackScore;
field_0002: number; // u16, always 1

View File

@@ -1,8 +1,8 @@
import { Id } from "../model/base";
import { ExtId } from "../model/base";
import { Team } from "../model/team";
export interface CreateTeamResponse {
type: "create_team_res";
status: number; // 0 is success, 1 is failure
teamId: Id<Team>;
teamId: ExtId<Team>;
}

View File

@@ -1,4 +1,4 @@
import { Id, TitleCode } from "../model/base";
import { ExtId, TitleCode } from "../model/base";
import { Car } from "../model/car";
import { Chara } from "../model/chara";
import { MissionState } from "../model/mission";
@@ -12,7 +12,7 @@ import { Unlocks } from "../model/unlocks";
export interface LoadProfileResponse2 {
type: "load_profile_v2_res";
name: string;
profileId: Id<Profile>;
profileId: ExtId<Profile>;
lv: number;
exp: number;
fame: number;