Index: src/game.d ================================================================== --- src/game.d +++ src/game.d @@ -45,15 +45,15 @@ mixin DeriveCreate; mixin DeriveCompare; mixin DeriveShow; Water clone() const { return cast(Water)this; } - static load(string[][string] params) + static load(string[string] params) { return new Water( - params.get("Water", ["0"])[0].to!int(), - params.get("Flooding", ["0"])[0].to!int() + params.get("Water", "0").to!int(), + params.get("Flooding", "0").to!int() ); } int level(int number_of_update) const { @@ -90,11 +90,11 @@ class Map { mixin DeriveShow; - static Map load(string[] raw_data, string[][string] params) + static Map load(string[] raw_data, string[string] params) { // TODO: choose optimal representation. return new Map(raw_data, params); } @@ -110,11 +110,11 @@ this.robot = m.robot.clone(); this.lift = m.lift.clone(); this.waterproof = m.waterproof; } - this(string[] raw_data, string[][string] params) + this(string[] raw_data, string[string] params) { int width = 0; foreach(r; raw_data) width = max(width, r.length); foreach(r; raw_data) { @@ -129,11 +129,11 @@ this.robot = new Pos(y,x); if(this[y,x] == 'L' || this[y,x] == 'O') this.lift = new Pos(y,x); } - this.waterproof = params.get("Waterproof", ["5"])[0].to!int(); + this.waterproof = params.get("Waterproof", "5").to!int(); } const @property { int H() { return data.length; } int W() { return data[0].length; } @@ -275,32 +275,33 @@ { mixin DeriveShow; static Game load(File input) { - string[] raw_data; - string[][string] params; + string[] raw_data; + string[string] params; // Raw map data; read until empty line. for(string line; !(line=input.readln().chomp()).empty; ) raw_data ~= line; // Additional commands; read until EOF. for(string line; !(line=input.readln()).empty; ) { string[] ss = line.split(); - params[ss[0]] = ss[1..$]; + if( ss.length == 2 ) + params[ss[0]] = ss[1]; } return load(raw_data, params); } - static Game load(string[] raw_data, string[][string] params) + static Game load(string[] raw_data, string[string] params) { return new Game(raw_data, params); } - this(string[] raw_data, string[][string] params) + this(string[] raw_data, string[string] params) { this.map = Map.load(raw_data, params); this.water = Water.load(params); }