Package 'pprules'

Title: Piecepack Game Rules
Description: Functions to generate piecepack game rulesets and books.
Authors: Trevor L Davis [aut, cre]
Maintainer: Trevor L Davis <[email protected]>
License: CC BY-SA 4.0
Version: 0.1.0-1
Built: 2024-11-03 05:06:20 UTC
Source: https://github.com/piecepackr/pprules

Help Index


Game Kit R6 object

Description

game_kit creates a game kit R6 object.

Usage

game_kit(cfgs = NULL)

Arguments

cfgs

A named list of piecepackr::pp_cfg() configuration list objects. If NULL (default) we will use the "piecepack" configuration from piecepackr::game_systems().

Examples

cfg <- piecepackr::game_systems()$dual_piecepacks_expansion
  gk <- game_kit(list(cfg = cfg))
  if (Sys.which("xelatex") != "") {
    output <- tempfile(fileext = ".pdf")
    save_pamphlet("tablut", gk = gk, output = output)
    # xopen::xopen(output)
    # browseURL(output)
  }

Get names of piecepack games we can generate rulesets for.

Description

names_rulesets() returns the names of piecepack games we can generate rulesets for.

Usage

names_rulesets(book = NULL)

Arguments

book

Book name or NULL (for all supported rules). Currently only supports "the historical piecepacker".

See Also

save_ruleset() and save_pamphlet().

Examples

names_rulesets()

Save promo image of game

Description

save_promo_image() saves a promo image of a game. This is usually just a starting diagram for the game but sometimes we may create a custom image.

Usage

save_promo_image(game, gk = game_kit(), file = NULL, ...)

Arguments

game

Game name. Will be normalized by normalize_name().

gk

A game_kit R6 object.

file

Filename for the image. If NULL we'll generate a pdf image with an appropriate name given game.

...

Passed to piecepackr::render_piece().

Details

If we haven't created a custom image for this game then basically we'll convert the game name to snake case, prepend a "piecepack_" in front and then dynGet() a function with that name and use the resulting data frame with piecepackr::render_piece(). See ppdf::games_piecepack() for list of games directly supported by this package.

Value

A list with the width, height, and filename of the promo image. As a side effect we save an image to disk.

Examples

file <- tempfile(fileext = ".pdf")
whf <- save_promo_image("Fuji-san", gk = game_kit(), file = file)
print(whf)
unlink(whf$file)

Save rulebook

Description

save_rulebook saves a rulebook.

Usage

save_rulebook(
  book = "The Historical Piecepacker",
  gk = game_kit(),
  output = NULL,
  quietly = TRUE,
  size = "letter",
  cmd_options = NULL
)

Arguments

book

Book name. Currently only supports "The Historical Piecepacker".

gk

A game_kit R6 object.

output

Path to the output file. If NULL the function will guess a default.

quietly

Whether to hide document compilation output.

size

Paper size (either "letter", or "A4").

cmd_options

Options passed to pandoc when using non-pdf output formats. If NULL we try to guess a good set of options.


Save ruleset

Description

save_ruleset save ruleset of a game. save_pamphlet is a variant that saves the ruleset as a (tri-fold) pamphlet.

Usage

save_ruleset(
  game,
  gk = game_kit(),
  output = NULL,
  quietly = TRUE,
  size = "letter",
  ...,
  game_info = NULL,
  game_files = NULL,
  cmd_options = NULL
)

save_pamphlet(
  game,
  gk = game_kit(),
  output = NULL,
  quietly = TRUE,
  size = "letter",
  duplex_edge = "short",
  ...,
  game_info = NULL,
  game_files = NULL,
  save_promo_fn = save_promo_image
)

Arguments

game

Game name to generate ruleset for. See names_rulesets(). Will be normalized by normalize_name().

gk

A game_kit R6 object.

output

Path to the output file. If NULL the function will guess a default.

quietly

Whether to hide document compilation output.

size

Paper size (either "letter", or "A4").

...

Ignored

game_info

List with game info. If NULL then we use yaml::yaml.load_file(system.file("extdata/game_info.yaml", package = "pprules")).

game_files

Character vector of (full path to) "Rtex" game rules. If NULL then we use list.files(system.file("rules", package = "pprules"), full.names = TRUE).

cmd_options

Options passed to pandoc when using non-pdf output formats. If NULL we try to guess a good set of options.

duplex_edge

String specifying the desired duplex printing edge. If "short" match the second page along its short edge (second page flipped up, easier to preview on computer) and if "long" match along its long edge (second page flipped upside down, usual printer default).

save_promo_fn

A function with arguments game, gk, and file that saves a promo image for game. Defaults to save_promo_image().

Examples

cfg <- piecepackr::game_systems()$dual_piecepacks_expansion
  gk <- game_kit(list(cfg = cfg))
  if (Sys.which("xelatex") != "") {
    output <- tempfile(fileext = ".pdf")
    save_pamphlet("tablut", gk = gk, output = output)
    # xopen::xopen(output)
    # browseURL(output)
  }