Class BookUpgrader

java.lang.Object
net.ixdarklord.folios.internal.format.BookUpgrader

public final class BookUpgrader extends Object
Rewrites a book written in an older format into a newer one, a format at a time, as it loads: Folios then only ever reads the current format. Each format's changes are data (/folios/upgrades/<format>.json), the same files the docs site's upgrader tool reads, so the two can't drift apart. A change is one of:
  • "rename": {"old": "new"}: a key takes a new name;
  • "remove": ["key"]: a key goes;
  • "move": {"from": "a.b", "to": "c.d"}: a value moves, dots stepping into objects;
  • "run": "name": one of the few changes that need code, written the same in Java and JavaScript.
with "in" naming which files and objects it applies to: book, category, entry, page (each object of an entry's "pages"), element (each page written as one element, and each object of a page's "elements"), objective (each of a quest's "objectives"), lockable (each category, entry and page, which can be locked) or build, and an optional "where": {"type": "recipe"} to only change objects with those values.

A book already in a format can still hold keys of an older one; check(String, Map, String) names them, from the same changes (those marked "check": false aside, and of the ones that need code only those marked "check": true).

Books are files by their path in the book's folder: book.json, categories/basics.json, entries/basics/first_steps.json, builds/tower.json. Gson only: it also runs outside the game, to check it against the web tool.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    What an upgrade made: the files, rewritten; translations to add to the book's lang file (en_us); and what changed, by file.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String, List<String>>
    check(String book, Map<String, com.google.gson.JsonObject> files, String format)
    What in a book written in format still has the shape of an older format: each change upgrading to it would make, by file.
    static void
    main(String[] args)
    Upgrades every book under a folder to the current format and writes the results to another, as the web tool would: <in> <out>; --check <in> names what in books already in the current format still has an older shape.
    static com.google.gson.JsonObject
    step(String format)
    A format's changes, as the mod carries them.
    upgrade(String book, Map<String, com.google.gson.JsonObject> files, String from, String to)
    Upgrades a book's files from format from to to; the files given are left as they are.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • upgrade

      public static BookUpgrader.Result upgrade(String book, Map<String, com.google.gson.JsonObject> files, String from, String to)
      Upgrades a book's files from format from to to; the files given are left as they are.
      Parameters:
      book - the book's id, namespace:path
    • check

      public static Map<String, List<String>> check(String book, Map<String, com.google.gson.JsonObject> files, String format)
      What in a book written in format still has the shape of an older format: each change upgrading to it would make, by file. Empty when the book is clean. The files given are left as they are.
    • step

      public static com.google.gson.JsonObject step(String format)
      A format's changes, as the mod carries them.
    • main

      public static void main(String[] args) throws IOException
      Upgrades every book under a folder to the current format and writes the results to another, as the web tool would: <in> <out>; --check <in> names what in books already in the current format still has an older shape. Used to check the mod and the web tool agree (tools/check-upgrader).
      Throws:
      IOException