You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.9 KiB
69 lines
1.9 KiB
12 months ago
|
import * as storage from './storage.js'
|
||
|
import * as math from './math.js'
|
||
|
|
||
|
import { SESSION, MESSAGE, EVENT } from './enums';
|
||
|
|
||
|
let first_point_x = null;
|
||
|
let first_point_y = null;
|
||
|
|
||
|
function parse_and_insert_stroke(desk_id, line) {
|
||
|
const stroke_id = math.fast_random32();
|
||
|
const points = new Float32Array(line.split(' ').filter(s => s.length > 0).map(i => parseFloat(i)));
|
||
|
|
||
|
if (first_point_x === null) {
|
||
|
first_point_x = 1;
|
||
|
first_point_y = 1;
|
||
|
} else if (first_point_x === 1) {
|
||
|
first_point_x = points[0];
|
||
|
first_point_y = points[1];
|
||
|
}
|
||
|
|
||
|
for (let i = 0; i < points.length; i += 2) {
|
||
|
points[i + 0] -= first_point_x;
|
||
|
points[i + 1] -= first_point_y;
|
||
|
}
|
||
|
|
||
|
storage.queries.insert_stroke.run({
|
||
|
'$id': stroke_id,
|
||
|
'$width': 8, // possibly handle pressure here if we ever support it
|
||
|
'$color': 0,
|
||
|
'$points': points
|
||
|
});
|
||
|
|
||
|
storage.queries.insert_event.run({
|
||
|
'$type': EVENT.STROKE,
|
||
|
'$desk_id': desk_id,
|
||
|
'$session_id': 0,
|
||
|
'$stroke_id': stroke_id,
|
||
|
'$image_id': 0,
|
||
|
'$x': 0,
|
||
|
'$y': 0,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async function import_milton_file_to_sqlite(fullpath) {
|
||
|
storage.startup();
|
||
|
|
||
|
const desk_id = 542; // math.fast_random32();
|
||
|
|
||
|
console.log(`Importing ${fullpath} into desk ${desk_id}`);
|
||
|
|
||
|
storage.queries.insert_desk.run({
|
||
|
'$id': desk_id,
|
||
|
'$title': `Desk ${desk_id}`
|
||
|
});
|
||
|
|
||
|
const input_file = Bun.file(fullpath);
|
||
|
const input_text = await input_file.text();
|
||
|
const input_lines = input_text.split('\n');
|
||
|
|
||
|
for (let i = 0; i < input_lines.length; ++i) {
|
||
|
console.log(`Importing ${i}/${input_lines.length}`);
|
||
|
parse_and_insert_stroke(desk_id, input_lines[i]);
|
||
|
}
|
||
|
|
||
|
consoe.log(`Finished importing desk ${desk_id}`);
|
||
|
}
|
||
|
|
||
|
import_milton_file_to_sqlite("/home/aolo2/desk2/server/points.txt");
|