Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rule_ideas.rst
html
others
^pkgdown$
raw-data
data-raw
tmp
.*.epub
.*.gif
Expand All @@ -18,6 +18,11 @@ tmp
^.lintr$
^_pkgdown.yml$
^.travis.yml$
^\.air.toml$
^\.editorconfig$
^\.git$
^\.github$
^\.pre-commit-config.yaml$
^Dockerfile$
^\.dockerignore$
^\.claude$
6 changes: 6 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[format]
indent-style = "tab"
indent-width = 4
line-ending = "lf"
line-width = 100
skip = ["tribble"]
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://editorconfig.org/
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{r,R}]
indent_style = tab
11 changes: 10 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -18,6 +19,8 @@ jobs:
fail-fast: false
matrix:
config:
# - {os: macOS-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
Expand All @@ -29,6 +32,9 @@ jobs:
steps:
- uses: actions/checkout@v4

# - if: runner.os == 'macOS'
# run: brew install --cask xquartz

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
Expand All @@ -43,3 +49,6 @@ jobs:
needs: check

- uses: r-lib/actions/check-r-package@v2
# with:
# upload-snapshots: true
# build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
21 changes: 21 additions & 0 deletions .github/workflows/air-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches: [main, master]
pull_request:

name: format-check

permissions: read-all

jobs:
format-check:
name: format-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install
uses: posit-dev/setup-air@v1

- name: Check
run: air format . --check
32 changes: 32 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
NOT_CRAN: true

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: covr

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
codecov.yml
README.html

.claude/
html/
others/
tmp/
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: air
name: Format R code with air
entry: air format
language: system
files: \.R$|\.r$
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Encoding: UTF-8
Package: ppcli
Type: Package
Title: Plaintext Board Game Visualizations
Version: 0.2.1
Version: 0.2.2-1
Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"),
email="trevor.l.davis@gmail.com",
comment = c(ORCID = "0000-0001-6341-4639")))
Expand All @@ -27,5 +27,5 @@ Suggests:
withr
Remotes: piecepackr/ppdf
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.3
Config/testthat/edition: 3
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ppcli 0.2.2 (development)
=========================

* No user-facing changes.

ppcli 0.2.1
===========

Expand Down
37 changes: 27 additions & 10 deletions R/cat_piece.r → R/cat_piece.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,31 @@
#' cat_piece(df)
#' cat_piece(df, annotate = TRUE)
#' @export
cat_piece <- function(df, color = NULL, reorient = "none", annotate = FALSE, ...,
file = "", annotation_scale = NULL,
style = c("Unicode", "Game Bit Mono", "Game Bit Duo"),
xbreaks = NULL, ybreaks = NULL) {
color <- color %||% (is.null(file) || file == "")
s <- str_piece(df, color = color, reorient = reorient, annotate = annotate,
annotation_scale = annotation_scale, style = style,
xbreaks = xbreaks, ybreaks = ybreaks)
if (!is.null(file)) cat(s, ..., file = file)
invisible(s)
cat_piece <- function(
df,
color = NULL,
reorient = "none",
annotate = FALSE,
...,
file = "",
annotation_scale = NULL,
style = c("Unicode", "Game Bit Mono", "Game Bit Duo"),
xbreaks = NULL,
ybreaks = NULL
) {
color <- color %||% (is.null(file) || file == "")
s <- str_piece(
df,
color = color,
reorient = reorient,
annotate = annotate,
annotation_scale = annotation_scale,
style = style,
xbreaks = xbreaks,
ybreaks = ybreaks
)
if (!is.null(file)) {
cat(s, ..., file = file)
}
invisible(s)
}
75 changes: 75 additions & 0 deletions R/range.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
range_heuristic <- function(df) {
if (nrow(df) == 0) {
return(list(xmin = NA_real_, xmax = NA_real_, ymin = NA_real_, ymax = NA_real_))
}
if (!isTRUE(attr(df, "was_cleaned"))) {
df <- clean_df(df)
}

# piecepack
is_tile <- grepl("tile", df$piece_side)
xleft <- ifelse(is_tile, df$x - 1, df$x - 0.5)
xright <- ifelse(is_tile, df$x + 1, df$x + 0.5)
ybot <- ifelse(is_tile, df$y - 1, df$y - 0.5)
ytop <- ifelse(is_tile, df$y + 1, df$y + 0.5)

# subpack
is_subpack <- is_tile & df$cfg == "subpack"
xleft <- ifelse(is_subpack, df$x - 0.5, xleft)
xright <- ifelse(is_subpack, df$x + 0.5, xright)
ybot <- ifelse(is_subpack, df$y - 0.5, ybot)
ytop <- ifelse(is_subpack, df$y + 0.5, ytop)

# dominoes
is_dominoes_horizontal <- is_tile &
grepl("dominoes", df$cfg) &
(df$angle == 90 | df$angle == 270)
ybot <- ifelse(is_dominoes_horizontal, df$y - 0.5, ybot)
ytop <- ifelse(is_dominoes_horizontal, df$y + 0.5, ytop)
is_dominoes_vertical <- is_tile & grepl("dominoes", df$cfg) & (df$angle == 0 | df$angle == 180)
xleft <- ifelse(is_dominoes_vertical, df$x - 0.5, xleft)
xright <- ifelse(is_dominoes_vertical, df$x + 0.5, xright)

# boards
is_board <- grepl("board", df$piece_side)
xleft <- ifelse(is_board, df$x - 0.5 * df$rank, xleft)
xright <- ifelse(is_board, df$x + 0.5 * df$rank, xright)
ybot <- ifelse(is_board, df$y - 0.5 * df$rank, ybot)
ytop <- ifelse(is_board, df$y + 0.5 * df$rank, ytop)

is_board2 <- is_board & grepl("2", df$cfg)
xleft <- ifelse(is_board2, df$x - df$rank, xleft)
xright <- ifelse(is_board2, df$x + df$rank, xright)
ybot <- ifelse(is_board2, df$y - df$rank, ybot)
ytop <- ifelse(is_board2, df$y + df$rank, ytop)

morris_offset <- c(3, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3)[df$rank]
is_morris_board <- is_board & df$cfg == "morris"
xleft <- ifelse(is_morris_board, df$x - morris_offset, xleft)
xright <- ifelse(is_morris_board, df$x + morris_offset, xright)
ybot <- ifelse(is_morris_board, df$y - morris_offset, ybot)
ytop <- ifelse(is_morris_board, df$y + morris_offset, ytop)

# matchsticks
m_offset <- pmax(floor(df$rank / 2) - 1, 0) / 2 # 1:6 -> 0, 0, 0, 0.5, 0.5, 1
is_matchsticks_horizontal <- grepl("matchstick", df$piece_side) &
(df$angle == 90 | df$angle == 270)
xleft <- ifelse(is_matchsticks_horizontal, df$x - m_offset, xleft)
xright <- ifelse(is_matchsticks_horizontal, df$x + m_offset, xright)

is_matchsticks_vertical <- grepl("matchstick", df$piece_side) &
(df$angle == 0 | df$angle == 180)
ybot <- ifelse(is_matchsticks_vertical, df$y - m_offset, ybot)
ytop <- ifelse(is_matchsticks_vertical, df$y + m_offset, ytop)

m_offset_d <- floor(df$rank / 4) # 1:6 -> 0, 0, 0, 1, 1, 1
is_matchsticks_diagonal <- grepl("matchstick", df$piece_side) &
!is_matchsticks_horizontal &
!is_matchsticks_vertical
xleft <- ifelse(is_matchsticks_diagonal, df$x - m_offset_d, xleft)
xright <- ifelse(is_matchsticks_diagonal, df$x + m_offset_d, xright)
ybot <- ifelse(is_matchsticks_diagonal, df$y - m_offset_d, ybot)
ytop <- ifelse(is_matchsticks_diagonal, df$y + m_offset_d, ytop)

list(xmin = min(xleft), xmax = max(xright), ymin = min(ybot), ymax = max(ytop))
}
68 changes: 0 additions & 68 deletions R/range.r

This file was deleted.

Loading
Loading