Refactor repository layer (and implement garage)
This commit is contained in:
@@ -4,7 +4,7 @@ import { Profile } from "../model/profile";
|
||||
import { Settings } from "../model/settings";
|
||||
import { Story } from "../model/story";
|
||||
import { Team } from "../model/team";
|
||||
import { TimeAttackState } from "../model/timeAttack";
|
||||
import { TimeAttackScore } from "../model/timeAttack";
|
||||
import { Unlocks } from "../model/unlocks";
|
||||
import { CreateProfileRequest } from "../request/createProfile";
|
||||
import { GenericResponse } from "../response/generic";
|
||||
@@ -14,9 +14,11 @@ export async function createProfile(
|
||||
w: World,
|
||||
req: CreateProfileRequest
|
||||
): Promise<GenericResponse> {
|
||||
const profileId = await w.profile().generateId();
|
||||
|
||||
const profile: Profile = {
|
||||
id: 1 as Id<Profile>,
|
||||
teamId: 2 as Id<Team>,
|
||||
id: profileId,
|
||||
teamId: 2 as Id<Team>, // TODO
|
||||
name: req.name,
|
||||
lv: 1,
|
||||
exp: 0,
|
||||
@@ -28,17 +30,16 @@ export async function createProfile(
|
||||
const missions: MissionState = { team: [], solo: [] };
|
||||
const settings: Settings = { music: 0, pack: 13640, paperCup: 0, gauges: 5 };
|
||||
const story: Story = { x: 0, y: 0, rows: [] };
|
||||
const timeAttack: TimeAttackState = { courses: [] };
|
||||
const unlocks: Unlocks = { cup: 0, gauges: 0, music: 0 };
|
||||
|
||||
await Promise.all([
|
||||
w.profile().save(profile.id, profile),
|
||||
w.chara().save(profile.id, req.chara),
|
||||
w.car().save(profile.id, req.car),
|
||||
w.car().saveCar(profile.id, req.car),
|
||||
w.car().saveSelection(profile.id, req.car.selector),
|
||||
w.missions().save(profile.id, missions),
|
||||
w.settings().save(profile.id, settings),
|
||||
w.story().save(profile.id, story),
|
||||
w.timeAttack().save(profile.id, timeAttack),
|
||||
w.unlocks().save(profile.id, unlocks),
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Car } from "../model";
|
||||
import { LoadGarageRequest } from "../request/loadGarage";
|
||||
import { LoadGarageResponse } from "../response/loadGarage";
|
||||
import { World } from "../world";
|
||||
import { loadJson } from "../world/_util";
|
||||
|
||||
export async function loadGarage(
|
||||
w: World,
|
||||
req: LoadGarageRequest
|
||||
): Promise<LoadGarageResponse> {
|
||||
throw new Error("TODO");
|
||||
return {
|
||||
type: "load_garage_res",
|
||||
cars: await w.car().loadAllCars(req.profileId),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,12 +12,13 @@ export async function loadProfile(
|
||||
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 coursePlays = await w.coursePlays().load(profile.id);
|
||||
const titles = await w.titles().loadAll(profile.id);
|
||||
const coursePlays = await w.coursePlays().loadAll(profile.id);
|
||||
const missions = await w.missions().load(profile.id);
|
||||
const car = await w.car().load(profile.id);
|
||||
const car = await w.car().loadSelectedCar(profile.id);
|
||||
const carCount = await w.car().countCars(profile.id);
|
||||
const story = await w.story().load(profile.id);
|
||||
const timeAttack = await w.timeAttack().load(profile.id);
|
||||
const timeAttack = await w.timeAttack().loadAll(profile.id);
|
||||
const unlocks = await w.unlocks().load(profile.id);
|
||||
|
||||
return {
|
||||
@@ -37,6 +38,7 @@ export async function loadProfile(
|
||||
missions,
|
||||
timeAttack,
|
||||
car,
|
||||
carCount,
|
||||
story,
|
||||
unlocks,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function loadStocker(
|
||||
w: World,
|
||||
req: LoadStockerRequest
|
||||
): Promise<LoadStockerResponse> {
|
||||
const backgrounds = await w.backgrounds().load(req.profileId);
|
||||
const backgrounds = await w.backgrounds().loadAll(req.profileId);
|
||||
|
||||
return {
|
||||
type: "load_stocker_res",
|
||||
|
||||
@@ -23,11 +23,11 @@ export async function saveProfile(
|
||||
title: req.title,
|
||||
background: req.background,
|
||||
}),
|
||||
w.car().save(req.profileId, req.car),
|
||||
w.coursePlays().save(req.profileId, req.coursePlays),
|
||||
w.car().saveCar(req.profileId, req.car),
|
||||
w.coursePlays().saveAll(req.profileId, req.coursePlays),
|
||||
w.missions().save(req.profileId, req.missions),
|
||||
w.story().save(req.profileId, req.story),
|
||||
w.titles().save(req.profileId, req.titles),
|
||||
w.titles().saveAll(req.profileId, req.titles),
|
||||
w.unlocks().save(req.profileId, req.unlocks),
|
||||
w.settings().save(req.profileId, req.settings),
|
||||
]);
|
||||
|
||||
@@ -6,8 +6,11 @@ export async function saveStocker(
|
||||
w: World,
|
||||
req: SaveStockerRequest
|
||||
): Promise<GenericResponse> {
|
||||
await w.backgrounds().save(req.profileId, req.backgrounds);
|
||||
await w.chara().save(req.profileId, req.chara);
|
||||
await Promise.all([
|
||||
w.backgrounds().saveAll(req.profileId, req.backgrounds),
|
||||
w.chara().save(req.profileId, req.chara),
|
||||
w.car().saveSelection(req.profileId, req.selectedCar),
|
||||
]);
|
||||
|
||||
return { type: "generic_res" };
|
||||
}
|
||||
|
||||
@@ -7,21 +7,12 @@ export async function saveTimeAttack(
|
||||
req: SaveTimeAttackRequest
|
||||
): Promise<SaveTimeAttackResponse> {
|
||||
if (req.payload.totalMsec > 0) {
|
||||
const state = await w.timeAttack().load(req.profileId);
|
||||
const existing = state.courses.find(
|
||||
course => course.courseId === req.payload.courseId
|
||||
);
|
||||
const existing = await w
|
||||
.timeAttack()
|
||||
.load(req.profileId, req.payload.courseId);
|
||||
|
||||
if (existing === undefined || existing.totalMsec > req.payload.totalMsec) {
|
||||
const newCourses = state.courses.filter(
|
||||
course => course.courseId !== req.payload.courseId
|
||||
);
|
||||
|
||||
newCourses.push(req.payload);
|
||||
|
||||
const newState = { courses: newCourses };
|
||||
|
||||
await w.timeAttack().save(req.profileId, newState);
|
||||
await w.timeAttack().save(req.profileId, req.payload);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user