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 IpuzStyle
s 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).
Instance methods
ipuz_puzzle_get_charset_str
Returns the characters that can be entered in the puzzle, in string form.
ipuz_puzzle_get_origin
Returns program-specific information about the program that wrote the puzzle file.
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_version
Returns the version of the ipuz spec that self
conforms to. This
version cannot be changed.
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_explanation
Note: This string can be styled with PangoMarkup. See the Text Handling section for additional information.
ipuz_puzzle_set_origin
Sets program-specific information about the program that wrote the puzzle file.
Properties
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:difficulty
Difficulty of the puzzle. Advisory only, as there is no standard for difficulty.
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()
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
);
}
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.