kopia lustrzana https://github.com/backface/turtlestitch
Cleanup LIBRARIES; Load Libraries using refactored code
rodzic
2b69b91a4a
commit
b2c6b43192
62
gui.js
62
gui.js
|
@ -2569,25 +2569,24 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
'Libraries...',
|
'Libraries...',
|
||||||
function () {
|
function () {
|
||||||
// read a list of libraries from an external file,
|
// read a list of libraries from an external file,
|
||||||
var libMenu = new MenuMorph(this, 'Import library'),
|
// TODO: Make menu name consistent, fix URL
|
||||||
libUrl = baseURL + 'libraries/' + 'LIBRARIES';
|
var libs,
|
||||||
|
libMenu = new MenuMorph(this, 'Import library'),
|
||||||
|
libUrl = 'libraries/' + 'LIBRARIES';
|
||||||
|
|
||||||
function loadLib(name) {
|
function loadLib(file, name) {
|
||||||
var url = baseURL + 'libraries/' + name + '.xml';
|
// TODO: Consistent URL
|
||||||
|
var url = 'libraries/' + file;
|
||||||
myself.droppedText(myself.getURL(url), name);
|
myself.droppedText(myself.getURL(url), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
myself.getURL(libUrl).split('\n').forEach(function (line) {
|
libs = myself.getURL(libUrl);
|
||||||
if (line.length > 0) {
|
myself.parseResourceFile(libs).forEach(function (lib) {
|
||||||
libMenu.addItem(
|
libMenu.addItem(
|
||||||
line.substring(line.indexOf('\t') + 1),
|
lib.name,
|
||||||
function () {
|
function () { loadLib(lib.file, lib.name) },
|
||||||
loadLib(
|
lib.help
|
||||||
line.substring(0, line.indexOf('\t'))
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
libMenu.popup(world, pos);
|
libMenu.popup(world, pos);
|
||||||
|
@ -2606,6 +2605,7 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
);
|
);
|
||||||
|
|
||||||
function loadCostume(name) {
|
function loadCostume(name) {
|
||||||
|
// TODO: Make this URL consistent
|
||||||
var url = dir + '/' + name,
|
var url = dir + '/' + name,
|
||||||
img = new Image();
|
img = new Image();
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
|
@ -2632,9 +2632,11 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
localize('Sounds') + '...',
|
localize('Sounds') + '...',
|
||||||
function () {
|
function () {
|
||||||
var names = this.getMediaList('Sounds'),
|
var names = this.getMediaList('Sounds'),
|
||||||
|
// TODO: Fix this menu name
|
||||||
libMenu = new MenuMorph(this, 'Import sound');
|
libMenu = new MenuMorph(this, 'Import sound');
|
||||||
|
|
||||||
function loadSound(name) {
|
function loadSound(name) {
|
||||||
|
// TODO: Refactor This URL
|
||||||
var url = 'Sounds/' + name,
|
var url = 'Sounds/' + name,
|
||||||
audio = new Audio();
|
audio = new Audio();
|
||||||
audio.src = url;
|
audio.src = url;
|
||||||
|
@ -2659,9 +2661,11 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.getMediaList = function (dirname) {
|
IDE_Morph.prototype.getMediaList = function (dirname) {
|
||||||
|
// TODO: Fix Variable Names
|
||||||
var dir,
|
var dir,
|
||||||
costumes = [];
|
costumes = [];
|
||||||
|
|
||||||
|
// TODO: have this load the /UPPERCASE name
|
||||||
dir = this.getURL(dirname);
|
dir = this.getURL(dirname);
|
||||||
dir.split('\n').forEach(
|
dir.split('\n').forEach(
|
||||||
function (line) {
|
function (line) {
|
||||||
|
@ -2690,8 +2694,34 @@ IDE_Morph.prototype.getMediaList = function (dirname) {
|
||||||
// All lines have 3 fields: file-name, Display Name, Help Text
|
// All lines have 3 fields: file-name, Display Name, Help Text
|
||||||
// These fields are delimited by tabs.
|
// These fields are delimited by tabs.
|
||||||
IDE_Morph.prototype.parseResourceFile = function (text) {
|
IDE_Morph.prototype.parseResourceFile = function (text) {
|
||||||
|
var parts,
|
||||||
|
items = [],
|
||||||
|
comment = '#',
|
||||||
|
delimter = '\t';
|
||||||
|
|
||||||
}
|
text = text.split(/\n|\r\n/);
|
||||||
|
|
||||||
|
text.map(function (line) {
|
||||||
|
return line.trim();
|
||||||
|
}).filter(function (line) {
|
||||||
|
return line.length > 0 && line[0] !== comment;
|
||||||
|
}).forEach(function (line) {
|
||||||
|
parts = line.split(delimter);
|
||||||
|
parts = parts.map(function (str) { return str.trim() });
|
||||||
|
|
||||||
|
if (parts.length < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push({
|
||||||
|
file: parts[0],
|
||||||
|
name: parts[1],
|
||||||
|
help: parts.length > 2 ? parts[2] : ''
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// IDE_Morph menu actions
|
// IDE_Morph menu actions
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
iteration-composition Iteration, composition
|
iteration-composition.xml Iteration, composition
|
||||||
list-utilities List utilities
|
list-utilities.xml List utilities
|
||||||
stream-tools Streams (lazy lists)
|
stream-tools.xml Streams (lazy lists)
|
||||||
variadic-reporters Variadic reporters
|
variadic-reporters.xml Variadic reporters
|
||||||
word-sentence Words, sentences
|
word-sentence.xml Words, sentences
|
||||||
cases Multi-branched conditional (switch)
|
cases.xml Multi-branched conditional (switch)
|
||||||
leap-library LEAP Motion controller
|
leap-library.xml LEAP Motion controller
|
||||||
TEST-TEST TEST-1234-45678
|
|
||||||
|
|
Ładowanie…
Reference in New Issue