Skip to content

Interior

Jantoom edited this page Oct 19, 2021 · 1 revision

Introduction

Interiors are expressed in their own JSON files in the room sub-directories of "maps". Adding more JSON files using the custom format below will add more interiors (for that room type) to the sample size used by the random generation algorithm, which will enhance the feeling of randomness.

Technical Explanation

Conceptual design of the Interior class

The purpose of this class is to separate the design of the room from its logic. This is needed because a Room's type, location and size are known at deserialization but its interior design is not.

Since this class is designed to house no complex logic, the variables are injected directly into the Room instance for convenience. This is better than injecting the whole Interior instance because of OOP obfuscation.

Defining an Interior using JSON deserialization

The Interior class implements the Json.Serializable interface to allow for de/serialization of Interior instances.

tileMap

This is an ObjectMap of Characters to GridObjects. Objects in this map define the textures used for the tiles belonging to the room.

entityMap

This is an ObjectMap of Characters to GridObjects. Objects in this map define the entities that will be spawned into the world for the owning room.

tileGrid

This is a Character grid representation of all tiles defined at the Interior level. All Characters specified in the tile map are placed in this grid. If a character not belonging to any key in the tile map is used, then the tile is assumed to be the Floor's defaultInteriorTile at runtime.

entityGrid

This is a Character grid representation of all entities defined at the Interior level. All Character's specified in the entity map are placed in this grid. If a character not belonging to any key in the entity map is used, then no entity is assumed to be there and nothing will be spawned. This grid can change at runtime if a Floor overrides an element on top of this grid in its floor grid.

Typical JSON file format

{
  tileMap: {
    ?: {
      // Custom GridObject serialization
    }
    ...
  }
  entityMap: {
    ?: {
      // Custom GridObject serialization
    }
    ...
  }
  tileGrid: [
    // Default JSON Character grid serialization
  ]
  entityGrid: [
    // Default JSON Character grid serialization
  ]
}

Post-deserialization

This object is typically instantiated in the random generation algorithm of the Room class. When instantiated, its values extracted from deserialization are injected into the Room instance. The room then drops the reference to this Interior so it is subsequently cleaned up by the Java garbage collector.

Clone this wiki locally