Skip to content

Commit

Permalink
refactor all this crap
Browse files Browse the repository at this point in the history
  • Loading branch information
ncase committed Jul 13, 2017
1 parent 0c610b1 commit eaef2c7
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 55 deletions.
Binary file added assets/ui/button_long.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ui/button_short.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 32 additions & 3 deletions css/slides.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ body{
/******* SLIDESHOW *******/
/*************************/

#slideshow_container{
width:0; height:0;
position:absolute;
margin:auto;
top:0; left:0; right:0; bottom:0;
}
#slideshow{

/*background: #bada55;*/
Expand All @@ -49,8 +55,8 @@ body{

/* Center this thing */
position: absolute;
margin: auto;
top:0; left:0; right:0; bottom:0;
left:-480px;
top:-270px;

}
#slideshow .object{
Expand Down Expand Up @@ -126,7 +132,7 @@ body{
z-index: 100;
}
.button[hover=yes] #background{
background-position: 0px -125px;
background-position: 0px -125px !important;
}
.button[deactivated=yes] #background{
background-position: 0px -250px;
Expand All @@ -137,6 +143,29 @@ body{
.button[deactivated=yes] #hitbox{
display: none;
}
.button[size=short] #background{
background: url(../assets/ui/button_short.png);
background-size: 100%;
width:150px; left:-20px;
}
.button[size=short] #text{
width:105px;
}
.button[size=short] #hitbox{
width:115px;
}
.button[size=long] #background{
background: url(../assets/ui/button_long.png);
background-size: 100%;
width:400px;
}
.button[size=long] #text{
width:330px;
top: 11px;
}
.button[size=long] #hitbox{
width:345px;
}


/*************************/
Expand Down
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
</head>
<body>
<div id="main">
<div id="slideshow"></div>
<div id="scratcher"></div>
<div id="slideshow_container">
<div id="slideshow"></div>
<div id="scratcher"></div>
</div>
</div>
<div id="footer">
<div id="select"></div>
Expand All @@ -19,6 +21,7 @@
<!-- Libraries -->
<script src="js/lib/helpers.js"></script>
<script src="js/lib/pegasus.js"></script>
<script>var c_ = {};</script>
<script src="js/lib/minpubsub.src.js"></script>
<script src="js/lib/q.js"></script>
<script src="js/lib/pixi.min.js"></script>
Expand Down
11 changes: 7 additions & 4 deletions js/core/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Button(config){
button.className = "object";
button.classList.add("fader");
button.classList.add("button");
if(config.size) button.setAttribute("size", config.size);
self.dom = button;

// BG
Expand All @@ -28,10 +29,9 @@ function Button(config){
text.style.fontSize = config.fontSize;
text.style.top = 14+(20-config.fontSize);
}
config.upperCase = (config.upperCase===undefined) ? true : config.upperCase;
self.setText = function(text_id){
var words = Words.get(text_id);
if(config.upperCase) words=words.toUpperCase();
if(config.uppercase) words = words.toUpperCase();
text.innerHTML = words;
};
self.setText(config.text_id);
Expand Down Expand Up @@ -67,8 +67,10 @@ function Button(config){
if(!config.active) self.deactivate();

// Listeners!
subscribe(self.id+"/activate", self.activate);
subscribe(self.id+"/deactivate", self.deactivate);
if(self.id){
listen(self, self.id+"/activate", self.activate);
listen(self, self.id+"/deactivate", self.deactivate);
}

// Add...
self.add = function(INSTANT){
Expand All @@ -77,6 +79,7 @@ function Button(config){

// Remove...
self.remove = function(INSTANT){
unlisten(self);
return _removeFade(self, INSTANT);
};

Expand Down
8 changes: 4 additions & 4 deletions js/core/IncDecNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ function IncDecNumber(config){
///////////////////////////////////////

// Add...
self.add = function(INSTANT){
return _addFade(self, INSTANT);
self.add = function(){
_add(self);
};

// Remove...
self.remove = function(INSTANT){
return _removeFade(self, INSTANT);
self.remove = function(){
_remove(self);
};

}
13 changes: 13 additions & 0 deletions js/core/Scratcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
var Scratcher = {};
exports.Scratcher = Scratcher;

Scratcher.isTransitioning = false;

Scratcher.scratch = function(gotoID){

if(Scratcher.isTransitioning) return;
Scratcher.isTransitioning = true;

var dom = $("#scratcher");
dom.style.display = "block";

var width = $("#main").clientWidth;
var height = $("#main").clientHeight;
dom.style.width = width+"px";
dom.style.height = height+"px";
dom.style.left = -width/2+"px";
dom.style.top = -height/2+"px";

Scratcher.scratchAnim(true)
.then(function(){
if(gotoID){
Expand All @@ -21,6 +33,7 @@ Scratcher.scratch = function(gotoID){
})
.then(function(){
dom.style.display = "none";
Scratcher.isTransitioning = false;
});

};
Expand Down
11 changes: 6 additions & 5 deletions js/core/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Slider(config){
knob.style.left = param*(config.width-30);

};
if(config.message) subscribe(config.message, self.setValue);
if(config.message) listen(self, config.message, self.setValue);

// Mouse events
var _isDragging = false;
Expand Down Expand Up @@ -101,13 +101,14 @@ function Slider(config){
////////////////////////////////////////

// Add...
self.add = function(INSTANT){
return _add(self, INSTANT);
self.add = function(){
_add(self);
};

// Remove...
self.remove = function(INSTANT){
return _remove(self, INSTANT);
self.remove = function(){
unlisten(self);
_remove(self);
};

}
4 changes: 4 additions & 0 deletions js/core/Slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function Slideshow(config){
// Reset: INITIAL VARIABLES
self.reset = function(){

// CLEAR
if(self.clear) self.clear();

// On End?
if(self.currentSlide && self.currentSlide.onend){
self.currentSlide.onend(self);
Expand Down Expand Up @@ -76,6 +79,7 @@ function Slideshow(config){

// Create object
var Classname = window[objectConfig.type];
objectConfig.slideshow = self;
var obj = new Classname(objectConfig);
obj.slideshow = self;

Expand Down
34 changes: 34 additions & 0 deletions js/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var _makeLabel = function(wordID, config){
if(config.align!==undefined) dom.style.textAlign = config.align;
if(config.color!==undefined) dom.style.color = config.color;
if(config.size!==undefined) dom.style.fontSize = config.size;
if(config.width!==undefined) dom.style.width = config.width;

return dom;

Expand All @@ -87,6 +88,39 @@ var _s = function(seconds){

/*******
Hook listeners to an object,
and unsubscribe ALL AT ONCE
*******/

var _listeners = [];
var listen = function(object, message, callback){
var handler = subscribe(message, callback);
_listeners.push({
object: object,
handler: handler
});
};
var unlisten = function(object){
var objectListeners = _listeners.filter(function(l){
return l.object==object;
});
objectListeners.forEach(function(objectListener){
unsubscribe(objectListener.handler); // unsubscribe
_listeners.splice(_listeners.indexOf(objectListener), 1); // but also FORGET it
});
}

var debugListeners = function(){
var count = 0;
for(var sub in c_){
count += c_[sub].length;
}
console.log("there are currently "+count+" listeners!");
};

/*******
Make a Sprite. e.g:
_makeSprite("bg", {width:960});
Expand Down
15 changes: 8 additions & 7 deletions js/sims/Iterated.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ function Iterated(config){
self.dom.appendChild(app.view);

// LABELS
var _l1 = _makeLabel("label_cooperate", {x:349, y:45, rotation:45, align:"center", color:"#333333", size:15});
var _l1 = _makeLabel("label_cooperate", {x:350, y:42, rotation:45, align:"center", color:"#333333", size:15, width:70});
self.dom.appendChild(_l1);
var _l2 = _makeLabel("label_cooperate", {x:277, y:45, rotation:-45, align:"center", color:"#333333", size:15});
var _l2 = _makeLabel("label_cooperate", {x:277, y:43, rotation:-45, align:"center", color:"#333333", size:15, width:70});
self.dom.appendChild(_l2);
var _l3 = _makeLabel("label_cheat", {x:416, y:96, rotation:45, align:"center", color:"#333333", size:15});
var _l3 = _makeLabel("label_cheat", {x:402, y:94, rotation:45, align:"center", color:"#333333", size:15, width:70});
self.dom.appendChild(_l3);
var _l4 = _makeLabel("label_cheat", {x:244, y:95, rotation:-45, align:"center", color:"#333333", size:15});
var _l4 = _makeLabel("label_cheat", {x:229, y:91, rotation:-45, align:"center", color:"#333333", size:15, width:70});
self.dom.appendChild(_l4);

///////////////////////////////////////////////
Expand Down Expand Up @@ -144,17 +144,17 @@ function Iterated(config){

};

subscribe("iterated/cooperate", function(){
listen(self, "iterated/cooperate", function(){
publish("iterated/round/start");
self.playOneRound(PD.COOPERATE);
});

subscribe("iterated/cheat", function(){
listen(self, "iterated/cheat", function(){
publish("iterated/round/start");
self.playOneRound(PD.CHEAT);
});

subscribe("iterated/newOpponent", function(id){
listen(self, "iterated/newOpponent", function(id){
self.chooseOpponent(id);
self.playerA.resetFace();
self.playerB.resetFace();
Expand All @@ -173,6 +173,7 @@ function Iterated(config){
// Remove...
self.remove = function(INSTANT){
app.destroy();
unlisten(self);
return _remove(self);
};

Expand Down
Loading

0 comments on commit eaef2c7

Please sign in to comment.