let path = require('path'),
    utils = require('./utils'),
    Region = require('./Region');

module.exports = class World {
    constructor(worldPath) {
        this.worldPath = worldPath;
        this.regionPath = path.join(worldPath, "region");
        this.playerPath = path.join(worldPath, "playerdata");
        this.regions = {};
    }

    getRegion(position) {
        let regionFilename = utils.regionFilenameFromPosition(position);

        if (regionFilename in this.regions === false) {
            let fullpath = path.join(this.regionPath, regionFilename);
            
            this.regions[regionFilename] = Region.fromFile(fullpath, utils.regionXZFromPosition(position));
        }

        return this.regions[regionFilename];
    }
};

let fs = require('fs'),
    path = require('path'),
    utils = require('./utils'),
    Region = require('./Region');

module.exports = class World {
    constructor(worldPath) {
        this.worldPath = worldPath;
        this.regionPath = path.join(worldPath, "region");
        this.playerPath = path.join(worldPath, "playerdata");
        this.regions = {};
    }

    getRegion(position) {
        let regionFilename = utils.regionFilenameFromPosition(position);

        if (regionFilename in this.regions === false) {
            let fullpath = path.join(this.regionPath, regionFilename);
            
            this.regions[regionFilename] = Region.fromFile(fullpath, utils.regionXZFromPosition(position));
        }

        return this.regions[regionFilename];
    }

    getRegions() {
        return fs.readdirSync(this.regionPath)
            .filter(file => /^r\.-?\d+\.-?\d+\.mca$/.test(file))
            .map(file => {
                let fullPath = path.join(this.regionPath, file);
                let parts = file.split(".");
                let x = parseInt(parts[1], 10);
                let z = parseInt(parts[2], 10);

                // TODO: use regions cache
                return Region.fromFile(fullPath, {x: x, z: z});
            });
    }
};

Add ability to return all regions
Add ability to return all regions

This walks the region’s directory and returns a Region instance for each .mca file in that directory.
