2019-07-24 20:31:49 +08:00
|
|
|
import { Persister } from "./Persister";
|
|
|
|
import { Server, HuntMethod } from "../domain";
|
|
|
|
|
2019-07-24 22:44:17 +08:00
|
|
|
const METHOD_USER_TIMES_KEY = "HuntMethodStore.methodUserTimes";
|
|
|
|
|
2019-07-24 20:31:49 +08:00
|
|
|
class HuntMethodPersister extends Persister {
|
|
|
|
persist_method_user_times(hunt_methods: HuntMethod[], server: Server): void {
|
|
|
|
const user_times: PersistedUserTimes = {};
|
|
|
|
|
|
|
|
for (const method of hunt_methods) {
|
|
|
|
if (method.user_time != undefined) {
|
|
|
|
user_times[method.id] = method.user_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:44:17 +08:00
|
|
|
this.persist_for_server(server, METHOD_USER_TIMES_KEY, user_times);
|
2019-07-24 20:31:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async load_method_user_times(
|
|
|
|
hunt_methods: HuntMethod[],
|
|
|
|
server: Server
|
|
|
|
): Promise<HuntMethod[]> {
|
|
|
|
const user_times = await this.load_for_server<PersistedUserTimes>(
|
|
|
|
server,
|
2019-07-24 22:44:17 +08:00
|
|
|
METHOD_USER_TIMES_KEY
|
2019-07-24 20:31:49 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
if (user_times) {
|
|
|
|
for (const method of hunt_methods) {
|
|
|
|
method.user_time = user_times[method.id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hunt_methods;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PersistedUserTimes = { [method_id: string]: number };
|
|
|
|
|
|
|
|
export const hunt_method_persister = new HuntMethodPersister();
|