Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blixt
committed
Mar 15, 2014
1 parent
612dd63
commit 191539c
Showing
10 changed files
with
364 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var ua = require('useragent-wtf'); | ||
|
||
module.exports = function () { | ||
switch (ua.os) { | ||
case 'mac': | ||
$('.mac').show(); | ||
break; | ||
case 'windows': | ||
$('.windows').show(); | ||
break; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = function (starbound) { | ||
var maxTasks = 0, | ||
progress = $('#progress'); | ||
|
||
requestAnimationFrame(function loop() { | ||
var pendingTasks = starbound.assets.api.pendingCalls + | ||
starbound.worlds.api.pendingCalls; | ||
|
||
if (pendingTasks) { | ||
if (maxTasks < pendingTasks) { | ||
maxTasks = pendingTasks; | ||
} | ||
|
||
var percentage = (maxTasks * 1.1 - pendingTasks) / (maxTasks * 1.1) * 100; | ||
progress.css('width', percentage + '%'); | ||
progress.show(); | ||
} else if (maxTasks) { | ||
maxTasks = 0; | ||
progress.css('width', '100%'); | ||
progress.fadeOut(); | ||
} | ||
|
||
requestAnimationFrame(loop); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
var once = require('once'); | ||
|
||
module.exports = function (starbound, callback) { | ||
var directory = document.getElementById('directory'), | ||
file = document.getElementById('file'); | ||
|
||
if (directory.webkitdirectory) { | ||
$('#directory-selector').modal({backdrop: 'static', keyboard: false}); | ||
directory.onchange = function () { | ||
// Verify that a Starbound directory is selected. | ||
var verified = false; | ||
for (var i = 0; i < this.files.length; i++) { | ||
var file = this.files[i]; | ||
if (file.webkitRelativePath == 'Starbound/assets/packed.pak') { | ||
verified = true; | ||
break; | ||
} | ||
} | ||
|
||
var status = $('#directory-status'); | ||
if (verified) { | ||
status.attr('class', 'text-success'); | ||
status.find('span').attr('class', 'glyphicon glyphicon-ok'); | ||
status.find('strong').text('Click Load assets to continue') | ||
$('#load-directory').attr('disabled', false); | ||
} else { | ||
status.attr('class', 'text-danger'); | ||
status.find('span').attr('class', 'glyphicon glyphicon-remove'); | ||
status.find('strong').text('That does not appear to be the Starbound directory') | ||
$('#load-directory').attr('disabled', true); | ||
} | ||
}; | ||
} else { | ||
$('#file-selector').modal({backdrop: 'static', keyboard: false}); | ||
file.onchange = function () { | ||
// Verify that packed.pak is selected. | ||
var status = $('#file-status'); | ||
if (this.files[0].name == 'packed.pak') { | ||
status.attr('class', 'text-success'); | ||
status.find('span').attr('class', 'glyphicon glyphicon-ok'); | ||
status.find('strong').text('Click Load assets to continue') | ||
$('#load-file').attr('disabled', false); | ||
} else { | ||
status.attr('class', 'text-danger'); | ||
status.find('span').attr('class', 'glyphicon glyphicon-remove'); | ||
status.find('strong').text('That does not appear to be the packed.pak file') | ||
$('#load-file').attr('disabled', true); | ||
} | ||
}; | ||
} | ||
|
||
$('#load-directory').click(function () { | ||
var pendingFiles = 0; | ||
|
||
var worldFiles = []; | ||
for (var i = 0; i < directory.files.length; i++) { | ||
var file = directory.files[i], | ||
path = file.webkitRelativePath, | ||
match; | ||
|
||
// Skip hidden files/directories. | ||
if (file.name[0] == '.') continue; | ||
|
||
if (file.name.match(/\.(ship)?world$/)) { | ||
worldFiles.push(file); | ||
} else if (match = path.match(/^Starbound\/(?:assets|mods)(\/.*)/)) { | ||
// Not sure why music files are stored incorrectly like this. | ||
if (match[1].substr(0, 13) == '/music/music/') { | ||
match[1] = match[1].substr(6); | ||
} | ||
|
||
// Add the file and then preload the renderer once all assets have been | ||
// added. | ||
pendingFiles++; | ||
starbound.assets.addFile(match[1], file, once(function (err) { | ||
pendingFiles--; | ||
if (!pendingFiles) { | ||
starbound.renderer.preload(); | ||
callback(null, {worldFiles: worldFiles}); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
$('#directory-selector').modal('hide'); | ||
}); | ||
|
||
$('#load-file').click(function () { | ||
// TODO: Allow adding mods? | ||
starbound.assets.addFile('/', file.files[0], once(function () { | ||
starbound.renderer.preload(); | ||
callback(null, {worldFiles: []}); | ||
})); | ||
|
||
$('#file-selector').modal('hide'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var moment = require('moment'); | ||
|
||
module.exports = function (starbound) { | ||
var addWorlds = document.getElementById('add-world-files'); | ||
addWorlds.onchange = (event) => { | ||
for (var i = 0; i < addWorlds.files.length; i++) { | ||
starbound.worlds.open(addWorlds.files[i]); | ||
} | ||
}; | ||
|
||
var worldList = $('#worlds'); | ||
|
||
var worlds = []; | ||
|
||
worldList.on('click', '.list-group-item', (event) => { | ||
var item = $(event.target).closest('.list-group-item'); | ||
|
||
var index = item.data('index'); | ||
starbound.renderer.setWorld(worlds[index]); | ||
starbound.renderer.requestRender(); | ||
}); | ||
|
||
starbound.renderer.on('load', () => { | ||
worldList.find('.list-group-item').removeClass('active'); | ||
for (var i = 0; i < worlds.length; i++) { | ||
if (worlds[i] == starbound.renderer.world) { | ||
worldList.find('[data-index=' + i + ']').addClass('active'); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
starbound.renderer.on('unload', () => { | ||
worldList.find('.list-group-item').removeClass('active'); | ||
}); | ||
|
||
starbound.worlds.on('load', (event) => { | ||
var world = event.world; | ||
|
||
var index = worlds.length; | ||
worlds.push(world); | ||
|
||
var item = $('<a href="#" class="list-group-item">') | ||
.attr('data-index', index) | ||
.append( | ||
$('<h4 class="list-group-item-heading">').text(world.name), | ||
$('<p class="list-group-item-text">').text('Played ' + moment(world.lastModified).fromNow()) | ||
); | ||
|
||
worldList.append(item); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.