add chart data

steps, jumps, mines, etc
This commit is contained in:
oat 2020-09-04 18:02:42 +03:00
parent 64446588c9
commit 1ed6dc6185
Signed by: oat
GPG key ID: DD83A9617A252385
4 changed files with 25 additions and 6 deletions

View file

@ -24,7 +24,8 @@
let charts = document.createElement('ul'); let charts = document.createElement('ul');
for (const chart of doc.charts) { for (const chart of doc.charts) {
let l = document.createElement('li'); let l = document.createElement('li');
l.innerText = `${chart.difficulty} ${chart.rating} - ${chart.name}` l.innerText = `${chart.difficulty} ${chart.rating} - ${chart.name}\n` +
`${chart.steps} steps, ${chart.mines} mines, ${chart.jumps} jumps, ${chart.hands} hands, ${chart.holds} holds, ${chart.rolls} rolls`
charts.insertAdjacentElement('beforeend', l); charts.insertAdjacentElement('beforeend', l);
} }
el.insertAdjacentElement('beforeend', charts); el.insertAdjacentElement('beforeend', charts);

View file

@ -1,6 +1,4 @@
export function parseSM(data: string) { export function parseSM(data: string) {
data = data.replace(/[\n\r]/g,'');
// steps // steps
const difficulties = []; const difficulties = [];
const steps = data.split('#NOTES:'); const steps = data.split('#NOTES:');
@ -18,11 +16,25 @@ export function parseSM(data: string) {
diff.rating = Number(stepsSplit[3]); diff.rating = Number(stepsSplit[3]);
diff.radarvalues = stepsSplit[4].split(',').map(v => Number(v)); diff.radarvalues = stepsSplit[4].split(',').map(v => Number(v));
const chart = stepsSplit[5];
diff.rawChart = chart;
diff.steps = chart.split(/[124]/g).length - 1;
diff.mines = chart.split('M').length - 1;
diff.jumps = chart.split(/[124]0{0,2}[124]/g).length - 1;
diff.hands = chart.split(/[124]0{0,1}[124]0{0,1}[124]/g).length - 1;
diff.holds = chart.split('2').length - 1;
diff.rolls = chart.split('4').length - 1;
diff.steps -= diff.jumps; // jumps are counted as 1 step
difficulties.push(diff); difficulties.push(diff);
} }
} }
} }
data = data.replace(/[\n\r]/g,'');
// metadata // metadata
const lines = data.split(';').filter(l => l.startsWith('#')); const lines = data.split(';').filter(l => l.startsWith('#'));
const obj: any = {}; const obj: any = {};

View file

@ -40,7 +40,14 @@ const Chart = new Schema({
ratingsVote: {type: [UserRating], default: []}, ratingsVote: {type: [UserRating], default: []},
spoilered: {type: Boolean, default: false}, spoilered: {type: Boolean, default: false},
hidden: {type: Boolean, default: false} hidden: {type: Boolean, default: false},
steps: {type: Number, default: 0},
mines: {type: Number, default: 0},
jumps: {type: Number, default: 0},
hands: {type: Number, default: 0},
holds: {type: Number, default: 0},
rolls: {type: Number, default: 0},
}); });
const Comment = new Schema({ const Comment = new Schema({

View file

@ -2,7 +2,6 @@ import { tmpdir } from 'os';
import * as fs from 'fs'; import * as fs from 'fs';
const StreamZip = require('node-stream-zip'); const StreamZip = require('node-stream-zip');
import { returnStatic } from './lib/util';
import { parseSM } from './lib/smparse'; import { parseSM } from './lib/smparse';
import { File } from './schema'; import { File } from './schema';