initial profile save wire-up

This commit is contained in:
Tau
2019-11-06 17:28:29 -05:00
parent 9bdc840019
commit c79c1b870d
18 changed files with 145 additions and 8 deletions
+6 -1
View File
@@ -1,5 +1,7 @@
import { Id } from "../model/base";
import { Profile } from "../model/profile";
import { Settings } from "../model/settings";
import { Story } from "../model/story";
import { Team } from "../model/team";
import { CreateProfileRequest } from "../request/createProfile";
import { GenericResponse } from "../response/generic";
@@ -14,11 +16,12 @@ export async function createProfile(
teamId: 2 as Id<Team>,
name: req.name,
lv: 1,
exp: 0,
fame: 0,
dpoint: 0,
};
const settings = {
const settings: Settings = {
bgMusic: 0,
forceQuitEn: false,
steeringForce: 4,
@@ -30,6 +33,8 @@ export async function createProfile(
taResultSkip: false,
};
const story: Story = { x: 0, y: 0, rows: [] };
await Promise.all([
w.profile().save(profile.id, profile),
w.chara().save(profile.id, req.chara),
+4
View File
@@ -14,6 +14,7 @@ import { loadTeamRanking } from "./loadTeamRanking";
import { loadTopTen } from "./loadTopTen";
import { lockGarage } from "./lockGarage";
import { lockProfile } from "./lockProfile";
import { msg00AD } from "./msg00AD";
import { saveExpedition } from "./saveExpedition";
import { saveGarage } from "./saveGarage";
import { saveProfile } from "./saveProfile";
@@ -83,6 +84,9 @@ export async function dispatch(w: World, req: Request): Promise<Response> {
case "load_team_ranking_req":
return loadTeamRanking(w, req);
case "msg_00AD_req":
return msg00AD(w, req);
case "save_expedition_req":
return saveExpedition(w, req);
+5
View File
@@ -6,11 +6,15 @@ export async function loadProfile(
w: World,
req: LoadProfileRequest
): Promise<LoadProfileResponse2> {
// Promise.all would be messy here, who cares anyway this isn't supposed to
// be a high-performance server.
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);
const story = await w.story().load(profile.id);
return {
type: "load_profile_v2_res",
@@ -24,5 +28,6 @@ export async function loadProfile(
chara,
titles,
car,
story,
};
}
+7
View File
@@ -0,0 +1,7 @@
import { Message00AD } from "../request/msg00AD";
import { GenericResponse } from "../response/generic";
import { World } from "../world";
export function msg00AD(w: World, req: Message00AD): GenericResponse {
return { type: "generic_res" };
}
+16 -2
View File
@@ -2,10 +2,24 @@ import { SaveProfileRequest } from "../request/saveProfile";
import { GenericResponse } from "../response/generic";
import { World } from "../world";
export function saveProfile(
export async function saveProfile(
w: World,
req: SaveProfileRequest
): GenericResponse {
): Promise<GenericResponse> {
const profile = await w.profile().load(req.profileId);
await Promise.all([
w.profile().save(req.profileId, {
...profile,
lv: req.lv,
exp: req.exp,
fame: req.fame,
dpoint: req.dpoint,
}),
w.story().save(req.profileId, req.story),
w.titles().save(req.profileId, req.titles),
]);
return {
type: "generic_res",
status: 1,