Browse Source

BatteryBilder <3

Tom Troppmann 6 years ago
parent
commit
279cda53a3
3 changed files with 15 additions and 27 deletions
  1. 9 16
      src/classes/HolonBattery.java
  2. 0 6
      src/classes/HolonObject.java
  3. 6 5
      src/ui/view/AbstractCanvas.java

+ 9 - 16
src/classes/HolonBattery.java

@@ -138,22 +138,6 @@ public class HolonBattery extends AbstractCpsObject{
 		
 	
 		stateOfChargeLevels[x] = validStateOfCharge(newStateOfCharge);
-		//DEBUG
-		//TODO delete Debug
-		boolean debug = false;
-		if(debug)
-		{
-			System.out.println( "Iterations:" + x);
-			for(int i = 0; i < stateOfChargeLevels.length - 1; i++)
-			{
-				System.out.print( i+":"+stateOfChargeLevels[i]+ ", ");
-				if(i%10 == 0)
-				{
-					System.out.println();
-				}
-			}
-			System.out.println( stateOfChargeLevels.length - 1+":"+stateOfChargeLevels[stateOfChargeLevels.length - 1]);
-		}
 	}
 	public float getStateOfChargeAtTimeStep(int x) {
 		if(iterations != SingletonControl.getInstance().getControl().getModel().getIterations())
@@ -191,4 +175,13 @@ public class HolonBattery extends AbstractCpsObject{
 			return stateOfChargeToValid;
 		}
 	}
+	public String getImageBattery() {
+		//HardCoded Image selection
+		
+		float actualStateOfCharge = getStateOfChargeAtTimeStep(SingletonControl.getInstance().getControl().getModel().getCurIteration() - 1 );
+		int whichOne = (int)(actualStateOfCharge/capacity * 4);
+		String battery = "/Images/battery"+ whichOne + ".png";
+		setImage(battery);
+		return battery;
+	}
 }

+ 0 - 6
src/classes/HolonObject.java

@@ -358,12 +358,6 @@ public class HolonObject extends AbstractCpsObject {
         } else {
             return false;
         }
-        /*
-        float prod = getSelfMadeEnergy(x);
-        float cons =-getMinEnergy(x);
-        //cons = (cons != Float.NEGATIVE_INFINITY)? -cons : 0.f;
-        suppliedPercentage = -(prod + currentSupply)/cons;
-        return (prod  >= cons );*/
     }
     
     /**@param x TimeStep

+ 6 - 5
src/ui/view/AbstractCanvas.java

@@ -378,11 +378,12 @@ public abstract class AbstractCanvas extends JPanel {
                             cps.getPosition().y - controller.getScaleDiv2() - 10);
                 }
             }
-			// draw image
-			File checkPath = new File(cps.getImage());
-			if (checkPath.exists()) {
-				img = new ImageIcon(cps.getImage()).getImage();
-			} else {
+			// set image
+			if(cps instanceof HolonBattery)
+			{
+				img = Util.loadImage(this, ((HolonBattery) cps).getImageBattery());
+			}else
+			{
 				img = Util.loadImage(this, cps.getImage());
 			}
 		}