atomicptr / openfl-tiled

openfl-tiled is a library which gives OpenFL developers the ability to use the TILED map editor.
Other
45 stars 21 forks source link

csv import broken (with simple fix) #33

Closed ruby0x1 closed 10 years ago

ruby0x1 commented 10 years ago

I was using a small portion of the TileLayer import code, testing against a csv export from Tiled and I ran into some issues -

I would make a pull request if need be, but it's simple really so!

Before : (wrong) screen shot 2014-01-18 at 8 47 16 pm

After : (expected) screen shot 2014-01-18 at 8 47 45 pm

You can see the printed output here, showing the blanks : screen shot 2014-01-18 at 8 50 59 pm

//before
private static function csvToArray(input:String):Array<Int> {   
    var result:Array<Int> = new Array<Int>();
    var rows:Array<String> = input.split("\n");
    var row:String;
    for (row in rows){
        if (row == "") continue;
        var resultRow:Array<Int> = new Array<Int>();
        var entries:Array<String> = row.split(",");
        var entry:String;
        for (entry in entries)
        result.push(Std.parseInt(entry));                       
    }
    return result;
}
//after
private static function csvToArray(input:String):Array<Int> {   
    var result:Array<Int> = new Array<Int>();
    var rows:Array<String> = StringTools.trim(input).split("\n");
    var row:String;
    for (row in rows){
        if (row == "") continue;
        var resultRow:Array<Int> = new Array<Int>();
        var entries:Array<String> = row.split(",");
        var entry:String;
        for (entry in entries) {
            if(entry != "") {
                result.push(Std.parseInt(entry));
            }
        }
    }
    return result;
}