Class

IpuzPuzzle

Description [src]

class Ipuz.Puzzle : GObject.Object
{
  /* No available fields */
}

IpuzPuzzle is the base class for all puzzles that libipuz supports. It contains the common puzzle metadata that all puzzle kinds share.

The IpuzPuzzle also stores global IpuzStyles that are shared among most puzzle kinds.

Info

We refer to puzzle kinds instead of puzzle types throughout the documentation when talking about puzzles. This is to match the terminology used in the ipuz spec, as well as to avoid confusion with GType and C types.

Using IpuzPuzzle

The IpuzPuzzle API is the expected way to load a new puzzle from data. For example:

gboolean
load_puzzle (const gchar *filename)
{
  g_autoptr (IpuzPuzzle) puzzle = NULL;
  g_autoptr (GError) error = NULL;

  puzzle = ipuz_puzzle_new_from_file (filename, &error);
  if (error != NULL)
    {
      g_critical ("Unable to load %s: %s\n", filename, error->message);
      return FALSE;
    }

  // Do something with the puzzle
  if (ipuz_puzzle_get_puzzle_kind (puzzle) == IPUZ_PUZZLE_CRYPTIC)
    g_print ("Puzzle %s is a cryptic crossword\n", filename);

  return TRUE;
}

It is also possible to create a new puzzle from scratch using g_object_new(). However, a standalone IpuzPuzzle is not supported or meaningful:

crossword = g_object_new (IPUZ_TYPE_CROSSWORD, NULL);

// Do something with the crossword
fill_in_crossword (crossword, my_data);

// Don't do this:
puzzle = g_object_new (IPUZ_TYPE_PUZZLE, NULL);

String handling

The Ipuz spec specifies certain tags are HTML text and not just a plain string. For those values, we sill convert them into PangoMarkup on parsing them so that they can be used by GTK. Those tags must be set as valid PangoMarkup as well.

See the Text Handling section for additional information.

Subclassing

There is currently no way to write a standalone subclass of IpuzPuzzle that can be loaded from disk through ipuz_puzzle_new_from_file(). The parsing code is only internally available to libipuz.

It is possible to inherit classes IpuzGrid and manually set the grid and fields.

If you have written an interesting puzzle type, please consider submiting it to libipuz (or the upstream spec).

Ancestors

Descendants

Constructors

ipuz_puzzle_new_from_data

Returns a newly allocated IpuzPuzzle loaded from data.

ipuz_puzzle_new_from_file

Returns a newly allocated IpuzPuzzle loaded from filename.

ipuz_puzzle_new_from_stream

Returns a newly allocated IpuzPuzzle loaded from stream.

Instance methods

ipuz_puzzle_deep_copy

Makes a full copy of self.

ipuz_puzzle_equal

Compares two puzzles and returns TRUE if they are identical.

ipuz_puzzle_foreach_style

Calls func for each IpuzStyle in self.

ipuz_puzzle_game_won

Returns TRUE if self has been played and is in a winning state.

ipuz_puzzle_get_annotation

Returns a non-displayed annotation.

ipuz_puzzle_get_author

Returns the author of the puzzle.

ipuz_puzzle_get_block

Returns the text value that represents a block in the saved file.

ipuz_puzzle_get_charset

Returns the characters that can be entered in the puzzle.

ipuz_puzzle_get_charset_str

Returns the characters that can be entered in the puzzle, in string form.

ipuz_puzzle_get_copyright

Returns the copyright information for self.

ipuz_puzzle_get_date

Returns the date of the puzzle or the publication date.

ipuz_puzzle_get_difficulty

Returns the difficulty of the puzzle.

ipuz_puzzle_get_editor

Returns the editor of the puzzle.

ipuz_puzzle_get_empty

Returns the text value that represents an empty cell.

ipuz_puzzle_get_explanation

Returns the text to be displayed after a successful solve.

ipuz_puzzle_get_flags

Indicates static properties about the puzzle determined at load time.

ipuz_puzzle_get_intro

Returns the text to be displayed above the puzzle.

ipuz_puzzle_get_license

Returns the license of the puzzle.

ipuz_puzzle_get_locale

Returns the locale of the puzzle.

ipuz_puzzle_get_notes

Returns the notes about the puzzle.

ipuz_puzzle_get_origin

Returns program-specific information about the program that wrote the puzzle file.

ipuz_puzzle_get_publication

Returns the bibliographic reference for a published puzzle.

ipuz_puzzle_get_publisher

Returns the name and/or reference for a publisher.

ipuz_puzzle_get_puzzle_info

Calculates information about the current state of self. This information is not kept in sync, so if there are any changes to self then the puzzle info will have to be recalculated.

ipuz_puzzle_get_puzzle_kind

Returns the type of puzzle that self is.

ipuz_puzzle_get_style

Returns one of the puzzle’s styles by name.

ipuz_puzzle_get_title

Returns the title of self.

ipuz_puzzle_get_uniqueid

Returns a globally unique identifier for self.

ipuz_puzzle_get_url

Returns the permanent URL for the puzzle.

ipuz_puzzle_get_version

Returns the version of the ipuz spec that self conforms to. This version cannot be changed.

ipuz_puzzle_save_to_data

Returns a newly allocated string dontaining self as an ipuz file.

ipuz_puzzle_save_to_file

Writes self to filename as an ipuz file, overwriting the current contents.

ipuz_puzzle_save_to_stream

Writes self to stream as an ipuz file. This operation is synchronous.

ipuz_puzzle_set_annotation

Sets a non-displayed annotation.

ipuz_puzzle_set_author

Sets the author of the puzzle.

ipuz_puzzle_set_block

Sets the text value that represents a block.

ipuz_puzzle_set_charset

Sets the characters that can be entered in the puzzle. Setting this explicitly will override the charset defined by IpuzPuzzle:locale.

ipuz_puzzle_set_charset_str

Sets the characters that can be entered in the puzzle, in string form. Setting this explicitly will override the charset defined by IpuzPuzzle:locale.

ipuz_puzzle_set_copyright

Sets the copyright information for self.

ipuz_puzzle_set_date

Sets the date of the puzzle or the publication date.

ipuz_puzzle_set_difficulty

Returns the difficulty of the puzzle.

ipuz_puzzle_set_editor

Sets the editor of the puzzle.

ipuz_puzzle_set_empty

Sets the text value that represents an empty cell.

ipuz_puzzle_set_explanation

Note: This string can be styled with PangoMarkup. See the Text Handling section for additional information.

ipuz_puzzle_set_intro

Sets the text to be displayed above puzzle.

ipuz_puzzle_set_license

Sets the license of the puzzle.

ipuz_puzzle_set_locale

Sets the locale of the puzzle.

ipuz_puzzle_set_notes

Sets the notes about the puzzle.

ipuz_puzzle_set_origin

Sets program-specific information about the program that wrote the puzzle file.

ipuz_puzzle_set_publication

Set the bibliographic reference for a published puzzle.

ipuz_puzzle_set_publisher

Set the name and/or reference for a publisher.

ipuz_puzzle_set_style
No description available.

ipuz_puzzle_set_title

Sets the title of self.

ipuz_puzzle_set_uniqueid

Sets the globally unique identifier for self.

ipuz_puzzle_set_url

Sets the permanent URL for the puzzle.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

Ipuz.Puzzle:annotation

Non-displayed annotation.

Ipuz.Puzzle:author

Author of the puzzle.

Ipuz.Puzzle:block

The text value that represents a block in the saved file.

Ipuz.Puzzle:charset

Characters that can be entered in the puzzle. Setting this explicitly will override the charset defined by IpuzPuzzle:locale.

Ipuz.Puzzle:charset-str

Characters that can be entered in the puzzle, in string form. Setting this explicitly will override the charset defined by IpuzPuzzle:locale.

Ipuz.Puzzle:copyright

Copyright information for the puzzle.

Ipuz.Puzzle:date

Date of puzzle or publication date.

Ipuz.Puzzle:difficulty

Difficulty of the puzzle. Advisory only, as there is no standard for difficulty.

Ipuz.Puzzle:editor

Editor of the puzzle.

Ipuz.Puzzle:empty

Text value that represents an empty cell.

Ipuz.Puzzle:explanation

Text to be displayed after a successful solve.

Ipuz.Puzzle:intro

Text displayed above the puzzle.

Ipuz.Puzzle:license

License of the puzzle.

Ipuz.Puzzle:locale

Locale of the puzzle.

Ipuz.Puzzle:notes

Notes about the puzzle.

Ipuz.Puzzle:origin

Program-specific information about the program that wrote the puzzle file.

Ipuz.Puzzle:publication

Bibliographic reference for a published puzzle.

Ipuz.Puzzle:publisher

Name and/or reference for a publisher.

Ipuz.Puzzle:puzzle-kind

The kind type of the puzzle.

Ipuz.Puzzle:styles

A GHash table containing all the named styles for the puzzle. These can be added or removed by calling ipuz_puzzle_set_style()

Ipuz.Puzzle:title

Title of the puzzle.

Ipuz.Puzzle:uniqueid

Globally unique identifier for the puzzle.

Ipuz.Puzzle:url

Permanent URL for the puzzle.

Ipuz.Puzzle:version

Version of the ipuz spec used for the puzzle.

Signals

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct IpuzPuzzleClass {
  void (* load_node) (
    IpuzPuzzle* self,
    const char* member_name,
    JsonNode* node
  );
  void (* post_load_node) (
    IpuzPuzzle* self,
    const char* member_name,
    JsonNode* node
  );
  void (* fixup) (
    IpuzPuzzle* self
  );
  void (* validate) (
    IpuzPuzzle* self
  );
  gboolean (* equal) (
    IpuzPuzzle* puzzle1,
    IpuzPuzzle* puzzle2
  );
  void (* build) (
    IpuzPuzzle* self,
    JsonBuilder* builder
  );
  IpuzPuzzleFlags (* get_flags) (
    IpuzPuzzle* self
  );
  void (* clone) (
    IpuzPuzzle* src,
    IpuzPuzzle* dest
  );
  const char* const* (* get_kind_str) (
    IpuzPuzzle* self
  );
  void (* set_style) (
    IpuzPuzzle* self,
    const char* style_name,
    IpuzStyle* style
  );
  void (* calculate_info) (
    IpuzPuzzle* self,
    IpuzPuzzleInfo* info
  );
  gboolean (* game_won) (
    IpuzPuzzle* self
  );
  
}
No description available.
Class members
load_node: void (* load_node) ( IpuzPuzzle* self, const char* member_name, JsonNode* node )
No description available.
post_load_node: void (* post_load_node) ( IpuzPuzzle* self, const char* member_name, JsonNode* node )
No description available.
fixup: void (* fixup) ( IpuzPuzzle* self )
No description available.
validate: void (* validate) ( IpuzPuzzle* self )
No description available.
equal: gboolean (* equal) ( IpuzPuzzle* puzzle1, IpuzPuzzle* puzzle2 )
No description available.
build: void (* build) ( IpuzPuzzle* self, JsonBuilder* builder )
No description available.
get_flags: IpuzPuzzleFlags (* get_flags) ( IpuzPuzzle* self )
No description available.
clone: void (* clone) ( IpuzPuzzle* src, IpuzPuzzle* dest )
No description available.
get_kind_str: const char* const* (* get_kind_str) ( IpuzPuzzle* self )
No description available.
set_style: void (* set_style) ( IpuzPuzzle* self, const char* style_name, IpuzStyle* style )
No description available.
calculate_info: void (* calculate_info) ( IpuzPuzzle* self, IpuzPuzzleInfo* info )
No description available.
game_won: gboolean (* game_won) ( IpuzPuzzle* self )
No description available.

Virtual methods

Ipuz.PuzzleClass.build
No description available.

Ipuz.PuzzleClass.calculate_info
No description available.

Ipuz.PuzzleClass.clone
No description available.

Ipuz.PuzzleClass.equal

Compares two puzzles and returns TRUE if they are identical.

Ipuz.PuzzleClass.fixup
No description available.

Ipuz.PuzzleClass.game_won

Returns TRUE if self has been played and is in a winning state.

Ipuz.PuzzleClass.get_flags

Indicates static properties about the puzzle determined at load time.

Ipuz.PuzzleClass.get_kind_str
No description available.

Ipuz.PuzzleClass.load_node
No description available.

Ipuz.PuzzleClass.post_load_node
No description available.

Ipuz.PuzzleClass.set_style
No description available.

Ipuz.PuzzleClass.validate
No description available.