diff --git a/DESCRIPTION b/DESCRIPTION index 4b38265..c7ecd58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Encoding: UTF-8 Package: ppcli Type: Package Title: Plaintext Board Game Visualizations -Version: 0.3.0-1 +Version: 0.3.0-2 Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"), email="trevor.l.davis@gmail.com", comment = c(ORCID = "0000-0001-6341-4639"))) diff --git a/NEWS.md b/NEWS.md index d93f4a2..2cd1668 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ ppcli 0.3.0 (development) ========================= -* `cat_piece()` and `str_piece()` add support for "cubes" bit pieces (#4). +* `cat_piece()` and `str_piece()` adds support for the following game pieces (#4): + + + "cubes" bit pieces + + (piecepack) saucers ppcli 0.2.1 =========== diff --git a/R/str_piece.R b/R/str_piece.R index 232ae1b..b279311 100644 --- a/R/str_piece.R +++ b/R/str_piece.R @@ -194,7 +194,8 @@ get_style_combining <- function(style) { dice_numeral = die_suits ) - list(coin = coin, die = die, pawn = pawn) + saucer <- if (style == "unicode") NULL else "\U000FCE51" + list(coin = coin, die = die, pawn = pawn, saucer = saucer) } get_style_rs <- function(style, big = FALSE) { @@ -572,7 +573,10 @@ add_piece <- function( reorient = "none", style = get_style() ) { - if (piece_side %in% c("tile_back", "coin_face", "card_back", "board_face", "board_back")) { + if ( + piece_side %in% + c("tile_back", "coin_face", "card_back", "board_face", "board_back", "saucer_back") + ) { fg <- "black" } else { if (grepl("pyramid", piece_side)) { @@ -600,7 +604,9 @@ add_piece <- function( "pawn_face", "pawn_back", "board_face", - "board_back" + "board_back", + "saucer_face", + "saucer_back" )) ) { if (piece_side == "tile_face") { @@ -636,6 +642,8 @@ add_piece <- function( piece_side, coin_back = add_coin_back(cm, ss, x, y, angle, fg, style), coin_face = add_coin_face(cm, rs, x, y, angle, fg, style), + saucer_back = add_saucer_back(cm, x, y, angle, fg, style), + saucer_face = add_saucer_face(cm, ss, x, y, angle, fg, style), die_face = add_die_face(cm, rs, x, y, angle, fg, cfg, style, suit), pawn_face = add_pawn_face(cm, ss, x, y, angle, fg, style), pawn_back = add_pawn_back(cm, ss, x, y, angle, fg, style), @@ -784,6 +792,26 @@ add_coin_face <- function(cm, rs, x, y, angle, fg, style) { cm$fg[y, x] <- fg cm } +add_saucer_back <- function(cm, x, y, angle, fg, style) { + if (is.null(style$combining$saucer)) { + cm$char[y, x] <- "\u25ce" + } else { + enclosing_saucer <- style$rotate(style$combining$saucer, angle) + cm$char[y, x] <- paste0(style$space, enclosing_saucer) + } + cm$fg[y, x] <- fg + cm +} +add_saucer_face <- function(cm, ss, x, y, angle, fg, style) { + if (is.null(style$combining$saucer)) { + cm$char[y, x] <- "\u25c9" + } else { + enclosing_saucer <- style$rotate(style$combining$saucer, angle) + cm$char[y, x] <- paste0(ss, enclosing_saucer) + } + cm$fg[y, x] <- fg + cm +} add_die_face <- function(cm, rs, x, y, angle, fg, cfg, style, suit) { enclosing_die <- style$rotate(style$combining$die[[cfg]][suit], angle) # nolint start diff --git a/R/sysdata.rda b/R/sysdata.rda index cfc5433..5505609 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/sysdata.R b/data-raw/sysdata.R index 881141e..e56c51e 100644 --- a/data-raw/sysdata.R +++ b/data-raw/sysdata.R @@ -740,7 +740,7 @@ r225[["\u25b3"]] <- "\u25ff" r270[["\u25b3"]] <- "\u25b7" r315[["\u25b3"]] <- "\u25f9" # Various Symmetric Circles -for (circle in c("\u25cb", "\u25cc", "\u25ce", "\u25cf", "\u20dd")) { +for (circle in c("\u25c9", "\u25cb", "\u25cc", "\u25ce", "\u25cf", "\u20dd")) { r45[[circle]] <- circle r90[[circle]] <- circle r135[[circle]] <- circle @@ -755,6 +755,11 @@ r90[["\U000FCE50"]] <- "\U000FCE5C" # Game Bit PUA r180[["\U000FCE50"]] <- "\U000FCE58" r270[["\U000FCE50"]] <- "\U000FCE54" +# Enclosing Pawn Saucer (with directional mark) +r90[["\U000FCE51"]] <- "\U000FCE5D" # Game Bit PUA +r180[["\U000FCE51"]] <- "\U000FCE59" +r270[["\U000FCE51"]] <- "\U000FCE55" + # Enclosing Pawn r45[["\u20df"]] <- "\u20de" r90[["\u20df"]] <- "\u20df" diff --git a/tests/testthat/_snaps/cat_piece.md b/tests/testthat/_snaps/cat_piece.md index be16ebf..49fe3db 100644 --- a/tests/testthat/_snaps/cat_piece.md +++ b/tests/testthat/_snaps/cat_piece.md @@ -110,6 +110,18 @@ └─┴┸┴─┴┸┘ +--- + + Code + dfs <- tibble(piece_side = rep(c("saucer_face", "saucer_back"), 2), x = 1:4, y = 1, + suit = 1:4) + cat_piece(dfs) + Output + + ◉ ◎ ◉ ◎ + + + --- Code diff --git a/tests/testthat/_snaps/game_bit_mono.md b/tests/testthat/_snaps/game_bit_mono.md index 73f89b2..c5b5535 100644 --- a/tests/testthat/_snaps/game_bit_mono.md +++ b/tests/testthat/_snaps/game_bit_mono.md @@ -19,6 +19,18 @@ │󼨀│ │󼨄│ └─┘ └─┘ +# saucers + + Code + cat_piece(dfs) + Output + + 󼹑 󼹝 󼹙 󼹕 + + 󼰀󼹑 󼰍󼹝 󼰊󼹙 󼰇󼹕 + + + # Can't rotate boards Code diff --git a/tests/testthat/test_cat_piece.R b/tests/testthat/test-cat_piece.R similarity index 97% rename from tests/testthat/test_cat_piece.R rename to tests/testthat/test-cat_piece.R index 3e71470..2a234bd 100644 --- a/tests/testthat/test_cat_piece.R +++ b/tests/testthat/test-cat_piece.R @@ -6,6 +6,8 @@ test_that("text diagrams", { skip_if_not_installed("withr") library("tibble") + expect_warning(capture.output(cat_piece(tibble(piece_side = "token_face", x = 2, y = 2)))) + style <- get_style("unicode") expect_warning(style$rotate("$", 90)) expect_warning(style$rotate("&", 180)) @@ -15,7 +17,6 @@ test_that("text diagrams", { f <- tempfile() expect_equal(cat_piece(tibble(), file = f), character()) unlink(f) - expect_warning(capture.output(cat_piece(tibble(piece_side = "saucer_face", x = 2, y = 2)))) expect_error(cat_piece(tibble( piece_side = "pyramid_top", x = 2, @@ -161,6 +162,17 @@ test_that("text diagrams", { cat_piece(df) }) + # saucers + expect_snapshot({ + dfs <- tibble( + piece_side = rep(c("saucer_face", "saucer_back"), 2), + x = 1:4, + y = 1, + suit = 1:4 + ) + cat_piece(dfs) + }) + # misc expect_snapshot({ dft <- tibble( diff --git a/tests/testthat/test_game_bit_duo.R b/tests/testthat/test-game_bit_duo.R similarity index 100% rename from tests/testthat/test_game_bit_duo.R rename to tests/testthat/test-game_bit_duo.R diff --git a/tests/testthat/test_game_bit_mono.R b/tests/testthat/test-game_bit_mono.R similarity index 73% rename from tests/testthat/test_game_bit_mono.R rename to tests/testthat/test-game_bit_mono.R index b017819..043cff4 100644 --- a/tests/testthat/test_game_bit_mono.R +++ b/tests/testthat/test-game_bit_mono.R @@ -17,6 +17,19 @@ test_that("Dominoes", { expect_snapshot(cat_piece(df)) }) +test_that("saucers", { + skip_if_not_installed("tibble") + library("tibble") + dfs <- tibble( + piece_side = rep(c("saucer_face", "saucer_back"), each = 4), + x = rep(1:4, 2), + y = rep(1:2, each = 4), + angle = rep(c(0, 90, 180, 270), 2), + suit = rep(1:4, 2) + ) + expect_snapshot(cat_piece(dfs)) +}) + # https://github.com/piecepackr/ppcli/issues/3 test_that("Can't rotate boards", { skip_if_not_installed("ppdf", "0.2.0-13") diff --git a/tests/testthat/test_html.R b/tests/testthat/test-html.R similarity index 100% rename from tests/testthat/test_html.R rename to tests/testthat/test-html.R diff --git a/tests/testthat/test_range.R b/tests/testthat/test-range.R similarity index 100% rename from tests/testthat/test_range.R rename to tests/testthat/test-range.R diff --git a/tests/testthat/test_zzz.R b/tests/testthat/test-zzz.R similarity index 100% rename from tests/testthat/test_zzz.R rename to tests/testthat/test-zzz.R