Skip to content

Commit

Permalink
Some minor modifications to add better Inventory support
Browse files Browse the repository at this point in the history
  • Loading branch information
cthulhuology committed Jun 14, 2009
1 parent f88804f commit 172f5b1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
12 changes: 8 additions & 4 deletions js/phos.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Array.prototype.has = function(a) {
if (this[i] == a) return true;
return false;
}
Array.prototype.append = function(a) {
a.every(function(v,i) { this.push(v) });
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Object Functions
Expand Down Expand Up @@ -148,7 +151,7 @@ Element.prototype.listen = function(e,f) {
return this;
}
document.onkeypress = function() { return false }; // Hack to break backspace
document.onmousedown = function(e) { e.preventDefault(); return false } // Hack to manage buttons
// document.onmousedown = function(e) { e.preventDefault(); return false } // Hack to manage buttons
document.oncontextmenu = function(e) { return false }; // Hack to remove popup menu

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -163,7 +166,7 @@ Object.prototype.request = function(cb) {
return this._request;
}
Object.prototype.post = function(url,cb) {
var data = (typeof(this) == "string" ) ? this : this.json();
var data = this.toString();
this.request(cb);
this._request.open("POST",url,true);
this._request.setRequestHeader('Content-Type','appliaction/x-www-from-urlencoded');
Expand All @@ -175,7 +178,7 @@ Object.prototype.get = function(url,cb) {
this._request.send("");
};
Object.prototype.download = function() {
document.location.href = "data:application/json," + escape(this.json());
document.location.href = "data:application/json," + escape(this);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -371,7 +374,7 @@ var Screen = let(Box,{
var xm = xo;
var ym = this.y;
var $self = this;
var a = (""+ tx).split(" ");
var a = (""+ tx).split("\n");
a.every(function(x,i) {
var len = Math.floor($self.hack ? $self.ctx.mozMeasureText(x).width:
$self.ctx.measureText(x).width);
Expand Down Expand Up @@ -607,6 +610,7 @@ var Movie = let(Widget,Resource,{
return this;
},
pause: function() { this.data.pause(); return this },
free: function() { _body.removeChild(this.div); }
});

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
29 changes: 27 additions & 2 deletions js/phosphor-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// About
var About = let(Image,{
show: function() { this.at(Display.w - 100,Display.h-40).load('img','images/about_button.png') },
show: function() { this.at(0,Display.h-40).load('img','images/about_button.png') },
down: function(e) {
if (!this.hit(e)) return;
this.blurb = Image.init('images/about.png').at(Display.w/2-150,Display.h/2-150);
Expand All @@ -40,10 +40,35 @@ var Tutorial = let(Text,{
////////////////////////////////////////////////////////////////////////////////////////////////////
// Blog
var Blog = let(Image,{
show: function() { this.at(0,Display.h-40).load('img','images/blog.png') },
show: function() { this.at(100,Display.h-40).load('img','images/blog.png') },
down: function(e) { if (this.hit(e)) _doc.location = 'http://blog.dloh.org' },
});

////////////////////////////////////////////////////////////////////////////////////////////////////
// YouTube Videos
var YouTube = let(Widget,{
init: function(id) {
var y = this.clone().instance();
y.id = id;
y.d = $_('div');
y.d.innerHTML = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/' + y.id + '&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/' + y.id + '&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object>';
y.d.style.position = 'absolute';
y.d.style.top = this.y;
y.d.style.left = this.x;
y.d.style.zIndex = 2;
y.w = y.d.style.width = 425;
y.h = y.d.style.height = 344;
_body.add(y.d);
return y;
},
draw: function() {
this.clamp(0,0,Display.w,Display.h);
this.d.style.top = this.y;
this.d.style.left = this.x;
},
free: function() { _body.removeChild(this.d); }
});

////////////////////////////////////////////////////////////////////////////////////////////////////
// startup function
function startup() {
Expand Down
28 changes: 22 additions & 6 deletions js/phosphor.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var Text = let(Widget,{
},
evaluate: function() {
if (!this.content) return "";
if (this.childof == localStorage) return this.content;
var retval = this.content
Sound.click.play();
try {
Expand All @@ -105,7 +106,15 @@ var Text = let(Widget,{
Phosphor.clipboard = "" + this.content;
this.free(); return;
case "c": Phosphor.clipboard = "" + this.content; return;
case "v": this.content = Phosphor.clipboard; return;
case "v": this.content = this.content + Phosphor.clipboard; return;
case "s":
if (this.childof == localStorage && !this.valueof)
(localStorage[this.content]).post('objects/' + Phosphor.abbr + '-' + this.content,function(txt) {if (!txt) alert('Failed to save try again') });
return;
case "d":
if (this.childof == localStorage && !this.valueof)
(localStorage[this.content]).download();
return;
}
this.content = e.key == Keyboard.enter && this.childof && this.valueof ?
this.childof[this.valueof] = this.evaluate():
Expand Down Expand Up @@ -158,7 +167,7 @@ var Text = let(Widget,{
return ![ $self, Display, Phosphor ].has(v)
&& v.can('hit') && v.hit($self) && v.editing }))) {
if (o.childof && !o.valueof) {
o.childof[o.content.deparameterized()] = this.evaluate();
o.childof[o.content.deparameterized()] = o.childof == localStorage ? this.content : this.evaluate();
this.free();
} else if (!o.childof) {
o.evaluate()[this.content] = true;
Expand Down Expand Up @@ -186,8 +195,10 @@ var Text = let(Widget,{
////////////////////////////////////////////////////////////////////////////////////////////////////
// Phosphor Environment
var Phosphor = let(Widget,{
abbr: localStorage['abbr'] || 'yyz',
clipboard: "",
init: function() {
Sound.trash = Sound.init('sounds/trash.aif');
Sound.error = Sound.init('sounds/error.wav');
Sound.click = Sound.init('sounds/click.wav');
this.at(0,Display.h-64).by(Display.w,64);
Expand Down Expand Up @@ -243,23 +254,28 @@ var Inventory = let(Widget,{
init: function() {
var i = this.clone().instance();
i.button = Image.init('images/inventory_button.png').at(0,10);
i.trash = Image.init('images/trash.png').at(120,10).hide();
i.trash = Image.init('images/trash.png').at(Display.w-64,Display.h-64);
i.trash.up = function(e) {
var o = this.overlaps([Display,this]);
var o = this.overlaps([Display,Phosphor,this]);
if (!o || !o.editing) return;
delete localStorage[o.content];
Sound.trash.play();
delete localStorage[o.content.deparameterized()];
o.free();
};
i.trash.down = false;
i.button.down = function(e) { if (this.hit(e)) Phosphor.inventory.show() };
i.button.up = function(e) {
var o = this.overlaps([Display,this]);
if (!o || !o.editing) return;
localStorage[o.content.deparameterized()] = o.evaluate().json();
localStorage[o.content.deparameterized()] = true;
Phosphor.inventory.show();
o.free();
};
i.at(10,50);
i.get('objects/',function(txt) {
var o = eval('(' + txt + ')');
o.each(function(v,k) { localStorage[k] = unescape(v) });
});
return i;
},
show: function() {
Expand Down

0 comments on commit 172f5b1

Please sign in to comment.