mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-03-21 17:34:46 -05:00
Add simple import of data from non-core asphyxia
This commit is contained in:
parent
10207c1044
commit
7fcd3024c1
|
|
@ -11,8 +11,4 @@ Changelog
|
|||
=========
|
||||
1.0.0
|
||||
-----
|
||||
Initial Release.
|
||||
|
||||
TODO
|
||||
====
|
||||
- Import of old Asphyxia data
|
||||
Initial Release.
|
||||
33
popn@asphyxia/handler/webui.ts
Normal file
33
popn@asphyxia/handler/webui.ts
Normal file
|
|
@ -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<Profile>(
|
||||
data.refid,
|
||||
{ collection: 'profile' },
|
||||
{
|
||||
$set: {
|
||||
...profile
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
await DB.Upsert<Scores>(
|
||||
data.refid,
|
||||
{ collection: 'scores' },
|
||||
{
|
||||
$set: {
|
||||
scores: {
|
||||
...scores
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
@ -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);
|
||||
}
|
||||
11
popn@asphyxia/webui/js/profile_page.js
Normal file
11
popn@asphyxia/webui/js/profile_page.js
Normal file
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
24
popn@asphyxia/webui/profile_page.pug
Normal file
24
popn@asphyxia/webui/profile_page.pug
Normal file
|
|
@ -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")
|
||||
Loading…
Reference in New Issue
Block a user