Created
May 3, 2022 00:40
-
-
Save elipousson/999e53562c37d074ecd38eb2620ef01b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
library(ragg) | |
library(systemfonts) | |
# NOTE: The url is not included because it contained copyright protected text from this game https://sniperserpent.itch.io/oupost-alpha | |
# url <- "https://docs.google.com/spreadsheets" | |
# Thing 1 ---- | |
cards_init <- | |
googlesheets4::read_sheet(url) | |
## ├︎ Thing 2 ---- | |
cards <- cards_init %>% | |
janitor::clean_names("snake") %>% | |
dplyr::mutate( | |
# id = dplyr::row_number(), | |
card = as.character(card), | |
suit = dplyr::case_when( | |
suit == "Heart" ~ "\U2B16", # "?", | |
suit == "Diamond" ~ "\U2B17", # "^", | |
suit == "Club" ~ "\U2B18", | |
suit == "Spade" ~ "\U2B19" | |
) | |
) %>% | |
tidyr::pivot_wider( | |
id_cols = c("suit", "card"), | |
names_from = "order", | |
values_from = "question" | |
) %>% | |
dplyr::mutate( | |
id = dplyr::row_number(), | |
size = dplyr::case_when( | |
card %in% c("J", "Q", "K", "A") ~ 5, | |
TRUE ~ 4 | |
), | |
# first = paste("\U27A1", first), | |
# second = paste0("\U2687", second), | |
question = glue::glue( | |
"{first} | |
{second}", | |
.na = "" | |
) | |
) | |
# sysfonts::font_add("card_font", systemfonts::match_font("Diazo MVB Cond")$path) | |
# font_add("fira_mono", systemfonts::match_font("Fira Mono")$path) | |
sysfonts::font_add_google( | |
"Share Tech", # "Exo 2", | |
"question_family"#, | |
# regular.wt = 400, | |
# bold.wt = 600 | |
) | |
sysfonts::font_add_google( | |
"Share Tech Mono", # "Space Mono", | |
"card_family" | |
) | |
sysfonts::font_add_google( | |
"Noto Sans Symbols 2", | |
"suit_family" | |
) | |
showtext::showtext_auto() | |
dark <- "gray30" | |
card_theme <- | |
list( | |
ggplot2::theme( | |
strip.text = ggplot2::element_blank(), | |
plot.margin = ggplot2::margin(0, 0, 0, 0), | |
panel.background = ggplot2::element_rect(fill = dark), | |
panel.border = ggplot2::element_rect(color = "black", fill = NA) | |
), | |
ggplot2::scale_size_identity() | |
) | |
card_edge <- | |
ggplot2::geom_polygon( | |
data = data.frame( | |
x = c(0.05, 0.05, 0.95, 0.95), | |
y = c(0.05, 0.95, 0.95, 0.05) | |
), | |
mapping = ggplot2::aes(x = x, y = y), | |
fill = "gray40", | |
color = "white" | |
) | |
card_data <- | |
cards %>% | |
dplyr::group_nest(id) | |
cards$pg <- sort(rep(c(1:6), 9))[1:length(cards$id)] | |
card_plots <- | |
purrr::map( | |
card_data$data, | |
function(x) { | |
plot <- | |
ggplot2::ggplot(data = x) + | |
card_edge + | |
ggplot2::geom_text( | |
mapping = ggplot2::aes(label = card), | |
x = 0.15, | |
y = 0.15, | |
family = "card_family", | |
size = 8, | |
fill = dark, | |
color = "white" | |
) + | |
ggtext::geom_richtext( | |
mapping = ggplot2::aes(label = suit), | |
x = 0.85, | |
y = 0.15, | |
family = "suit_family", | |
# hjust = 0.5, | |
# vjust = 0.5, | |
label.padding = unit(c(0, 0, 0.2, 0), "lines"), | |
size = 14, | |
fill = NA, | |
label.color = NA, | |
color = "white" | |
) + | |
ggtext::geom_textbox( | |
mapping = ggplot2::aes( | |
label = question, | |
size = size | |
), | |
x = 0.5, | |
y = 0.9, | |
halign = 0, # Horizontal alignment of text in box | |
hjust = 0.5, # Horizontal alignment of box on card | |
valign = 1, | |
vjust = 1, | |
width = 0.8, | |
box.r = unit(0, "pt"), | |
box.padding = unit(c(20, 20), "pt"), | |
box.margin = unit(0, "pt"), | |
minheight = unit(0.6, "npc"), | |
maxheight = unit(0.8, "npc"), | |
# width = unit(2.75, "inch"), | |
family = "question_family" | |
) + | |
theme_void() + | |
card_theme | |
return(plot) | |
} | |
) | |
patchwork::wrap_plots(card_plots[1:9], ncol = 3) | |
ggsave( | |
filename = "pg_1.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) | |
patchwork::wrap_plots(card_plots[10:18], ncol = 3) | |
ggsave( | |
filename = "pg_2.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) | |
patchwork::wrap_plots(card_plots[19:27], ncol = 3) | |
ggsave( | |
filename = "pg_3.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) | |
patchwork::wrap_plots(card_plots[28:36], ncol = 3) | |
ggsave( | |
filename = "pg_4.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) | |
patchwork::wrap_plots(card_plots[37:45], ncol = 3) | |
ggsave( | |
filename = "pg_5.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) | |
patchwork::wrap_plots(card_plots[46:length(card_plots)], ncol = 3, nrow = 3) | |
ggsave( | |
filename = "pg_6.pdf", | |
device = cairo_pdf, | |
width = 8.5, | |
height = 11 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment