Index: binaries/data/mods/public/maps/random/rmgen/errors/Errors.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/errors/Errors.js @@ -0,0 +1,31 @@ +class RMGENMethodNotImplementedError extends Error +{ + constructor(interface, ...params) + { + super(...params); + this.name = "RMGENMethodNotImplementedError"; + + this.interface = interface; + + this.message = `${this.interface}: ${this.message}`; + } +} + +class RMGENInvalidTextureError extends Error +{ + constructor(file, ...params) + { + super(...params); + this.name = "RMGENInvalidTextureError"; + } +} + +class RMGENInvalidTemplateError extends Error +{ + constructor(file, ...params) + { + super(...params); + this.name = "RMGENInvalidTemplateError"; + } +} + Index: binaries/data/mods/public/maps/random/rmgen/texture/EntityTexture.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/texture/EntityTexture.js @@ -0,0 +1,22 @@ +class EntityTexture extends ITexture +{ + constructor(textureName, templateName) + { + super(); + + if (!textureName || !(textureName instanceof String)) + throw new RMGENInvalidTextureError(); + + if (!templateName || !(templateName instanceof String)) + throw new RMGENInvalidTemplateError(); + + this.textureName = textureName; + this.templateName = templateName; + } + + paint(pos) + { + g_Map.setTerrainEntity(this.templateName, 0, new Vector2D(0.5, 0.5).add(position), randomAngle()); + g_Map.setTexture(pos, this.textureName); + } +} Index: binaries/data/mods/public/maps/random/rmgen/texture/ITexture.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/texture/ITexture.js @@ -0,0 +1,9 @@ +class ITexture +{ + paint(tile) + { + throw new RMGENMethodNotImplementedError(ITexture); + } +} + +// ITexture.textureCache = new Map(); // Only encourages doing pointless things. Index: binaries/data/mods/public/maps/random/rmgen/texture/RandomTexture.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/texture/RandomTexture.js @@ -0,0 +1,17 @@ +class RandomTexture extends ITexture +{ + constructor(textures) + { + super(); + + if (!textures || !(textures instanceof Array) || !textures.every(texture => texture instanceof ITexture)) + throw new RMGENInvalidTextureError(); + + this.textures = textures; + } + + paint(pos) + { + pickRandom(this.textures).place(pos); + } +} Index: binaries/data/mods/public/maps/random/rmgen/texture/SimpleTexture.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/texture/SimpleTexture.js @@ -0,0 +1,17 @@ +class SimpleTexture extends ITexture +{ + constructor(textureName) + { + super(); + + if (!textureName || !(textureName instanceof String)) + throw new RMGENInvalidTextureError(); + + this.textureName = textureName; + } + + paint(pos) + { + g_Map.setTexture(pos, this.textureName); + } +}