add idz repository layer

This commit is contained in:
Tau
2019-11-06 17:28:29 -05:00
parent 6beb3b2343
commit 8817029258
39 changed files with 375 additions and 99 deletions
+6 -1
View File
@@ -1,3 +1,5 @@
import { Id } from "../model/base";
import { Team } from "../model/team";
import { CreateTeamRequest } from "../request/createTeam";
import { LoadTeamRequest } from "../request/loadTeam";
import { CreateTeamResponse } from "../response/createTeam";
@@ -9,7 +11,10 @@ export function _team(
req: CreateTeamRequest | LoadTeamRequest
): CreateTeamResponse | LoadTeamResponse {
const bits = {
name: "ASS GENTLEMEN",
team: {
id: 2 as Id<Team>,
name: "ASS GENTLEMEN",
},
members: [],
};
+33 -2
View File
@@ -1,11 +1,42 @@
import { Id } from "../model/base";
import { Profile } from "../model/profile";
import { Team } from "../model/team";
import { CreateProfileRequest } from "../request/createProfile";
import { GenericResponse } from "../response/generic";
import { World } from "../world";
export function createProfile(
export async function createProfile(
w: World,
req: CreateProfileRequest
): GenericResponse {
): Promise<GenericResponse> {
const profile: Profile = {
id: 1 as Id<Profile>,
teamId: 2 as Id<Team>,
name: req.name,
lv: 1,
fame: 0,
dpoint: 0,
};
const settings = {
bgMusic: 15,
forceQuitEn: false,
steeringForce: 4,
bgVolume: 10,
seVolume: 10,
cornerGuide: true,
lineGuide: false,
ghostEn: false,
taResultSkip: false,
};
await Promise.all([
w.profile().save(profile.id, profile),
w.chara().save(profile.id, req.chara),
w.car().save(profile.id, req.car),
w.settings().save(profile.id, settings),
]);
return {
type: "generic_res",
status: 1,
+3 -3
View File
@@ -2,12 +2,12 @@ import { DiscoverProfileRequest } from "../request/discoverProfile";
import { DiscoverProfileResponse } from "../response/discoverProfile";
import { World } from "../world";
export function discoverProfile(
export async function discoverProfile(
w: World,
req: DiscoverProfileRequest
): DiscoverProfileResponse {
): Promise<DiscoverProfileResponse> {
return {
type: "discover_profile_res",
exists: true,
exists: await w.profile().discoverByAimeId(req.aimeId),
};
}
+1 -1
View File
@@ -26,7 +26,7 @@ import { Request } from "../request";
import { Response } from "../response";
import { World } from "../world";
export function dispatch(w: World, req: Request): Response {
export async function dispatch(w: World, req: Request): Promise<Response> {
switch (req.type) {
case "create_profile_req":
return createProfile(w, req);
+18 -49
View File
@@ -2,58 +2,27 @@ import { LoadProfileRequest } from "../request/loadProfile";
import { LoadProfileResponse2 } from "../response/loadProfile2";
import { World } from "../world";
export function loadProfile(
export async function loadProfile(
w: World,
req: LoadProfileRequest
): LoadProfileResponse2 {
): Promise<LoadProfileResponse2> {
const profile = await w.profile().loadByAimeId(req.aimeId);
const settings = await w.settings().load(profile.id);
const chara = await w.chara().load(profile.id);
const titles = await w.titles().load(profile.id);
const car = await w.car().load(profile.id);
return {
type: "load_profile_v2_res",
name: "てすと",
profileId: 0x11223344,
lv: 99,
fame: 1234,
dpoint: 54321,
teamId: 0x22334455,
settings: {
bgMusic: 15,
forceQuitEn: false,
steeringForce: 4,
bgVolume: 10,
seVolume: 10,
cornerGuide: true,
lineGuide: false,
ghostEn: false,
taResultSkip: false,
},
chara: {
gender: "male",
clothing: 0,
mouth: 0,
field_06: 0,
field_08: 0,
field_0A: 0,
field_0C: 0,
field_0E: 0,
},
background: 0,
title: 0,
titles: [],
car: {
field_00: 0,
field_02: 0,
field_04: [],
model: 0,
color: 0,
transmission: 0,
field_4A: 0,
field_4C: 21527,
field_50_lo: 3674393,
field_50_hi: 6407,
field_58: 0,
field_5A: 0,
field_5B: 0,
field_5C: 1,
field_5E: 0,
},
name: profile.name,
profileId: profile.id,
lv: profile.lv,
fame: profile.fame,
dpoint: profile.dpoint,
teamId: profile.teamId,
settings,
chara,
titles,
car,
};
}
+5 -3
View File
@@ -2,13 +2,15 @@ import { LoadStockerRequest } from "../request/loadStocker";
import { LoadStockerResponse } from "../response/loadStocker";
import { World } from "../world";
export function loadStocker(
export async function loadStocker(
w: World,
req: LoadStockerRequest
): LoadStockerResponse {
): Promise<LoadStockerResponse> {
const backgrounds = await w.backgrounds().load(req.profileId);
return {
type: "load_stocker_res",
status: 1,
backgrounds: [],
backgrounds,
};
}
+4 -2
View File
@@ -2,10 +2,12 @@ import { SaveSettingsRequest } from "../request/saveSettings";
import { GenericResponse } from "../response/generic";
import { World } from "../world";
export function saveSettings(
export async function saveSettings(
w: World,
req: SaveSettingsRequest
): GenericResponse {
): Promise<GenericResponse> {
await w.settings().save(req.profileId, req.settings);
return {
type: "generic_res",
status: 1, // ignored but whatever
+5 -2
View File
@@ -2,10 +2,13 @@ import { SaveStockerRequest } from "../request/saveStocker";
import { GenericResponse } from "../response/generic";
import { World } from "../world";
export function saveStocker(
export async function saveStocker(
w: World,
req: SaveStockerRequest
): GenericResponse {
): Promise<GenericResponse> {
await w.backgrounds().save(req.profileId, req.backgrounds);
await w.chara().save(req.profileId, req.chara);
return {
type: "generic_res",
status: 1, // ignored