77 lines
1.9 KiB
Bash
Executable file
77 lines
1.9 KiB
Bash
Executable file
#!/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
|