From 7fcd3024c1b7311b072a480eaffdeeb8806772eb Mon Sep 17 00:00:00 2001 From: cracrayol Date: Sat, 12 Dec 2020 23:44:01 +0100 Subject: [PATCH] Add simple import of data from non-core asphyxia --- popn@asphyxia/README.md | 6 +--- popn@asphyxia/handler/webui.ts | 33 +++++++++++++++++ popn@asphyxia/index.ts | 49 ++++++++++++++------------ popn@asphyxia/webui/js/profile_page.js | 11 ++++++ popn@asphyxia/webui/profile_page.pug | 24 +++++++++++++ 5 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 popn@asphyxia/handler/webui.ts create mode 100644 popn@asphyxia/webui/js/profile_page.js create mode 100644 popn@asphyxia/webui/profile_page.pug diff --git a/popn@asphyxia/README.md b/popn@asphyxia/README.md index ed3fad4..fde0db8 100644 --- a/popn@asphyxia/README.md +++ b/popn@asphyxia/README.md @@ -11,8 +11,4 @@ Changelog ========= 1.0.0 ----- -Initial Release. - -TODO -==== -- Import of old Asphyxia data \ No newline at end of file +Initial Release. \ No newline at end of file diff --git a/popn@asphyxia/handler/webui.ts b/popn@asphyxia/handler/webui.ts new file mode 100644 index 0000000..139ccd1 --- /dev/null +++ b/popn@asphyxia/handler/webui.ts @@ -0,0 +1,33 @@ +import { Profile } from "../models/profile"; +import { Scores } from "../models/scores"; + +export const importPnmData = async (data: { + refid: string; + profile: string; + scores: string; +}) => { + const profile = JSON.parse(data.profile); + const scores = JSON.parse(data.scores); + + await DB.Update( + data.refid, + { collection: 'profile' }, + { + $set: { + ...profile + } + } + ); + + await DB.Upsert( + data.refid, + { collection: 'scores' }, + { + $set: { + scores: { + ...scores + } + } + } + ); +}; \ No newline at end of file diff --git a/popn@asphyxia/index.ts b/popn@asphyxia/index.ts index 0f83c80..c5eb5bb 100644 --- a/popn@asphyxia/index.ts +++ b/popn@asphyxia/index.ts @@ -1,30 +1,33 @@ import { getInfo } from "./handler/common"; -import { newPlayer, read, readScore, start, writeMusic, write, buy} from "./handler/player" +import { newPlayer, read, readScore, start, writeMusic, write, buy } from "./handler/player"; +import { importPnmData } from "./handler/webui"; export function register() { - R.GameCode('M39'); + R.GameCode('M39'); - const PlayerRoute = (method: string, handler: EPR | boolean) => { - R.Route(`player24.${method}`, handler); - R.Route(`player23.${method}`, handler); - }; + R.WebUIEvent('importPnmData', importPnmData); - const CommonRoute = (method: string, handler: EPR | boolean) => { - R.Route(`info24.${method}`, handler); - R.Route(`info23.${method}`, handler); - }; - - // Common - CommonRoute('common', (req, data, send) => { - return send.object(getInfo(req)); - }); + const PlayerRoute = (method: string, handler: EPR | boolean) => { + R.Route(`player24.${method}`, handler); + R.Route(`player23.${method}`, handler); + }; - // Player - PlayerRoute('new', newPlayer); - PlayerRoute('read', read); - PlayerRoute('read_score', readScore); - PlayerRoute('write_music', writeMusic); - PlayerRoute('write', write); - PlayerRoute('start', start); - PlayerRoute('buy', buy); + const CommonRoute = (method: string, handler: EPR | boolean) => { + R.Route(`info24.${method}`, handler); + R.Route(`info23.${method}`, handler); + }; + + // Common + CommonRoute('common', (req, data, send) => { + return send.object(getInfo(req)); + }); + + // Player + PlayerRoute('new', newPlayer); + PlayerRoute('read', read); + PlayerRoute('read_score', readScore); + PlayerRoute('write_music', writeMusic); + PlayerRoute('write', write); + PlayerRoute('start', start); + PlayerRoute('buy', buy); } \ No newline at end of file diff --git a/popn@asphyxia/webui/js/profile_page.js b/popn@asphyxia/webui/js/profile_page.js new file mode 100644 index 0000000..008af26 --- /dev/null +++ b/popn@asphyxia/webui/js/profile_page.js @@ -0,0 +1,11 @@ +$('#import-click').on('click', () => { + data = { + refid: $('#refid').val(), + profile: $('#profile').val(), + scores: $('#scores').val() + } + + emit('importPnmData', data).then(() => { + $('#import-success').removeClass("is-hidden"); + }); +}); diff --git a/popn@asphyxia/webui/profile_page.pug b/popn@asphyxia/webui/profile_page.pug new file mode 100644 index 0000000..49043ff --- /dev/null +++ b/popn@asphyxia/webui/profile_page.pug @@ -0,0 +1,24 @@ +div + div.notification.is-success.is-hidden#import-success + .field + label.label.is-small Data imported + .card + .card-header + p.card-header-title + span.icon + i.mdi.mdi-account-edit + | Import data + .card-content + input(type="hidden" id="refid" name="refid" value=refid) + .field + label.label Import data from previous Asphyxia (non-core) + .field + input.input(type="text" id="profile" name="profile" placeholder="Put content of popn.json") + .field + input.input(type="text" id="scores" name="scores" placeholder="Put content of popn_scores.json") + .field + label.help.is-danger /!\ Please backup your savedata.db before importing data /!\ + .field + button.button.is-primary#import-click Import + +script(src="static/js/profile_page.js") \ No newline at end of file