seed r591 - trunk/examples/lightsoff



Author: hortont
Date: Wed Dec 31 03:14:32 2008
New Revision: 591
URL: http://svn.gnome.org/viewvc/seed?rev=591&view=rev

Log:
Still working on lightsoff.


Removed:
   trunk/examples/lightsoff/menu.js
Modified:
   trunk/examples/lightsoff/arrow.js
   trunk/examples/lightsoff/board.js
   trunk/examples/lightsoff/light.js
   trunk/examples/lightsoff/main.js
   trunk/examples/lightsoff/score.js

Modified: trunk/examples/lightsoff/arrow.js
==============================================================================
--- trunk/examples/lightsoff/arrow.js	(original)
+++ trunk/examples/lightsoff/arrow.js	Wed Dec 31 03:14:32 2008
@@ -27,15 +27,15 @@
 	
 			var direction = (flipped ? 1 : -1);
 	
-			if(score.value + direction < 1)
+			if(score.get_value() + direction < 1)
 				return true;
 	
-			score.set_value(score.value + direction);
+			score.set_value(score.get_value() + direction);
 			swap_animation(direction);
 
 			try
 			{
-				gconf_client.set_int("/apps/lightsoff/score", score.value);
+				gconf_client.set_int("/apps/lightsoff/score", score.get_value());
 			}
 			catch(e)
 			{

Modified: trunk/examples/lightsoff/board.js
==============================================================================
--- trunk/examples/lightsoff/board.js	(original)
+++ trunk/examples/lightsoff/board.js	Wed Dec 31 03:14:32 2008
@@ -99,11 +99,11 @@
 	
 	if(light.get_parent().cleared() && !in_setup)
 	{
-		score.set_value(score.value+1);
+		score.set_value(score.get_value()+1);
 
 		try
 		{
-			gconf_client.set_int("/apps/lightsoff/score", score.value);
+			gconf_client.set_int("/apps/lightsoff/score", score.get_value());
 		}
 		catch(e)
 		{
@@ -127,7 +127,7 @@
 	var fadeline = new Clutter.Timeline({num_frames: 20});
 	
 	light.flip(fadeline);
-	
+
 	if(x + 1 < tiles)
 		light.get_parent().lights[x + 1][y].flip(fadeline);
 	if(x - 1 >= 0)
@@ -154,7 +154,7 @@
 		{
 			for(x in this.lights)
 				for(y in this.lights[x])
-					if(this.lights[x][y].state)
+					if(this.lights[x][y].get_state())
 						return false;
 			return true;
 		}
@@ -163,11 +163,11 @@
 		{
 			in_setup = true;
 			
-			GLib.random_set_seed(score.value);
+			GLib.random_set_seed(score.get_value());
 			
 			do
 			{
-				var count = Math.floor(Math.log(score.value*score.value) + 1);
+				var count = Math.floor(Math.log(score.get_value()*score.get_value()) + 1);
 				var sym = Math.floor(3*GLib.random_double());
 
 				for (q = 0; q < count; ++q)

Modified: trunk/examples/lightsoff/light.js
==============================================================================
--- trunk/examples/lightsoff/light.js	(original)
+++ trunk/examples/lightsoff/light.js	Wed Dec 31 03:14:32 2008
@@ -15,16 +15,33 @@
 Light = new GType({
 	parent: Clutter.Group.type,
 	name: "Light",
-	class_init: function(klass, prototype)
+	instance_init: function(klass)
 	{
-		prototype.flip = function (fadeline)
+		// Private
+		var state = false;
+		
+		// Public
+		this.scale_x = this.scale_y = .9;
+		
+		this.on = new Clutter.CloneTexture({parent_texture: on_svg,
+											reactive: true});
+		this.off = new Clutter.CloneTexture({parent_texture: off_svg, 
+											 reactive: true});
+		
+		this.get_state = function ()
+		{
+			return state;
+		}
+		
+		this.flip = function (fadeline)
 		{
-			this.state = !this.state;
-			var new_scale = this.state ? 1 : .9;
+			state = !state;
+			
+			var new_scale = state ? 1 : .9;
 			
 			if(in_setup)
 			{
-				this.on.opacity = this.state * 255;
+				this.on.opacity = state * 255;
 				this.scale_x = this.scale_y = new_scale;
 				
 				return true;
@@ -33,23 +50,13 @@
 			var effect = Clutter.EffectTemplate._new(fadeline,
 													 Clutter.sine_inc_func);
 			
-			Clutter.effect_fade(effect, this.on, this.state * 255);
+			Clutter.effect_fade(effect, this.on, state * 255);
 			Clutter.effect_scale(effect, this, new_scale, new_scale);
 
 			return true;
 		}
-	},
-	instance_init: function(klass)
-	{
-		this.state = false;
-		
-		this.scale_x = this.scale_y = .9;
-		
-		this.on = new Clutter.CloneTexture({parent_texture: on_svg,
-											reactive: true});
-		this.off = new Clutter.CloneTexture({parent_texture: off_svg, 
-											 reactive: true});
 		
+		// Implementation
 		this.on.set_size(tile_size, tile_size);
 		this.off.set_size(tile_size, tile_size);
 		

Modified: trunk/examples/lightsoff/main.js
==============================================================================
--- trunk/examples/lightsoff/main.js	(original)
+++ trunk/examples/lightsoff/main.js	Wed Dec 31 03:14:32 2008
@@ -41,7 +41,7 @@
 Clutter.color_parse("Black", black);
 
 var stage = new Clutter.Stage();
-stage.signal.hide.connect(function(){Clutter.main_quit()});
+stage.signal.hide.connect(function () { Clutter.main_quit(); });
 stage.color = black;
 
 score = new Score();
@@ -63,7 +63,7 @@
 forward.set_position(score.x + score.width + 2*margin, score.y + (.5 * score.height) - (.5 * forward.height));
 
 stage.add_actor(board);
-stage.add_actor(rect); // TODO: gradient at top of rect
+stage.add_actor(rect);
 stage.add_actor(score);
 stage.add_actor(forward);
 stage.add_actor(back);

Modified: trunk/examples/lightsoff/score.js
==============================================================================
--- trunk/examples/lightsoff/score.js	(original)
+++ trunk/examples/lightsoff/score.js	Wed Dec 31 03:14:32 2008
@@ -1,82 +1,87 @@
-ScoreType = {
+var bkg_top = Clutter.Texture.new_from_file("./lcd-front.svg");
+var bkg = Clutter.Texture.new_from_file("./lcd-back.svg");
+
+bkg_top.filter_quality = Clutter.TextureQuality.High;
+bkg.filter_quality = Clutter.TextureQuality.High;
+
+var num_margin = 7;
+
+Score = new GType({
 	parent: Clutter.Group.type,
 	name: "Score",
-	class_init: function(klass, prototype)
+	instance_init: function(klass)
 	{
-		prototype.set_value = function (val)
+		var value = 0;
+		var current_set = null;
+		
+		var num_width = bkg.height * 0.9 * 0.625;
+		var num_height = bkg.height * 0.9;
+		var num_offset = num_width;
+		
+		var num_textures = new Array();
+		
+		var off_svg = Clutter.Texture.new_from_file("./lcd-off.svg");
+		off_svg.filter_quality = Clutter.TextureQuality.High;
+		
+		this.get_value = function ()
+		{
+			return value;
+		};
+		
+		this.set_value = function (val)
 		{
-			this.value = val;
+			value = val;
 			
-			var old_set = this.current_set;
+			var old_set = current_set;
 			
-			this.current_set = new Clutter.Group();
+			current_set = new Clutter.Group();
 
-			var val_s = Seed.sprintf("% 5d",val);
+			var val_s = Seed.sprintf("% 5d", val);
 		
 			for(var i = 0; i < val_s.length; i++)
 			{
-				var texture = this.num_textures[val_s[i]];
+				var texture = num_textures[val_s[i]];
 		
 				if(val_s[i] == ' ')
 					texture = null;
 			
 				var num = new Clutter.CloneTexture({parent_texture:texture});
-				num.set_position(this.num_margin + this.num_offset * i,5);
-				num.set_size(this.num_width,this.num_height);
-				this.current_set.add_actor(num);
+				num.set_position(num_margin + num_offset * i, 5);
+				num.set_size(num_width, num_height);
+				current_set.add_actor(num);
 			}
 			
-			this.add_actor(this.current_set);
+			this.add_actor(current_set);
 			
 			if(old_set)
 				old_set.destroy();
 			
-			this.bkg_top.raise_top();
-		}
-	},
-	instance_init: function(klass)
-	{
-		this.current_set = null;
+			bkg_top.raise_top();
+		};
 		
-		this.bkg_top = Clutter.Texture.new_from_file("./lcd-front.svg");
-		var bkg = Clutter.Texture.new_from_file("./lcd-back.svg");
-		var off_svg = Clutter.Texture.new_from_file("./lcd-off.svg");
-
-		this.bkg_top.filter_quality = Clutter.TextureQuality.High;
-		bkg.filter_quality = Clutter.TextureQuality.High;
-		off_svg.filter_quality = Clutter.TextureQuality.High;
-		
-		this.num_margin = 7;
-		this.num_width = bkg.height * 0.9 * 0.625;
-		this.num_height = bkg.height * 0.9;
-		this.num_offset = this.num_width;
-			
 		this.add_actor(bkg);
 		
 		for(var i = 0; i < 5; i++)
 		{
 			var off_i = new Clutter.CloneTexture({parent_texture:off_svg});
-			off_i.set_position(this.num_margin + this.num_offset * i,5);
-			off_i.set_size(this.num_width,this.num_height);
+			off_i.set_position(num_margin + num_offset * i, 5);
+			off_i.set_size(num_width, num_height);
 			this.add_actor(off_i);
 		}
 		
-		this.num_textures = new Array();
-		
 		for(var i = 0; i <= 9; i++)
 		{
-			this.num_textures[i] = Clutter.Texture.new_from_file("./"+i+".svg");
-			this.num_textures[i].filter_quality = Clutter.TextureQuality.High;
+			num_textures[i] = Clutter.Texture.new_from_file("./"+i+".svg");
+			num_textures[i].filter_quality = Clutter.TextureQuality.High;
 		}
 		
-		this.bkg_top.set_position(1, 1);
-		this.add_actor(this.bkg_top);
+		bkg_top.set_position(1, 1);
+		this.add_actor(bkg_top);
 
 		this.set_value(initial_score);
 		
-		if(this.value == 0)
+		if(value == 0)
 			this.set_value(1);
-	}};
-
-Score = new GType(ScoreType);
+	}
+});
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]