Skip to content

Commit

Permalink
fixes and generic dice roller
Browse files Browse the repository at this point in the history
  • Loading branch information
oganm committed Feb 17, 2018
1 parent b107628 commit 9eda8cf
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 18 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Imports:
shinythemes,
shinyjs,
shinyWidgets,
DT
DT,
shinyBS
Remotes:
oganm/ogbox,
oganm/diceSyntax
Expand Down
1 change: 1 addition & 0 deletions inst/app/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ library(DT)
library(magrittr)
library(purrr)
library(dplyr)
library(shinyBS)
source('modules.R')

consoleLength = 15
Expand Down
88 changes: 75 additions & 13 deletions inst/app/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ characterDescription = function(input,output,session,char,charInitial){

tagList(
fluidRow(
column(4,
column(5,
wellPanel(fluidRow(
column(8,h2(char$Name)),
column(4,fileInput(session$ns('charInput'),label = 'Load char'))
column(5,h2(char$Name)),
column(4,
div(textInput(session$ns('driveInput'),label = 'G Drive Import',width = '150px') ,style= 'display: inline-block'),
actionButton(session$ns('driveSubmit'),label = '',icon = icon('check'),class = 'modButton',style = 'display: inline-block'),
bsTooltip(session$ns('driveSubmit'),'Search in Google Drive',placement = 'bottom')),
column(3,
fileInput(session$ns('charInput'),label = 'Local import'),
bsTooltip(session$ns('charInput'),'Load local file',placement = 'bottom'))
)
)
),
column(8,
column(7,
wellPanel(
fluidRow(
column(4, descriptiveElement(char$ClassField,'Class & Level')),
column(4, descriptiveElement(char$Background,'Background')),
column(2, descriptiveElement(AC(char),'AC')),
column(2, descriptiveElement(initBonus(char),'Initiative'))
column(2, descriptiveElement(initBonus(char),'Initiative')),
column(4, descriptiveElement(char$ClassField,'Class & Level')),
column(4, descriptiveElement(char$Background,'Background'))

),
fluidRow(
column(4, descriptiveElement(char$Race, 'Race')),
column(4,descriptiveElement(char$Alignment, 'Alignment')),
column(2, descriptiveElement(char$proficiencyBonus,'Proficiency')),
column(2, descriptiveElement(char$baseSpeed, 'Speed'))
column(2, descriptiveElement(char$baseSpeed, 'Speed')),
column(4, descriptiveElement(char$Race, 'Race')),
column(4,descriptiveElement(char$Alignment, 'Alignment'))
)
))
)
Expand All @@ -58,6 +65,23 @@ characterDescription = function(input,output,session,char,charInitial){
}
})

observe({
input$driveSubmit
isolate({
if(!is.null(input$driveSubmit) && !is.null(input$driveInput) && input$driveInput != ''){
withProgress({
character = importCharacter(regex = input$driveInput)
for(x in names(reactiveValuesToList(char))){
char[[x]] = character[[x]]
}
for(x in names(reactiveValuesToList(charInitial))){
charInitial[[x]] = character[[x]]
}
},value =0.5 ,message = 'Reading from Google Drive')
}
})
})

}

healthUI = function(id){
Expand Down Expand Up @@ -89,7 +113,11 @@ healthUI = function(id){
actionButton(ns('minusHealth'),'-', class = 'modButton'),
actionButton(ns('plusHealth'),'+',class = 'modButton'),
actionButton(ns('plusTempHealth'),'+ 0',
class = 'modButton',style = 'background-color:#6959CD')
class = 'modButton',style = 'background-color:#6959CD'),
bsTooltip(ns('minusHealth'),'Damage Health',placement = 'bottom'),
bsTooltip(ns('plusHealth'),'Heal',placement = 'bottom'),
bsTooltip(ns('plusTempHealth'),'Add temp. HP',placement = 'bottom'),
bsTooltip(ns('increment'),'HP to change',placement = 'bottom')

)
}
Expand Down Expand Up @@ -636,8 +664,7 @@ spells = function(input,output,session,char){


nameButtons = char$spells$name %>% sapply(function(x){
a(href = paste0(# 'https://thebombzen.com/grimoire/spells/',
'https://www.dndbeyond.com/spells/',
a(href = paste0(spellSource,
x %>% tolower() %>% gsub(' |/','-',.) %>% gsub("'",'',.)),
target= '_blank',x
) %>% as.character()
Expand Down Expand Up @@ -728,3 +755,38 @@ spells = function(input,output,session,char){


}


diceRollerUI = function(id){
ns = NS(id)
tagList(
tags$script("Shiny.addCustomMessageHandler('inputZero', function(variableName){
Shiny.onInputChange(variableName, 0);
});"),
div(textInput(ns('diceText'),placeholder = 'eg. 4d6k3',label = 'Roll dice'),style = 'display: inline-block;width: 30%'),
actionButton(ns('diceRoll'),
label = div(img(src = 'icons/dice-twenty-faces-twenty.png',
height = 20,
width = 20),'Roll!'), style = "display: inline-block")

)
}

diceRoller = function(input,output,session){
out = reactive({
if(input$diceRoll>0){
isolate({
out = tryCatch(capture.output(roll(input$diceText)) %>% paste(collapse='\n'),
error = function(e){''})

session$sendCustomMessage(type = 'inputZero',
message = session$ns('diceRoll'))
})
} else {
out = ''
}
return(out)
})

return(out)
}
6 changes: 5 additions & 1 deletion inst/app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ shinyServer(function(input, output,session) {

resourceModule = callModule(resources,'resources',char = char)


spellsModule = callModule(spells,'spells',char=char)

diceModule = callModule(diceRoller,'diceRoller')

output$console = renderText({
out = ''

Expand All @@ -56,6 +57,9 @@ shinyServer(function(input, output,session) {
if(out == ''){
out = resourceModule()
}
if(out == ''){
out = diceModule()
}


isolate({
Expand Down
24 changes: 21 additions & 3 deletions inst/app/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,31 @@ shinyUI(
tabPanel('Weapons',
weaponsUI(id = 'weapons')),
tabPanel('Spells',
spellsUI(id = 'spells')))),
spellsUI(id = 'spells'))),
diceRollerUI(id = 'diceRoller')),
column(3,
wellPanel(verbatimTextOutput('console',placeholder = TRUE)),
resourcesUI('resources'))),
fluidRow(
wellPanel(p('Icon credits:',
paste0(paste(iconCredits,collapse =', '),'.')))
hr(),
fluidRow(column(2),
column(2,
p('Developed by',a(href = 'https://github.com/oganm', target="_blank",'Ogan Mancarci'),
style = 'text-align:center'),
p('Source code', a(href = 'https://github.com/oganm/import5eChar/tree/master/inst/app', target="_blank",'here'),
style = 'text-align:center')),
column(3,
p(a(href = 'https://play.google.com/store/apps/details?id=com.wgkammerer.testgui.basiccharactersheet.app&hl=en', target="_blank",'Fifth Edition Character Sheet'),
'is created by Walter Kammerer'),style = 'text-align:center'),
column(3,
p('Icon credits:',
paste(iconCredits,collapse =', '),
'from',a(href = 'http://game-icons.net/', target="_blank",'game-icons.net'),
style = 'text-align:center'),
p('Released under', a(href = 'https://creativecommons.org/licenses/by/3.0/', target="_blank",'CC BY 3.0'),
style = 'text-align:center')),
column(2))

)
)
)
Binary file added inst/app/www/icons/dice-twenty-faces-twenty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions inst/app/www/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.progress{
margin-bottom:0;
}

.checkbox{
margin-top:0;
margin-bottom:0;
Expand Down

0 comments on commit 9eda8cf

Please sign in to comment.