Package jsim.field

Class FieldLoader

java.lang.Object
jsim.field.FieldLoader

public final class FieldLoader extends Object
Loads a JSim field definition from a JSON resource or file, producing a fully-configured FieldSimulator that includes:
  • the correct perimeter walls for the field dimensions declared in the JSON,
  • static obstacle hitboxes (reef structures, scoring targets, etc.), and
  • pre-spawned game pieces at their starting positions.

Bundled season definitions ship with JSim as classpath resources under jsim/field/<name>.json. Load them by name:


 FieldSimulator sim = FieldLoader.fromResource("2025-reefscape");
 

Custom field files can be loaded from disk:


 FieldSimulator sim = FieldLoader.fromFile(Path.of("my-field.json"));
 

JSON schema


 {
   "year": 2025,
   "game": "Reefscape",
   "field": {
     "lengthMeters": 17.548,
     "widthMeters": 8.052
   },
   "obstacles": [
     {
       "name": "ReefBlue",
       "x": 4.49,  "y": 4.03,  "z": 1.00,
       "halfX": 0.85, "halfY": 0.85, "halfZ": 1.00
     }
   ],
   "gamePieces": [
     {
       "variant": "Coral",
       "radius": 0.057,
       "mass": 0.227,
       "friction": 0.5,
       "restitution": 0.3,
       "poses": [
         { "x": 1.15, "y": 0.65, "z": 0.057 }
       ]
     }
   ]
 }
 

Each obstacle becomes a static BoxCollider body in the physics world — robots and game pieces bounce off it but cannot push it. gamePieces become dynamic sphere bodies tracked by FieldSimulator.getGamePiecePoses(String) for AdvantageScope output.

  • Method Details

    • fromResource

      public static FieldSimulator fromResource(String name)
      Load a bundled field definition by short name, e.g. "2025-reefscape". The classpath resource must exist at /jsim/field/<name>.json.
      Parameters:
      name - resource name, without path prefix or .json extension
      Returns:
      a fully configured FieldSimulator
      Throws:
      IllegalArgumentException - if no bundled resource matches name
      RuntimeException - if the resource cannot be read or parsed
    • fromFile

      public static FieldSimulator fromFile(Path jsonPath)
      Load a field definition from a JSON file on disk.
      Parameters:
      jsonPath - path to the .json field definition file
      Returns:
      a fully configured FieldSimulator
      Throws:
      RuntimeException - if the file cannot be read or parsed