package alfredo;

import alfredo.gfx.Renderer;
import alfredo.phx.Physics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.HashMap;

/**
 *
 * @author TheMonsterOfTheDeep
 */
public class Scene {
    private static HashMap<String, Scene> sceneMap;
    private static Scene current = null;
    
    public static void add(Scene s) {
        if(s == null) { return; }
        if(sceneMap == null) {
            sceneMap = new HashMap();
        }
        if(sceneMap.containsKey(s.name)) {
            throw new IllegalStateException("Scene named " + s.name + " already exists!");
        }
        sceneMap.put(s.name, s);
    }
    
    private static void open(Scene s) {
        current = s;
    }
    
    public static void open(String name) {
        if(name == null) { throw new NullPointerException("Scene name cannot be null!"); }
        if(sceneMap == null) { return; }
        Scene next = sceneMap.get(name);
        if(next == null) { throw new IllegalArgumentException("No scene named " + name + " exists!"); }
        open(next);
    }
    
    public static void begin(Scene s) {
        if(s == null) { return; }
        if(current != null) {
            throw new IllegalStateException("Trying to begin with scene " + s.name + ", but a scene is already loaded!");
        }
        add(s);
        open(s);
    }
    
    public static Scene getCurrent() { return current; }
    
    private final String name;
    
    protected Scene(String name) {
        this.name = name;
    }
    
    public final String getName() { return name; }
    
    public void render(Canvas c) {
        c.clear();
        
        Entity[] all = Entity.getAllEntities();
        Renderer r;
        for(Entity e : all) {
            r = e.getComponent(Renderer.class);
            if(r == null) { continue; }
            c.draw(r.graphic, e.position.x, e.position.y);
        }
        
        draw(c);
    }
    
    public void loop() {
        Physics.tick();
    }
    
    public void tick() { }
    public void draw(Canvas c) { }
}

@@ -139,23 +139,116 @@
 va.util.
-HashMap
+ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger
 ;%0A%0A/**%0A 
@@ -305,16 +305,21 @@
 Scene %7B%0A
+    %0A
     priv
@@ -333,24 +333,18 @@
 tic 
-HashMap%3CString, 
+ArrayList%3C
 Scen
@@ -351,19 +351,17 @@
 e%3E scene
-Map
+s
 ;%0A    pr
@@ -422,61 +422,58 @@
 tic 
-void add(Scene s) %7B%0A        if(s == null) %7B return; %7D
+%3CT extends Scene%3E void open(Class%3CT%3E sceneClass) %7B
 %0A   
@@ -477,35 +477,33 @@
         if(scene
-Map
+s
  == null) %7B%0A    
@@ -519,25 +519,25 @@
 cene
-Map
+s
  = new 
-HashMap
+ArrayList
 ();%0A
@@ -558,142 +558,62 @@
     
-if(sceneMap.containsKey(s.name)) %7B%0A            throw new IllegalStateException(%22Scene named %22 + s.name + %22 already exists!%22);%0A
+else %7B%0A            for(Scene s : scenes) %7B%0A   
         
 %7D%0A  
@@ -612,94 +612,58 @@
     
-%7D%0A
      
-   sceneMap.put(s.name, s);%0A    %7D
+if(s.getClass() == sceneClass) %7B
 %0A    
-%0A
     
-private static void open(Scene s) %7B%0A
+    
     
@@ -687,864 +687,401 @@
     
-%7D%0A
     
-%0A
     
-public static void open(String name) %7B%0A        if(name == null) %7B throw new NullPointerException(%22Scene name cannot be null!%22); %7D%0A        if(sceneMap == null) %7B return; %7D%0A        Scene next = sceneMap.get(name);%0A        if(next == null) %7B throw new IllegalArgumentException(%22No scene named %22 + name + %22 exists!%22); %7D%0A        open(next
+        return;%0A                %7D%0A            %7D%0A        %7D%0A        try %7B%0A            current = sceneClass.newInstance(
 );%0A    
-%7D%0A
     
-%0A    public 
+%7D catch (In
 sta
+n
 ti
-c void begin(Scene s) %7B%0A        if(s == null) %7B return; %7D%0A        if(current != null) %7B%0A            throw new IllegalStateException(%22Trying to begin with
+ationException %7C IllegalAccessException ex) %7B%0A            System.out.println(%22Error setting
  scene
+:
  %22 + 
-s.name + %22, but a scene is already loaded!%22);%0A        %7D%0A        add(s);%0A        open(s);%0A    %7D%0A    %0A    public static Scene getCurrent() %7B return current; %7D%0A    %0A    private final String name;%0A    %0A    protected Scene(String name) %7B%0A        this.name = name;%0A    %7D%0A    %0A    public final String getName() %7B return name;
+ex);%0A        %7D%0A        scenes.add(current);%0A    %7D%0A    %0A    public static Scene getCurrent() %7B return current; %7D%0A    %0A    public Scene() %7B
  %7D%0A 

Update scene to use getClass() so its easier