-
Notifications
You must be signed in to change notification settings - Fork 5
Fonts and Tilesets
Zaffre supports several fonts and tilesets by default. It's extremely easy to add your own.
TTF fonts can be used by instantiating instances of zaffre.font/TTFFont
like so:
(TTFFont. "Consolas" 12)
The first parameter can be either a font name, a font family, or a file path. Some fonts may not exist on all platforms or use the same name so when creating a terminal consider this pattern:
:font (fn [platform]
(case platform
:linux (TTFFont. "Monospaced" 12)
:macosx (TTFFont. "Monaco" 12)
:windows (TTFFont. "Consolas" 12)))
CP437 fontsheets can be loaded from disk or by url like so
(CP437Font. "http://dwarffortresswiki.org/images/b/be/Pastiche_8x8.png" :green 1 true)
The first argument specifies the location, followed by the color channel to use, then a zoom multiplier (1, 2, 3...) and lastly true
or false
depending on whether the font should be rendered with transparency or be completely opaque. If false
is used to then characters drawn with this font will be rendered with their background color.
Tilesets are a way to render sprites and images to the terminal. Keywords can be used to identify individual tiles in the tileset. Additionally each tile may be rendered completely opaque or with transparency.
(def one-bit-map [[:metal :panels :stone :masonry :dark-metal :dark-panels :grass :tree]
[:water-nw :water-n :water-ne :column :parapet :parapet-flag :sign :palm]
[:water-w :water :water-e :fence :gate :dead-tree :tombstone1 :tombstone2]
[:water-sw :water-s :water-se :black :pine-tree :cave :cave-nw :cave-ne]
[:water-f-se :water-f-sw :masonry-top :wall-top :gravel :mountain :cave-sw :cave-se]
[:water-f-se :water-f-nw :window :wall :robot :lever-left :lever-right :key]
[:dark-water :locked-door :open-door :masonry-parapet :window :ladder :stairs-up :stairs-down]
[:cactus :skull :boulder :crate :barrel :chest-closed :chest-open :blank]])
(def one-bit-tileset (TileSet. "http://opengameart.org/sites/default/files/tileset_1bit.png" :green 16 16 0
(map->tile->col-row one-bit-map)
(map->tile->transparent one-bit-map false)))
The parameters to TileSet are as follows
- The path on disk or url of the tileset image
- The color channel to use for transparency
- The width and height in pixels of each tile
- Padding between tiles in pixels. Zero indicates that there is no padding between tiles
- A map of tile-id to [col row] indicating the location of each tile in the image
- A map of tile-id to true/false indicating if the tile should be rendered with transparency
Fonts with matching character/tile dimensions may be combined by using zaffre.font.CompositeFont
. It's best to use at most one character-based font (TTFFont or CP437Font) and one or more TileSets.
(def font (CompositeFont. [(CP437Font. "http://dwarffortresswiki.org/images/b/be/Pastiche_8x8.png" :green 2 true)
(TileSet. "http://opengameart.org/sites/default/files/tileset_1bit.png" :green 16 16 0
(map->tile->col-row one-bit-map)
(map->tile->transparent one-bit-map))]))
Each layer group is assigned a single font so liberal use of composite fonts helps to work around this.