kopia lustrzana https://github.com/backface/turtlestitch
Fix #867; All media has an index file that is being used to load files
rodzic
7b0fc4a17f
commit
c6b43bee12
74
gui.js
74
gui.js
|
@ -2570,21 +2570,18 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
function () {
|
function () {
|
||||||
// read a list of libraries from an external file,
|
// read a list of libraries from an external file,
|
||||||
// TODO: Make menu name consistent, fix URL
|
// TODO: Make menu name consistent, fix URL
|
||||||
var libs,
|
var libMenu = new MenuMorph(this, 'Import library'),
|
||||||
libMenu = new MenuMorph(this, 'Import library'),
|
libraries = this.getMediaList('libraries');
|
||||||
libUrl = 'libraries/' + 'LIBRARIES';
|
|
||||||
|
|
||||||
function loadLib(file, name) {
|
function loadLib(file, name) {
|
||||||
// TODO: Consistent URL
|
var url = myself.resourceURL('libraries', file);
|
||||||
var url = 'libraries/' + file;
|
|
||||||
myself.droppedText(myself.getURL(url), name);
|
myself.droppedText(myself.getURL(url), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
libs = myself.getURL(libUrl);
|
libraries.forEach(function (lib) {
|
||||||
myself.parseResourceFile(libs).forEach(function (lib) {
|
|
||||||
libMenu.addItem(
|
libMenu.addItem(
|
||||||
lib.name,
|
lib.name,
|
||||||
function () { loadLib(lib.file, lib.name) },
|
function () {loadLib(lib.file, lib.name) },
|
||||||
lib.help
|
lib.help
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -2605,8 +2602,7 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
);
|
);
|
||||||
|
|
||||||
function loadCostume(name) {
|
function loadCostume(name) {
|
||||||
// TODO: Make this URL consistent
|
var url = myself.resourceURL(dir, name),
|
||||||
var url = dir + '/' + name,
|
|
||||||
img = new Image();
|
img = new Image();
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
var canvas = newCanvas(new Point(img.width, img.height));
|
var canvas = newCanvas(new Point(img.width, img.height));
|
||||||
|
@ -2616,13 +2612,12 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
img.src = url;
|
img.src = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
names.forEach(function (line) {
|
names.forEach(function (image) {
|
||||||
if (line.length > 0) {
|
|
||||||
libMenu.addItem(
|
libMenu.addItem(
|
||||||
line,
|
image.name,
|
||||||
function () {loadCostume(line); }
|
function () {loadCostume(image.file); },
|
||||||
|
image.help
|
||||||
);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
libMenu.popup(world, pos);
|
libMenu.popup(world, pos);
|
||||||
},
|
},
|
||||||
|
@ -2636,21 +2631,19 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
libMenu = new MenuMorph(this, 'Import sound');
|
libMenu = new MenuMorph(this, 'Import sound');
|
||||||
|
|
||||||
function loadSound(name) {
|
function loadSound(name) {
|
||||||
// TODO: Refactor This URL
|
var url = myself.resourceURL('Sounds', name),
|
||||||
var url = 'Sounds/' + name,
|
|
||||||
audio = new Audio();
|
audio = new Audio();
|
||||||
audio.src = url;
|
audio.src = url;
|
||||||
audio.load();
|
audio.load();
|
||||||
myself.droppedAudio(audio, name);
|
myself.droppedAudio(audio, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
names.forEach(function (line) {
|
names.forEach(function (sound) {
|
||||||
if (line.length > 0) {
|
|
||||||
libMenu.addItem(
|
libMenu.addItem(
|
||||||
line,
|
sound.name,
|
||||||
function () {loadSound(line); }
|
function () {loadSound(sound.file); },
|
||||||
|
sound.help
|
||||||
);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
libMenu.popup(world, pos);
|
libMenu.popup(world, pos);
|
||||||
},
|
},
|
||||||
|
@ -2660,31 +2653,24 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
menu.popup(world, pos);
|
menu.popup(world, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Give a path a file in subfolders.
|
||||||
|
// Method can be easily overridden if running in a custom location.
|
||||||
|
IDE_Morph.prototype.resourceURL = function (folder, file) {
|
||||||
|
return folder + '/' + file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a list of files in a directory based on the contents file
|
||||||
IDE_Morph.prototype.getMediaList = function (dirname) {
|
IDE_Morph.prototype.getMediaList = function (dirname) {
|
||||||
// TODO: Fix Variable Names
|
var url, data;
|
||||||
var dir,
|
|
||||||
costumes = [];
|
|
||||||
|
|
||||||
// TODO: have this load the /UPPERCASE name
|
url = this.resourceURL(dirname, dirname.toUpperCase());
|
||||||
dir = this.getURL(dirname);
|
data = this.parseResourceFile(this.getURL(url));
|
||||||
dir.split('\n').forEach(
|
|
||||||
function (line) {
|
|
||||||
var startIdx = line.search(new RegExp('href="[^./?].*"')),
|
|
||||||
endIdx,
|
|
||||||
name;
|
|
||||||
|
|
||||||
if (startIdx > 0) {
|
data.sort(function (x, y) {
|
||||||
name = line.substring(startIdx + 6);
|
return x.name.toLowerCase() < y.name.toLowerCase() ? -1 : 1;
|
||||||
endIdx = name.search(new RegExp('"'));
|
|
||||||
name = name.substring(0, endIdx);
|
|
||||||
costumes.push(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
costumes.sort(function (x, y) {
|
|
||||||
return x < y ? -1 : 1;
|
|
||||||
});
|
});
|
||||||
return costumes;
|
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A Resource File lists all the files that could be loaded in a submenu
|
// A Resource File lists all the files that could be loaded in a submenu
|
||||||
|
@ -2696,7 +2682,7 @@ IDE_Morph.prototype.getMediaList = function (dirname) {
|
||||||
IDE_Morph.prototype.parseResourceFile = function (text) {
|
IDE_Morph.prototype.parseResourceFile = function (text) {
|
||||||
var parts,
|
var parts,
|
||||||
items = [],
|
items = [],
|
||||||
comment = '#',
|
comment = '//',
|
||||||
delimter = '\t';
|
delimter = '\t';
|
||||||
|
|
||||||
text = text.split(/\n|\r\n/);
|
text = text.split(/\n|\r\n/);
|
||||||
|
|
Ładowanie…
Reference in New Issue