Commit 9205ac94 authored by nerrons's avatar nerrons
Browse files

Add a parser for K12 help patches to retrieve tooltip content

parent 7238ca3b
Pipeline #1629 failed with stage
in 0 seconds
......@@ -329,6 +329,7 @@ var pd_myversion, // Pd version string
global_selection, //
k12_mode = 0,
k12_offset = 0,
k12_xlet_tt,
k12_saveas_on_new, //
autotips, // tooltips
magicglass, // cord inspector
......@@ -343,31 +344,82 @@ var pd_myversion, // Pd version string
// 3: screen y
pd_colors = {}; // associative array of canvas color presets
var pd_filetypes = { ".pd": "Pd Files",
".pat":"Max Patch Files",
".mxt":"Max Text Files",
".mxb":"Max Binary Files",
".help":"Max Help Files"
};
exports.pd_filetypes = pd_filetypes;
// gets called once by index.js when initializing
exports.set_k12_mode = function (k12) {
k12_mode = k12; // set the global k12 variable
k12_offset = k12_mode ? -200 : 0;
if (k12_mode) {
post("K12 mode is on. K12 offset: " + k12_offset);
} else {
post("K12 mode is off");
}
var pd_filetypes = {
".pd": "Pd Files",
".pat":"Max Patch Files",
".mxt":"Max Text Files",
".mxb":"Max Binary Files",
".help":"Max Help Files"
};
exports.pd_filetypes = pd_filetypes;
// gets called once by index.js when initializing
exports.set_k12_mode = function (k12) {
k12_mode = k12 ? 1 : 0; // set the global k12 variable
k12_offset = k12_mode ? -200 : 0;
if (k12_mode) {
post("K12 mode is on. K12 offset: " + k12_offset);
build_k12_xlet_tt();
} else {
post("K12 mode is off");
}
exports.get_k12_mode = function () { return k12_mode; };
exports.get_k12_offset = function () { return k12_offset; };
exports.get_k12_demo_dir = function () {
return path.join(lib_dir, "extra/K12/demos");
}
exports.get_k12_mode = function () { return k12_mode; };
exports.get_k12_offset = function () { return k12_offset; };
exports.get_k12_demo_dir = function () {
return path.join(lib_dir, "extra/K12/demos");
}
function build_k12_xlet_tt() {
k12_xlet_tt = {}; // after: { "ab1": { "i0": "content", "o0": "content", ...}, "ab2": ... }
var help_patch_files;
try {
help_patch_files = fs.readdirSync("extra/K12")
.filter(function (f) { return f.endsWith("-help.pd"); });
} catch (err) {
post("err: " + err);
}
help_patch_files.forEach(function (filename) {
try {
var f = fs.readFileSync("extra/K12/" + filename).toString();
var ab_name = filename.slice(0, -8); // remove -help.pd
k12_xlet_tt[ab_name] = {};
f.split(" META 0;")[1].split(" pd META;")[0] // get content within pd META
.replace(/[\r\n\x0B\x0C\u0085\u2028\u2029]+/g, " ") // normalize the various linebreaks
.replace(/([^\\]);/g, '$1\u000B').split('\u000B') // split by ; but not \;
.slice(0, -1) // remove the last line which is #X restore
// now each element starts with either INLET_, OUTLET_ or DESCRIPTION
.map(function (l) {
var line = l.trim()
.replace(/#X text [0-9]+ [0-9]+ /g, "") // remove #X text <number> <number>
.replace(/\\,/g, ",").replace(/ ,/g, ","); // remove the escaping of commas
if (line.endsWith(".")) line = line.slice(0, -1);
if (line.startsWith("INLET_")) {
var parsed_line = line.match(/INLET_(\d+) (.*)/);
var xlet_no = Number(parsed_line[1]),
tt_content = parsed_line[2];
k12_xlet_tt[ab_name]["i" + xlet_no] = tt_content;
} else if (line.startsWith("OUTLET_")) {
var parsed_line = line.match(/OUTLET_(\d+) (.*)/);
var xlet_no = Number(parsed_line[1]),
tt_content = parsed_line[2];
k12_xlet_tt[ab_name]["o" + xlet_no] = tt_content;
}
// currently ignoring DESCRIPTION
});
} catch (err) {
post("err: " + err);
}
});
// Object.keys(k12_xlet_tt).forEach(function (ab) {
// post("----- " + ab);
// Object.keys(k12_xlet_tt[ab]).forEach(function (xlet) {
// post(xlet + ": " + k12_xlet_tt[ab][xlet]);
// });
// });
// post("#####################");
}
popup_coords = [0,0];
popup_coords = [0,0];
// Keycode vs Charcode: A Primer
// -----------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment