Commit be8856af authored by nerrons's avatar nerrons

Fix: make extra/K12 dir work on all platforms

parent fe74de1f
Pipeline #1655 failed with stage
in 0 seconds
......@@ -112,14 +112,14 @@
<div id="k12-frame" class="control-panel">
<button
id="k12-edit-button"
><img id="k12-edit-button-icon" src="./extra/K12/icons-large/perform.png"></button>
><img id="k12-edit-button-icon"></button>
<div id="k12-panel-toggles">
<button
id="k12-control-button"
><img id="k12-control-button-icon" src="./extra/K12/icons/control_on.png"></button>
><img id="k12-control-button-icon"></button>
<button
id="k12-sound-button"
><img id="k12-sound-button-icon" src="./extra/K12/icons/sound.png"></button>
><img id="k12-sound-button-icon"></button>
</div>
<div id="k12-buttons">
<div id="k12-buttons-control"></div>
......
......@@ -12,6 +12,7 @@ pdgui.skin.apply(window);
var l = pdgui.get_local_string;
var k12_mode = pdgui.get_k12_mode();
var k12_offset = pdgui.get_k12_offset();
var k12_dir = "file://" + pdgui.get_k12_dir();
function nw_window_focus_callback(name) {
pdgui.set_focused_patchwin(name);
......@@ -895,21 +896,23 @@ var canvas_events = (function() {
var k12frame = document.getElementById("k12-frame");
// add edit and control/sound buttons
document.getElementById("k12-edit-button").firstChild.src = k12_dir + "/icons-large/perform.png";
document.getElementById("k12-edit-button").onclick = function () {
// first change the button in case pd responds later than the "editmode" check
if (document.getElementById("patchsvg").classList.contains("editmode")) {
document.getElementById("k12-edit-button").firstElementChild.src =
"./extra/K12/icons-large/perform.png";
k12_dir + "/icons-large/perform.png";
document.getElementById("k12-edit-button").title =
"Start playing the patch you created!"
} else {
document.getElementById("k12-edit-button").firstElementChild.src =
"./extra/K12/icons-large/edit.png";
k12_dir + "/icons-large/edit.png";
document.getElementById("k12-edit-button").title =
"Start building your own patch!"
}
pdgui.pdsend(name, "editmode 0");
}
document.getElementById("k12-control-button").firstChild.src = k12_dir + "/icons/control_on.png";
document.getElementById("k12-control-button").onclick = function () {
if (k12frame.classList.contains("sound-panel")) {
k12frame.classList.remove("sound-panel");
......@@ -917,11 +920,12 @@ var canvas_events = (function() {
document.getElementById("k12-buttons-control").style.visibility = "visible";
document.getElementById("k12-buttons-sound").style.visibility = "hidden";
document.getElementById("k12-control-button").firstElementChild.src =
"./extra/K12/icons/control_on.png";
k12_dir + "/icons/control_on.png";
document.getElementById("k12-sound-button").firstElementChild.src =
"./extra/K12/icons/sound.png";
k12_dir + "/icons/sound.png";
}
}
document.getElementById("k12-sound-button").firstChild.src = k12_dir + "/icons/sound.png";
document.getElementById("k12-sound-button").onclick = function () {
if (k12frame.classList.contains("control-panel")) {
k12frame.classList.remove("control-panel");
......@@ -929,9 +933,9 @@ var canvas_events = (function() {
document.getElementById("k12-buttons-sound").style.visibility = "visible";
document.getElementById("k12-buttons-control").style.visibility = "hidden";
document.getElementById("k12-sound-button").firstElementChild.src =
"./extra/K12/icons/sound_on.png";
k12_dir + "/icons/sound_on.png";
document.getElementById("k12-control-button").firstElementChild.src =
"./extra/K12/icons/control.png";
k12_dir + "/icons/control.png";
}
}
......@@ -985,7 +989,7 @@ var canvas_events = (function() {
// set the icon for the button
var icon = document.createElement("img");
icon.className = "k12-button-icon";
icon.src = "./extra/K12/icons-large/" + fullname + ".png";
icon.src = k12_dir + "/icons-large/" + fullname + ".png";
button.appendChild(icon);
if (panel === "control") {
k12_control_buttons_div.appendChild(button);
......@@ -1592,10 +1596,10 @@ function nw_create_patch_window_menus(gui, w, name) {
// change button appearance first to avoid delays
var edit_button = document.getElementById("k12-edit-button");
if (document.getElementById("patchsvg").classList.contains("editmode")) {
edit_button.firstElementChild.src = "./extra/K12/icons-large/perform.png";
edit_button.firstElementChild.src = k12_dir + "/icons-large/perform.png";
edit_button.title = "Start playing the patch you created!"
} else {
edit_button.firstElementChild.src = "./extra/K12/icons-large/edit.png";
edit_button.firstElementChild.src = k12_dir + "/icons-large/edit.png";
edit_button.title = "Start building your own patch!"
}
}
......
......@@ -42,6 +42,13 @@ function gui_set_browser_config(doc_flag, path_flag, init_flag, helppath) {
function gui_set_lib_dir(dir) {
lib_dir = dir;
// This definitely shouldn't be here, but this seems to be the only safe
// place to run build_k12_xlet_tt() ensuring that lib_dir isn't undefined,
// if we are not modifying the C code.
if (k12_mode && !k12_xlet_tt_ready) {
k12_xlet_tt_ready = 1;
build_k12_xlet_tt();
}
}
exports.get_lib_dir = function() {
......@@ -329,7 +336,8 @@ var pd_myversion, // Pd version string
global_selection, //
k12_mode = 0,
k12_offset = 0,
k12_xlet_tt,
k12_xlet_tt, // a dictionary of xlet tooltips
k12_xlet_tt_ready = 0, // has k12_xlet_tt been built
k12_saveas_on_new, //
autotips, // tooltips
magicglass, // cord inspector
......@@ -353,34 +361,39 @@ var pd_filetypes = {
};
exports.pd_filetypes = pd_filetypes;
// gets called once by index.js when initializing
// k12 related functions
// set_k12_mode 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; };
function get_k12_dir() {
return path.join(lib_dir, "extra/K12");
}
exports.get_k12_dir = get_k12_dir;
exports.get_k12_demo_dir = function () {
return path.join(lib_dir, "extra/K12/demos");
return path.join(get_k12_dir(), "demos");
}
function build_k12_xlet_tt() {
var help_patch_files;
var help_patch_files,
k12_dir = get_k12_dir();
k12_xlet_tt = {}; // after: { "add": { "i0": "content", "o0": "content", ...}, "subtract": ... }
try {
help_patch_files = fs.readdirSync("extra/K12")
help_patch_files = fs.readdirSync(k12_dir)
.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 f = fs.readFileSync(path.join(k12_dir, 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
......@@ -413,6 +426,7 @@ function build_k12_xlet_tt() {
post("err: " + err);
}
});
post("xlet_tt building finished.");
}
popup_coords = [0,0];
......@@ -2176,6 +2190,9 @@ exports.gui = gui;
// In the future, it might make sense to combine the scalar and object
// creation, in which case a flag to toggle the offset would be appropriate.
// For K12 mode tooltips, we have the additional "text" parameter so we know
// which K12 abstraction is our new gobj representing, making it possible
// to retrieve tooltip content from k12_xlet_tt.
function gui_gobj_new(cid, tag, type, xpos, ypos, is_toplevel, text) {
var g;
xpos += 0.5;
......
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