pp_cfg() and as_pp_cfg() create piecepack configuration list R6 objects. is_pp_cfg() returns TRUE if object is a piecepack configuration list R6 object. as.list() will convert it into a list.

pp_cfg(cfg = list())

is_pp_cfg(cfg)

as_pp_cfg(cfg = list())

Arguments

cfg

List of configuration options

Details

pp_cfg R6 class objects serve the following purposes:

  • Customize the appearance of pieces drawn by grid.piece().

  • Speed up the drawing of graphics through use of caching.

  • Allow the setting and querying of information about the board game components that maybe of use to developers:

    • Number of suits

    • Number of ranks

    • Suit colors

    • Which types of components are included and/or properly supported

    • What would be a good color to use when adding annotations on top of these components.

    • Title, Description, Copyright, and Credit metadata

pp_cfg R6 Class Method Arguments

piece_side

A string with piece and side separated by a underscore e.g. "coin_face".

suit

Number of suit (starting from 1).

rank

Number of rank (starting from 1).

type

Which type of grob to return, either "normal", "picture", or "raster".

pp_cfg R6 Class Methods

get_grob()

Returns a grid “grob” for drawing the piece.

get_piece_opt()

Returns a list with info useful for drawing the piece.

get_suit_color()

Returns the suit colors.

get_width(), get_height(), get_depth()

Dimensions (of the bounding cube) of the piece in inches

pp_cfg R6 Class Fields and Active Bindings

annotation_color

Suggestion of a good color to annotate with

cache

Cache object which stores intermediate graphical calculations. Default is a memory-cache that does not prune. This can be replaced by another cache that implements the cache API used by the cachem package

cache_grob

Whether we should cache (2D) grobs

cache_piece_opt

Whether we should cache piece opt information

cache_op_fn

Whether we should cache the oblique projection functions

cache_obj_fn

Whether we should cache any 3D rendering functions

copyright

Design copyright information

credit

Design credits

description

Design description

fontfamily

Main font family

has_bits

Whether we should assume this supports "bit" pieces

has_boards

Whether we should assume this supports "board" pieces

has_cards

Whether we should assume this supports "card" pieces

has_coins

Whether we should assume this supports "coin" pieces

has_dice

Whether we should assume this supports "die" pieces

has_matchsticks

Whether we should assume this supports "matchstick" pieces

has_pawns

Whether we should assume this supports "pawn" pieces

has_piecepack

Binding which simultaneously checks/sets has_coins, has_tiles, has_pawns, has_dice

has_pyramids

Whether we should assume this supports "pyramid" pieces

has_saucers

Whether we should assume this supports "saucer" pieces

has_tiles

Whether we should assume this supports "tile" pieces

title

Design title

Deprecated pp_cfg R6 Class attributes

cache_shadow

Use cache_op_fn instead

get_pictureGrob()

Use get_grob(..., type = "picture") instead

i_unsuit

Instead add 1L to n_suits

See also

game_systems() for functions that return configuration list objects for several game systems. https://trevorldavis.com/piecepackr/configuration-lists.html for more details about piecepackr configuration lists.

Examples

cfg <- pp_cfg(list(invert_colors=TRUE)) as.list(cfg)
#> $invert_colors #> [1] TRUE #> #> $n_suits #> [1] 4 #> #> $n_ranks #> [1] 6 #> #> $lacks_rank #> [1] "tile_back" "coin_back" "card_back" "pawn_face" "pawn_back" #> [6] "belt_face" "saucer_face" "saucer_back" "suitdie_face" #> #> $lacks_suit #> [1] "tile_back" "saucer_back" "coin_face" "card_back" #>
is_pp_cfg(cfg)
#> [1] TRUE
as_pp_cfg(list(suit_color="darkred,black,darkgreen,darkblue,grey"))
#> $lacks_rank : tile_back,coin_back,card_back,pawn_face,pawn_back,belt_face,saucer_face,saucer_back,suitdie_face #> $lacks_suit : tile_back,saucer_back,coin_face,card_back #> $n_ranks : 6 #> $n_suits : 4 #> $suit_color : darkred,black,darkgreen,darkblue,grey
cfg$get_suit_color(suit=3)
#> [1] "#009E73"
cfg$annotation_color
#> [1] "black"
cfg$has_matchsticks
#> [1] FALSE
cfg$has_matchsticks <- TRUE cfg$has_matchsticks
#> [1] TRUE
cfg$get_width("tile_back")
#> [1] 2
cfg$get_height("die_face")
#> [1] 0.5
cfg$get_depth("coin_face")
#> [1] 0.125
# \donttest{ cfg <- list() system.time(replicate(100, grid.piece("tile_face", 4, 4, cfg)))
#> user system elapsed #> 2.022 0.000 2.023
cfg <- pp_cfg(list()) system.time(replicate(100, grid.piece("tile_face", 4, 4, cfg)))
#> user system elapsed #> 0.375 0.000 0.376
# }