Starts the implementation of the chunk-based pixel storage system for
levels and drawings.
Previously the levels had a Pixels structure which was just an array of
X,Y and palette index triplets. The new chunk system divides the map up
into square chunks, and lets each chunk manage its own memory layout.
The "MapAccessor" layout is implemented first which is a map of X,Y
coordinates to their Swatches (pointer to an index of the palette). When
serialized the MapAccessor maps the "X,Y": "index" similarly to the old
Pixels array.
The object hierarchy for the chunk system is like:
* Chunker: the manager of the chunks who keeps track of the ChunkSize
and a map of "chunk coordinates" to the chunk in charge of it.
* Chunk: a part of the drawing ChunkSize length square. A chunk has a
Type (of how it stores its data, 0 being a map[Point]Swatch and 1
being a [][]Swatch 2D array), and the chunk has an Accessor which
implements the underlying type.
* Accessor: an interface for a Chunk to provide access to its
pixels.
* MapAccessor: a "sparse map" of coordinates to their Swatches.
* GridAccessor: TBD, will be a "dense" 2D grid of Swatches.
The JSON files are loaded in two passes:
1. The chunks only load their swatch indexes from disk.
2. With the palette also loaded, the chunks are "inflated" and linked
to their swatch pointers.
Misc changes:
* The `level.Canvas` UI widget switches from the old Grid data type to
being able to directly use a `level.Chunker`
* The Chunker is a shared data type between the on-disk level format and
the actual renderer (level.Canvas), so saving the level is easy
because you can just pull the Chunker out from the canvas.
* ChunkSize is stored inside the level file and the default value is at
balance/numbers.go: 1000
The `level.Canvas` is a widget that holds onto its Palette and Grid and
has interactions to allow scrolling and editing the grid using the
swatches available on the palette.
Thus all of the logic in the Editor Mode for drawing directly onto the
root SDL surface are now handled inside a level.Canvas instance.
The `level.Canvas` widget has the following properties:
* Like any widget it has an X,Y position and a width/height.
* It has a Scroll position to control which slice of its drawing will be
visible inside its bounding box.
* It supports levels having negative coordinates for their pixels. It
doesn't care. The default Scroll position is (0,0) at the top left
corner of the widget but you can scroll into the negatives and see the
negative pixels.
* Keyboard keys will scroll the viewport inside the canvas.
* The canvas draws only the pixels that are visible inside its bounding
box.
This feature will eventually pave the way toward:
* Doodads being dropped on top of your map, each Doodad being its own
Canvas widget.
* Using drawings as button icons for the user interface, as the Canvas
is a normal widget.
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
* Add ui.Window to easily create reusable windows with titles.
* Add a palette window (panel) to the right edge of the Edit Mode.
* Has Radio Buttons listing the colors available in the palette.
* Add palette support to Edit Mode so when you draw pixels, they take
on the color and attributes of the currently selected Swatch in your
palette.
* Revise the on-disk format to better serialize the Palette object to
JSON.
* Break Play Mode: collision detection fails because the Grid key
elements are now full Pixel objects (which retain their Palette and
Swatch properties).
* The Grid will need to be re-worked to separate X,Y coordinates from
the Pixel metadata to just test "is something there, and what is
it?"