Class gamefile

java.lang.Object
name.moore.kevin.ze.game.gamefile

public class gamefile extends Object
A game file is a snapshot of the gameplay and settings that can be saved and reloaded to/from disk.

The class is focused on reading and writing a XML format snapshot of the gamefile. Once parsed it is used populate the runtime entities, components for actual gameplay.

All games run relative to the install directory, files and resources are relative to that location.

<?xml version="1.0" ?><game><starDate>25 Dec 2410</starDate></game>
Author:
Kevin Moore <dev@kevin.moore.name>
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • xstream

      public static com.thoughtworks.xstream.XStream xstream
      Expects a valid XStream instance to be provided by the caller. The xstream instance must register this class as a converter as well.
    • STARTDATE

      private static final starDate STARTDATE
    • stardate

      @XStreamConverter(starDate.class) private starDate stardate
      The current in-gamefile datetime as XML element <stardate>>01 Jun 2456</stardate>>. Required.
    • mapf

      @XStreamConverter(com.thoughtworks.xstream.converters.extended.FileConverter.class) private File mapf
      The filename of the starmap used in this game. The actual map is parsed elsewhere.
    • factions

      private List<faction> factions
      List of the processed <faction> elements, stored as faction objects.
    • ships

      private List<ship> ships
      List of the processed <ship> elements, stored as ship objects.
    • saved

      @XStreamConverter(com.thoughtworks.xstream.converters.time.LocalDateTimeConverter.class) private LocalDateTime saved
      Realworld timestamp of the last save of this gamefile as XML element <saved>>2021-06-14T21:46:58.547886</saved>. Required and defaults to LocalDateTime.now().
    • loadedFrom

      private File loadedFrom
  • Constructor Details

    • gamefile

      public gamefile()
  • Method Details

    • getStardate

      public starDate getStardate()
      Returns:
    • getSaved

      public LocalDateTime getSaved()
      Returns:
    • getMapf

      public File getMapf()
      The filename that was recorded in the gamefile file.
      Returns:
    • getFactions

      public List<faction> getFactions()
      The faction objects loaded from the file.
      Returns:
    • getShips

      public List<ship> getShips()
      Returns:
    • load

      public void load(File gf)
      Create a new game by loading a specified XML file.

      The file is parsed by this class into 'this' and is relative to the working directory.

      Requires a valid XStream object injected.

      Parameters:
      gf -