mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-13 06:29:57 +00:00
use Github gists for sharing
This commit is contained in:
parent
f9c9fc91aa
commit
ec2391f16e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
||||
[submodule "codemirror"]
|
||||
path = codemirror
|
||||
url = git@github.com:sehugg/codemirror
|
||||
[submodule "octokat.js"]
|
||||
path = octokat.js
|
||||
url = ./octokat.js
|
||||
|
@ -283,10 +283,12 @@ canvas.pixelated {
|
||||
<script src="local/williams/defender.js"></script>
|
||||
<script src="local/williams/robotron.js"></script>
|
||||
|
||||
<script src="octokat.js/dist/octokat.js"></script>
|
||||
<script src="src/emu.js"></script>
|
||||
<script src="src/util.js"></script>
|
||||
<script src="src/disasm.js"></script>
|
||||
<script src="src/ui.js"></script>
|
||||
|
||||
<script>
|
||||
showWelcomeMessage();
|
||||
startUI(true);
|
||||
|
1
octokat.js
Submodule
1
octokat.js
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2cba2d91728730ae5d51eb595cf36c7bf9221c5d
|
85
src/ui.js
85
src/ui.js
@ -235,24 +235,24 @@ function _shareFile(e) {
|
||||
alert("Please fix errors before sharing.");
|
||||
return true;
|
||||
}
|
||||
if (!current_preset_id.startsWith("local/")) {
|
||||
alert("Can only share files created with New File.");
|
||||
return true;
|
||||
}
|
||||
var github = new Octokat();
|
||||
var files = {};
|
||||
var text = editor.getValue();
|
||||
console.log("POST",text.length,'bytes');
|
||||
$.post({
|
||||
url: 'share.php',
|
||||
data: {
|
||||
'platform':platform_id,
|
||||
'filename':current_preset_id.split('/').pop(),
|
||||
'text':text,
|
||||
},
|
||||
error: function(e) {
|
||||
console.log(e);
|
||||
alert("Error sharing file.");
|
||||
},
|
||||
success: function(result) {
|
||||
var sharekey = result['key'];
|
||||
var url = "http://8bitworkshop.com/?sharekey=" + sharekey;
|
||||
window.prompt("Copy link to clipboard (Ctrl+C, Enter)", url);
|
||||
}
|
||||
files[current_preset_id.slice(6)] = {"content": text};
|
||||
var gistdata = {
|
||||
"description": '8bitworkshop.com {"platform":"' + platform_id + '"}',
|
||||
"public": true,
|
||||
"files": files
|
||||
};
|
||||
var gist = github.gists.create(gistdata).done(function(val) {
|
||||
var url = "http://8bitworkshop.com/?sharekey=" + val.id;
|
||||
window.prompt("Copy link to clipboard (Ctrl+C, Enter)", url);
|
||||
}).fail(function(err) {
|
||||
alert("Error sharing file: " + err.message);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@ -893,9 +893,13 @@ function preloadWorker(fileid) {
|
||||
if (tool) worker.postMessage({preload:tool});
|
||||
}
|
||||
|
||||
function startPlatform() {
|
||||
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
||||
function initPlatform() {
|
||||
store = new FileStore(localStorage, platform_id + '/');
|
||||
}
|
||||
|
||||
function startPlatform() {
|
||||
initPlatform();
|
||||
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
|
||||
PRESETS = platform.getPresets();
|
||||
if (qs['file']) {
|
||||
// start platform and load file
|
||||
@ -914,22 +918,40 @@ function startPlatform() {
|
||||
}
|
||||
}
|
||||
|
||||
function loadSharedFile(sharekey) {
|
||||
var github = new Octokat();
|
||||
var gist = github.gists(sharekey);
|
||||
gist.fetch().done(function(val) {
|
||||
var filename;
|
||||
for (filename in val.files) { break; }
|
||||
var newid = 'shared/' + filename;
|
||||
var json = JSON.parse(val.description.slice(val.description.indexOf(' ')+1));
|
||||
console.log("Fetched " + newid, json);
|
||||
platform_id = json['platform'];
|
||||
initPlatform();
|
||||
updatePreset(newid, val.files[filename].content);
|
||||
qs['file'] = newid;
|
||||
qs['platform'] = platform_id;
|
||||
delete qs['sharekey'];
|
||||
gotoNewLocation();
|
||||
}).fail(function(err) {
|
||||
alert("Error loading share file: " + err.message);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// start
|
||||
function startUI(loadplatform) {
|
||||
installErrorHandler();
|
||||
// add default platform?
|
||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||
if (!platform_id) {
|
||||
platform_id = qs['platform'] = "vcs";
|
||||
}
|
||||
// parse query string
|
||||
// is this a share URL?
|
||||
if (qs['sharekey']) {
|
||||
var sharekey = qs['sharekey'];
|
||||
console.log("Loading shared file ", sharekey);
|
||||
$.getJSON( ".storage/" + sharekey, function( result ) {
|
||||
console.log(result);
|
||||
var newid = 'shared/' + result['filename'];
|
||||
updatePreset(newid, result['text']);
|
||||
qs['file'] = newid;
|
||||
delete qs['sharekey'];
|
||||
gotoNewLocation();
|
||||
}, 'text');
|
||||
loadSharedFile(qs['sharekey']);
|
||||
} else {
|
||||
// reset file?
|
||||
if (qs['file'] && qs['reset']) {
|
||||
@ -937,11 +959,6 @@ function startUI(loadplatform) {
|
||||
qs['reset'] = '';
|
||||
gotoNewLocation();
|
||||
} else {
|
||||
// add default platform?
|
||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||
if (!platform_id) {
|
||||
platform_id = qs['platform'] = "vcs";
|
||||
}
|
||||
// load and start platform object
|
||||
if (loadplatform) {
|
||||
$.getScript('src/platform/' + platform_id + '.js', function() {
|
||||
|
@ -11,3 +11,5 @@
|
||||
%-48.pbm: %.jpg
|
||||
convert $< -resize 48x192\! -colorspace Gray -dither FloydSteinberg $@
|
||||
|
||||
ship1.pbm: ship1.png
|
||||
convert ship1.png -negate -flop ship1.pbm
|
37
tools/pbm_to_c.py
Normal file
37
tools/pbm_to_c.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys, struct
|
||||
|
||||
# reverse byte
|
||||
def rev(n):
|
||||
return int('{:08b}'.format(n)[::-1], 2)
|
||||
|
||||
# output bits in given range
|
||||
def out(i, pix, lb, hb, reverse=0, shift=0):
|
||||
x = (pix >> lb) & ((1<<(hb-lb))-1)
|
||||
if reverse:
|
||||
x = rev(x)
|
||||
if shift:
|
||||
x = x << shift
|
||||
assert(x>=0 and x<=255)
|
||||
output[i].append(x)
|
||||
|
||||
# read PBM (binary P4 format) file
|
||||
with open(sys.argv[1],'rb') as f:
|
||||
# read PBM header
|
||||
header = f.readline().strip()
|
||||
assert(header == 'P4')
|
||||
dims = f.readline().strip()
|
||||
if dims[0] == '#':
|
||||
dims = f.readline().strip()
|
||||
width,height = map(int, dims.split())
|
||||
wbytes = (width+7)/8
|
||||
data = f.read()
|
||||
print "{%d,%d," % (wbytes,height),
|
||||
for i in range(0,len(data)):
|
||||
if i>0:
|
||||
sys.stdout.write(",")
|
||||
ofs = i+wbytes-(i%wbytes)*2-1
|
||||
sys.stdout.write( "0x%02x" % ord(data[ofs]) )
|
||||
print "}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user