seed r631 - trunk/examples/lightsoff



Author: hortont
Date: Sat Jan  3 14:01:39 2009
New Revision: 631
URL: http://svn.gnome.org/viewvc/seed?rev=631&view=rev

Log:
Big Lights Off cleanup.


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	Sat Jan  3 14:01:39 2009
@@ -3,48 +3,33 @@
 	name: "Arrow",
 	instance_init: function(klass)
 	{
-		var flipped = 0;
-		
-		this.set_arrow_direction = function (dir)
-		{
-			var bkg;
-			flipped = dir;
-
-			if(dir)
-				bkg = Clutter.Texture.new_from_file("./arrow-r.svg");
-			else
-				bkg = Clutter.Texture.new_from_file("./arrow-l.svg");
-			
-			bkg.filter_quality = Clutter.TextureQuality.High;
-			this.add_actor(bkg);
-			bkg.show();
-		}
+		// Private
+		var direction = 0;
 		
 		var toggle_arrow = function (actor, event)
 		{
 			if(animating_board)
 				return true;
-	
-			var direction = (flipped ? 1 : -1);
-	
-			if(score.get_value() + direction < 1)
-				return true;
-	
-			score.set_value(score.get_value() + direction);
-			swap_animation(direction);
 
-			try
-			{
-				gconf_client.set_int("/apps/lightsoff/score", score.get_value());
-			}
-			catch(e)
-			{
-				Seed.print("Couldn't save score to GConf.");
-			}
+			if(score.set_value(score.get_value() + direction))
+				swap_animation(direction);
 	
 			return true;
 		}
+		
+		// Public
+		this.set_arrow_direction = function (dir)
+		{
+			direction = dir ? 1 : -1;
+			
+			var bkg = Clutter.Texture.new_from_file("./arrow-" + 
+													(dir ? "r" : "l") + ".svg");
+			
+			bkg.filter_quality = Clutter.TextureQuality.High;
+			this.add_actor(bkg);
+		}
 
+		// Implementation
 		this.reactive = true;
 		this.signal.button_press_event.connect(toggle_arrow);
 	}

Modified: trunk/examples/lightsoff/board.js
==============================================================================
--- trunk/examples/lightsoff/board.js	(original)
+++ trunk/examples/lightsoff/board.js	Sat Jan  3 14:01:39 2009
@@ -60,7 +60,6 @@
 	
 	remove_timeline.signal.completed.connect(delete_board, board);
 	animating_board = true;
-	fadeline.start();
 	
 	board = new_board;
 }
@@ -79,13 +78,12 @@
 	var effect = Clutter.EffectTemplate._new(fadeline, Clutter.sine_inc_func);
 	
 	Clutter.effect_depth(effect, new_board, 0);
-	var remove_timeline = Clutter.effect_depth(effect, board, direction * 250);
+	Clutter.effect_depth(effect, board, direction * 250);
 	Clutter.effect_fade(effect, new_board, 255);
-	Clutter.effect_fade(effect, board, 0);
+	var remove_timeline = Clutter.effect_fade(effect, board, 0);
 	
 	remove_timeline.signal.completed.connect(delete_board, board);	
 	animating_board = true;
-	fadeline.start();
 	
 	board = new_board;
 }
@@ -94,22 +92,9 @@
 {
 	in_fade = false;
 	
-	if(animating_board)
-		return true;
-	
-	if(light.get_parent().cleared() && !in_setup)
+	if(light.get_parent().cleared() && !in_setup && !animating_board)
 	{
-		score.set_value(score.get_value()+1);
-
-		try
-		{
-			gconf_client.set_int("/apps/lightsoff/score", score.get_value());
-		}
-		catch(e)
-		{
-			Seed.print("Couldn't save score to GConf.");
-		}
-
+		score.set_value(score.get_value() + 1);
 		win_animation();
 	}
 }
@@ -119,27 +104,34 @@
 	if(!in_setup && in_fade)
 		return true;
 	
-	var x = light.light_x;
-	var y = light.light_y;
+	var x = light.get_light_x();
+	var y = light.get_light_y();
 	
 	var fadeline = new Clutter.Timeline({num_frames: 20});
 	
+	in_fade = true;
+	
 	light.flip(fadeline);
 	
-	var lights = light.get_parent().get_lights();
+	try
+	{
+		var lights = light.get_parent().get_lights();
 
-	if(x + 1 < tiles)
-		lights[x + 1][y].flip(fadeline);
-	if(x - 1 >= 0)
-		lights[x - 1][y].flip(fadeline);
-	if(y + 1 < tiles)
-		lights[x][y + 1].flip(fadeline);
-	if(y - 1 >= 0)
-		lights[x][y - 1].flip(fadeline);
+		if(x + 1 < tiles)
+			lights[x + 1][y].flip(fadeline);
+		if(x - 1 >= 0)
+			lights[x - 1][y].flip(fadeline);
+		if(y + 1 < tiles)
+			lights[x][y + 1].flip(fadeline);
+		if(y - 1 >= 0)
+			lights[x][y - 1].flip(fadeline);
+	}
+	catch(e)
+	{
+		// User clicked too fast!
+	}
 	
 	fadeline.start();
-	in_fade = true;
-	
 	fadeline.signal.completed.connect(check_won, light);
 	
 	return true;
@@ -216,8 +208,10 @@
 			{
 				var offset = margin + tile_size/2;
 				lights[x][y] = new Light();
-				lights[x][y].light_x = x;
-				lights[x][y].light_y = y;
+				
+				lights[x][y].set_light_x(x);
+				lights[x][y].set_light_y(y);
+				
 				lights[x][y].set_position(x * (tile_size+margin) + offset,
 										  y * (tile_size+margin) + offset);
 				this.add_actor(lights[x][y]);

Modified: trunk/examples/lightsoff/light.js
==============================================================================
--- trunk/examples/lightsoff/light.js	(original)
+++ trunk/examples/lightsoff/light.js	Sat Jan  3 14:01:39 2009
@@ -1,4 +1,4 @@
-var tile_svg_size = 200;
+var tile_svg_size = 100;
 
 var on_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("./light-on.svg",
 													   tile_svg_size,
@@ -19,12 +19,14 @@
 	{
 		// Private
 		var state = false;
+		var light_x, light_y;
 		
 		// Public
 		this.scale_x = this.scale_y = .9;
 		
 		this.on = new Clutter.CloneTexture({parent_texture: on_svg,
-											reactive: true});
+											reactive: true,
+											opacity: 0});
 		this.off = new Clutter.CloneTexture({parent_texture: off_svg, 
 											 reactive: true});
 		
@@ -44,7 +46,7 @@
 				this.on.opacity = state * 255;
 				this.scale_x = this.scale_y = new_scale;
 				
-				return true;
+				return;
 			}
 			
 			var effect = Clutter.EffectTemplate._new(fadeline,
@@ -52,16 +54,32 @@
 			
 			Clutter.effect_fade(effect, this.on, state * 255);
 			Clutter.effect_scale(effect, this, new_scale, new_scale);
-
-			return true;
+		}
+		
+		this.set_light_x = function (new_x)
+		{
+			light_x = new_x;
+		}
+		
+		this.set_light_y = function (new_y)
+		{
+			light_y = new_y;
+		}
+		
+		this.get_light_x = function ()
+		{
+			return light_x;
+		}
+		
+		this.get_light_y = function ()
+		{
+			return light_y;
 		}
 		
 		// Implementation
 		this.on.set_size(tile_size, tile_size);
 		this.off.set_size(tile_size, tile_size);
 		
-		this.on.opacity = 0.0;
-		
 		this.set_anchor_point(tile_size / 2, tile_size / 2);
 
 		this.on.signal.button_press_event.connect(flip_region, this);

Modified: trunk/examples/lightsoff/main.js
==============================================================================
--- trunk/examples/lightsoff/main.js	(original)
+++ trunk/examples/lightsoff/main.js	Sat Jan  3 14:01:39 2009
@@ -23,20 +23,6 @@
 Seed.include("board.js");
 Seed.include("arrow.js");
 
-var gconf_client;
-var initial_score;
-
-try
-{
-	gconf_client = GConf.Client.get_default();
-	initial_score = gconf_client.get_int("/apps/lightsoff/score")
-}
-catch(e)
-{
-	initial_score = 1;
-	Seed.print("Couldn't load score from GConf.");
-}
-
 var black = Clutter.Color._new();
 Clutter.color_parse("Black", black);
 

Modified: trunk/examples/lightsoff/score.js
==============================================================================
--- trunk/examples/lightsoff/score.js	(original)
+++ trunk/examples/lightsoff/score.js	Sat Jan  3 14:01:39 2009
@@ -1,8 +1,7 @@
 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;
+bkg_top.filter_quality = bkg.filter_quality = Clutter.TextureQuality.High;
 
 var num_margin = 7;
 
@@ -32,8 +31,20 @@
 		
 		this.set_value = function (val)
 		{
+			if(val < 1)
+				return false;
+			
 			value = val;
 			
+			try
+			{
+				gconf_client.set_int("/apps/lightsoff/score", value);
+			}
+			catch(e)
+			{
+				Seed.print("Couldn't save score to GConf.");
+			}
+			
 			var old_set = current_set;
 			
 			current_set = new Clutter.Group();
@@ -61,11 +72,12 @@
 				old_set.destroy();
 			
 			bkg_top.raise_top();
+			
+			return true;
 		};
 		
 		// Implementation
 		this.add_actor(bkg);
-		bkg.show();
 		
 		for(var i = 0; i < 5; i++)
 		{
@@ -73,7 +85,6 @@
 			off_i.set_position(num_margin + num_offset * i, 5);
 			off_i.set_size(num_width, num_height);
 			this.add_actor(off_i);
-			off_i.show();
 		}
 		
 		for(var i = 0; i <= 9; i++)
@@ -84,12 +95,17 @@
 		
 		bkg_top.set_position(1, 1);
 		this.add_actor(bkg_top);
-		bkg_top.show();
-
-		this.set_value(initial_score);
 		
-		if(value == 0)
+		try
+		{
+			gconf_client = GConf.Client.get_default();
+			this.set_value(gconf_client.get_int("/apps/lightsoff/score"));
+		}
+		catch(e)
+		{
+			Seed.print("Couldn't load score from GConf.");
 			this.set_value(1);
+		}
 	}
 });
 



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