Moved scripts to paren folder, and updated README some more

This commit is contained in:
Techognito 2025-08-14 22:45:04 +02:00
parent e45fb41e1b
commit b4891f3061
6 changed files with 7 additions and 1 deletions

77
foundryrolltable.sh Executable file
View file

@ -0,0 +1,77 @@
#!/bin/bash
inputfile="output.txt"
title="Title"
description=""
inputjson=Template.json
outputjson=fvtt-RollTable-$title.json
tempjson=temp.json
#todo: check if empty
addItem () {
cp "$outputjson" $tempjson
local rangemin=$(jq '.results[.results| length-1].range[0]' "$outputjson")
local rangemax=$(jq '.results[.results| length-1].range[1]' "$outputjson")
#Check what the last range number is and add 1 to that number
local newrangemin=$(($rangemin+1))
local newrangemax=$(($rangemax+1)) #while this will technically work, this will break of range min and max is not the same
# local text= "$1"
jq --argjson newrangemin $newrangemin --argjson newrangemax $newrangemax --arg text "${1}" '.results[.results| length] += {"Type": "text", "range": [$newrangemin,$newrangemax],"drawn": false, "text": $text }' "$outputjson" > $tempjson
cp $tempjson "$outputjson"
rm $tempjson
}
setTitle() {
cp "$outputjson" $tempjson
jq --arg title "${title}" '.name = $title' "$outputjson" > $tempjson
cp $tempjson "$outputjson"
rm $tempjson
}
setDescription() {
cp "$outputjson" $tempjson
jq --arg desc ${description} '.description = $desc' "$outputjson" > $tempjson
cp $tempjson "$outputjson"
rm $tempjson
}
readFile() {
echo $1
if [ -z "$1" ]; then
echo test
read -r -p "File location:" fileInput
inputfile="$fileInput"
else
inputfile="$1"
fi
}
# todo fix setTitle
readTitle() {
echo $1
if [ -z "$1" ]; then
read -r -p "What is the Title of the RollTable? (input as string): " input
title="$input"
echo $title
else
title="$1"
fi
}
## runtime ##
filevar="$1"
titlevar="$2"
echo "Creating a new JSON file for import in FoundrVTT"
readFile "$filevar"
readTitle "$titlevar"
outputjson="fvtt-RollTable-$title.json"
cp $inputjson "$outputjson"
while read line; do
echo "$line"
addItem "$line"
done < "$inputfile"
#todo: make addItem able to read csv with range and text
#todo: Check outputfile if item allready exists (prevent duplicate items)
setTitle