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 words = line.split(' '); const width = parseInt(words.shift()); const data = new Float32Array(words.map(i => parseFloat(i))); const points = new Float32Array(data.length / 3 * 2); const pressures = new Uint8Array(data.length / 3); if (first_point_x === null) { first_point_x = points[0]; first_point_y = points[1]; } for (let i = 0; i < data.length; i += 3) { points[i / 3 * 2 + 0] = data[i + 0]; points[i / 3 * 2 + 1] = data[i + 1]; pressures[i / 3 + 0] = Math.floor(data[i + 2] * 255); } const stroke_res = storage.queries.insert_stroke.get({ '$width': width, '$color': 0, '$points': points, '$pressures': pressures, }); storage.queries.insert_event.run({ '$type': EVENT.STROKE, '$desk_id': desk_id, '$session_id': 0, '$stroke_id': stroke_res.id, '$image_id': 0, '$corner': 0, '$x': 0, '$y': 0, '$width': 0, '$height': 0, }); } async function import_milton_file_to_sqlite(fullpath) { storage.startup(); const desk_id = 9881; // 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]); } console.log(`Finished importing desk ${desk_id}`); } async function set_dimentions_to_images(fullpath) { const images = [ // ]; storage.startup(); for (const image of images) { storage.db.run(`UPDATE events SET width = ${image.w}, height = ${image.h} WHERE image_id = ${image.t};`); } } set_dimentions_to_images();