Helpers

This module contains a mishmash of stuff that didn’t fit anywhere else.

quest.helpers.tint(color, ratio=0.25)[source]

Creates a tint of a color by scaling it toward pure white.

Parameters
  • color (int, int, int) – The base color.

  • ratio (float) – A value between 0 and 1. 0 would have no effect; 1 would be pure white.

quest.helpers.shade(color, ratio=0.25)[source]

Creates a shade of a color by scaling it toward pure black.

Parameters
  • color (int, int, int) – The base color.

  • ratio (float) – A value between 0 and 1. 0 would have no effect; 1 would be pure black.

class quest.helpers.Direction[source]

Direction lets you talk about directions like Direction.DOWN, Direction.UPLEFT or using compass directions such as Direction.NE.

is_diagonal()[source]

Returns whether the Direction is diaognal.

>>> Direction.NW.is_diagonal()
True
turn_clockwise()[source]

Returns the direction 90 degrees clockwise. Only supports cardinal directions.

turn_anticlockwise()[source]

Returns the direction 90 degrees anticlockwise. Only supports cardinal directions.

to_vector(normalized=False)[source]

Converts the Direction into an (x, y) tuple.

Arugments:
normalized (bool): Whether to normalize the vector so that its

magintude is 1. Defaults to False, in which case x and y are each either 0 or 1.

class quest.helpers.SpriteListList(sprite_lists)[source]

Allows multiple SpriteLists to be treated as if they were a single SpriteList.

quest.helpers.tileset_to_collection(image_path, tile_size, output_dir, name='tileset', create_tsx=True)[source]

Splits a tileset image into separate files.

Quest relies on Arcade, which only works with collections of images. A lot of game art is provided as a single tile image. This function can help split it out.

Parameters
  • image_path – Path to an image containing a grid of tiles.

  • tile_size – Size in pixels of each tile.

  • output_dir – Directory for output files (there may be a lot of them).

  • name – Name of the tileset.

  • create_tsx – If True, also creates a tsx file which can be opened as a Tileset using Tiled.

class quest.helpers.SimpleInkParser[source]

Parses a simple subset of Ink syntax into a JSON-like data structure.

The ink must meet the following constraints:

  • Must be valid Ink.

  • All content must be in a knot. Knots must be delimited with three equal signs on either side of the knot name.

  • The only syntax allowed is knot declarations, sticky choices (+) and diverts (->). Diverts are only allowed following a sticky choice.

parse(ink)[source]

Reads a story written in a subset of Ink syntax (described above) and returns a data structure of content and choices, also described above.

parse_knot_ink(line_num, ink)[source]

Reads lines of code in a knot and returns a list of content and a dict of options.

split_and_join(strings, condition)[source]

Splits a list of strings on a condition and joins the results. For example,

>>> vowel = lambda l: l in 'aeiou'
>>> split_and_join('abcdefghijklmnop', vowel)
['a', 'bcde', 'fghi', 'jklmno', 'p']
parse_knot_declaration(line)[source]

Returns knot name if found

quest.helpers.resolve_resource_path(filename)[source]

Resolves a resource path for example game resouces (so they can be played from anywhere).