Permalink
Browse files

fixed ScageProperties default to be by-value parameter, fixed tracers…

… params for field_to_(x,y) to be window(Width,Height) by default
  • Loading branch information...
1 parent fec5dfd commit 3a37fac688f5d35404fba6dc95d1019ca807b553 Andrey Borunov committed Apr 5, 2012
@@ -5,8 +5,8 @@ import support._
import support.messages._
trait ScageLib extends ScagePropertiesTrait with ScageMessageTrait with ScageXMLTrait with RendererLib with LWJGLKeyboard with ScageColorTrait with ScageIdTrait {
- def property[A : Manifest](key:String, default:A):A = ScageProperties.property(key, default)
- def property[A : Manifest](key:String, default:A, condition:(A => (Boolean, String))):A = ScageProperties.property(key, default, condition)
+ def property[A : Manifest](key:String, default: => A):A = ScageProperties.property(key, default)
+ def property[A : Manifest](key:String, default: => A, condition:(A => (Boolean, String))):A = ScageProperties.property(key, default, condition)
val max_font_size = ScageMessage.max_font_size
def print(message:Any, x:Float, y:Float, size:Float, color:ScageColor) {ScageMessage.print(message, x, y, size, color)}
@@ -6,13 +6,13 @@ import com.weiglewilczek.slf4s.Logger
import parsers.FormulaParser
trait ScagePropertiesTrait {
- def property[A : Manifest](key:String, default:A):A
+ def property[A : Manifest](key:String, default: => A):A
def stringProperty(key:String) = property(key, "")
def intProperty(key:String) = property(key, 0)
def floatProperty(key:String) = property(key, 0.0f)
def booleanProperty(key:String) = property(key, false)
- def property[A : Manifest](key:String, default:A, condition:(A => (Boolean, String))):A
+ def property[A : Manifest](key:String, default: => A, condition:(A => (Boolean, String))):A
def stringProperty(key:String, condition:(String => (Boolean, String))) = property(key, "", (value:String) => (true, ""))
def intProperty(key:String, condition:(Int => (Boolean, String))) = property(key, 0, (value:Int) => (true, ""))
def floatProperty(key:String, condition:(Float => (Boolean, String))) = property(key, 0.0f, (value:Float) => (true, ""))
@@ -111,7 +111,7 @@ object ScageProperties extends ScagePropertiesTrait {
case _ => p.asInstanceOf[A] // assuming A is String here. If not - we throw exception
}
}
- def property[A : Manifest](key:String, default:A):A = {
+ def property[A : Manifest](key:String, default: => A):A = {
getProperty(key) match {
case Some(p) =>
try {parsedProperty(key, p)}
@@ -124,7 +124,7 @@ object ScageProperties extends ScagePropertiesTrait {
}
}
- def property[A : Manifest](key:String, default:A, condition:(A => (Boolean, String))):A = {
+ def property[A : Manifest](key:String, default: => A, condition:(A => (Boolean, String))):A = {
getProperty(key) match {
case Some(p) =>
try {
@@ -3,15 +3,16 @@ package net.scage.support.tracer3
import net.scage.support.Vec
import net.scage.support.ScageProperties._
import com.weiglewilczek.slf4s.Logger
+import net.scage.handlers.RendererLib
-class CoordTracer[T <: TraceTrait](field_from_x:Int = property("field.from.x", 0),
- field_to_x:Int = property("field.to.x", property("screen.width", 800)),
+class CoordTracer[T <: TraceTrait](field_from_x:Int = property("field.from.x", 0),
+ field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
field_from_y:Int = property("field.from.y", 0),
- field_to_y:Int = property("field.to.y", property("screen.height", 600)),
+ field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
init_h_x:Int = property("field.h_x", 0),
init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 600})/50) else 0,
solid_edges:Boolean = property("field.solid_edges", true))
extends ScageTracer[T](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,init_h_y,init_N_x,init_N_y,solid_edges) {
private val log = Logger(this.getClass.getName);
@@ -118,13 +119,13 @@ extends ScageTracer[T](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,
object CoordTracer {
def apply(field_from_x:Int = property("field.from.x", 0),
- field_to_x:Int = property("field.to.x", property("screen.width", 800)),
+ field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
field_from_y:Int = property("field.from.y", 0),
- field_to_y:Int = property("field.to.y", property("screen.height", 600)),
+ field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
init_h_x:Int = property("field.h_x", 0),
init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 600})/50) else 0,
solid_edges:Boolean = property("field.solid_edges", true)) = {
new CoordTracer[Trace](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,init_h_y,init_N_x,init_N_y,solid_edges) {
def addTrace(coord:Vec):Trace = {addTrace(coord, Trace())}
@@ -133,13 +134,13 @@ object CoordTracer {
// maybe some other name for this factory method (like 'newTracer', etc)
def create[T <: TraceTrait](field_from_x:Int = property("field.from.x", 0),
- field_to_x:Int = property("field.to.x", property("screen.width", 800)),
+ field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
field_from_y:Int = property("field.from.y", 0),
- field_to_y:Int = property("field.to.y", property("screen.height", 600)),
+ field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
init_h_x:Int = property("field.h_x", 0),
init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 600})/50) else 0,
solid_edges:Boolean = property("field.solid_edges", true)) = {
new CoordTracer[T](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,init_h_y,init_N_x,init_N_y,solid_edges)
}
@@ -4,16 +4,17 @@ import net.scage.support.Vec
import net.scage.support.ScageProperties._
import com.weiglewilczek.slf4s.Logger
import collection.mutable.{ArrayBuffer, HashMap}
-
-class ScageTracer[T <: TraceTrait](val field_from_x:Int = property("field.from.x", 0),
- val field_to_x:Int = property("field.to.x", property("screen.width", 800)),
- val field_from_y:Int = property("field.from.y", 0),
- val field_to_y:Int = property("field.to.y", property("screen.height", 600)),
- init_h_x:Int = property("field.h_x", 0),
- init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
- val solid_edges:Boolean = property("field.solid_edges", true)) {
+import net.scage.handlers.RendererLib
+
+class ScageTracer[T <: TraceTrait](val field_from_x:Int = property("field.from.x", 0),
+ val field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
+ val field_from_y:Int = property("field.from.y", 0),
+ val field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
+ init_h_x:Int = property("field.h_x", 0),
+ init_h_y:Int = property("field.h_y", 0),
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 800})/50) else 0,
+ val solid_edges:Boolean = property("field.solid_edges", true)) {
private val log = Logger(this.getClass.getName)
log.debug("creating tracer "+this.getClass.getName)
@@ -221,28 +222,28 @@ class ScageTracer[T <: TraceTrait](val field_from_x:Int = property("field
object ScageTracer {
def apply(field_from_x:Int = property("field.from.x", 0),
- field_to_x:Int = property("field.to.x", property("screen.width", 800)),
+ field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
field_from_y:Int = property("field.from.y", 0),
- field_to_y:Int = property("field.to.y", property("screen.height", 600)),
+ field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
init_h_x:Int = property("field.h_x", 0),
init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 600})/50) else 0,
solid_edges:Boolean = property("field.solid_edges", true)) = {
new ScageTracer[Trace](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,init_h_y,init_N_x,init_N_y,solid_edges) {
def addTrace(point:Vec):Trace = {addTrace(point, Trace())}
}
}
// maybe some other name for this factory method (like 'newTracer', etc)
- def create[T <: TraceTrait](field_from_x:Int = property("field.from.x", 0),
- field_to_x:Int = property("field.to.x", property("screen.width", 800)),
+ def create[T <: TraceTrait](field_from_x:Int = property("field.from.x", 0),
+ field_to_x:Int = property("field.to.x", try {RendererLib.windowWidth} catch {case e:Exception => 800}),
field_from_y:Int = property("field.from.y", 0),
- field_to_y:Int = property("field.to.y", property("screen.height", 600)),
+ field_to_y:Int = property("field.to.y", try {RendererLib.windowHeight} catch {case e:Exception => 600}),
init_h_x:Int = property("field.h_x", 0),
init_h_y:Int = property("field.h_y", 0),
- init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", property("screen.width", 800)/50) else 0,
- init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", property("screen.height", 600)/50) else 0,
+ init_N_x:Int = if(property("field.h_x", 0) == 0) property("field.N_x", (try {RendererLib.windowWidth} catch {case e:Exception => 800})/50) else 0,
+ init_N_y:Int = if(property("field.h_y", 0) == 0) property("field.N_y", (try {RendererLib.windowHeight} catch {case e:Exception => 600})/50) else 0,
solid_edges:Boolean = property("field.solid_edges", true)) = {
new ScageTracer[T](field_from_x,field_to_x,field_from_y,field_to_y,init_h_x,init_h_y,init_N_x,init_N_y,solid_edges)
}

0 comments on commit 3a37fac

Please sign in to comment.