💾 Archived View for tilde.club › ~filip › tech › script › rashomon › rashomon captured on 2023-09-08 at 17:57:04.
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
#!/bin/bash # Rashomon: Generating random scenarios for use in solitaire role-playing games or writing exercises. set -eu printhelp(){ echo "Rashomon is a script of generating random scenarios for use in solitaire role-plaing games or writing exercises." echo "" echo "Usage: rashomon <DIRECTORY> [-quick]" echo "<DIRECTORY> must contain the following files:" echo " .locations" echo " .events" echo " .subjects" echo " .objects" echo " .oracle_yes_no" echo " .oracle_outcome" echo " .oracle_aspect" echo "If the -quick flag is used the script will output a scenario without giving the option to specifi the question for The Oracle." echo "" } check_dir(){ # Check if the directory contains all needed files. # Parameter: directory path of the module. [[ -f "$1/.locations" ]] || return 0 [[ -f "$1/.events" ]] || return 0 [[ -f "$1/.subjects" ]] || return 0 [[ -f "$1/.objects" ]] || return 0 [[ -f "$1/.oracle_yes_no" ]] || return 0 [[ -f "$1/.oracle_outcome" ]] || return 0 [[ -f "$1/.oracle_aspect" ]] || return 0 return 1 } scenario_print(){ # Print scenario. echo "# Scenario description" echo "* Location: $location." echo "* Event : $event." echo "* Subject : $subject." echo "* Object : $object." echo "# Oracle's clarifications" for ((i=0; i<${#qna[@]}; i++)); do echo "* ${qna[i]}" done } quick_scenario_print(){ # Print a quick scenario. # Parameter: directory path of the module. location=$(shuf -n1 "$1/.locations") event=$(shuf -n1 "$1/.events") subject=$(shuf -n1 "$1/.subjects") object=$(shuf -n1 "$1/.objects") location_aspect=$(shuf -n1 "$1/.oracle_aspect") event_outcome=$(shuf -n1 "$1/.oracle_outcome") event_aspect=$(shuf -n1 "$1/.oracle_aspect") subject_aspect=$(shuf -n1 "$1/.oracle_aspect") object_aspect=$(shuf -n1 "$1/.oracle_aspect") echo "# Scenario description" echo "* Location: $location. Aspect of $location_aspect." echo "* Event : $event. Aspect of $event_aspect. $event_outcome." echo "* Subject : $subject. Aspect of $subject_aspect." echo "* Object : $object. Aspect of $subject_aspect." } if [[ $1 == "-h" ]]; then printhelp else if [[ -d "$1" ]]; then # check if directory contains all needed files check_dir "$1" || (( "$?" == 0 )) && echo "The directory does not contain all needed files!" && exit # check if -quick flag is invoked [[ "$2" == "-quick" ]] && quick_scenario_print "$1" && exit # get scenario description location=$(shuf -n1 "$1/.locations") event=$(shuf -n1 "$1/.events") subject=$(shuf -n1 "$1/.subjects") object=$(shuf -n1 "$1/.objects") echo "# Scenario description" echo "* Location: $location" echo "* Event : $event" echo "* Subject : $subject" echo "* Object : $object" # prepare questions and answers array qna=() echo "" echo "You may ask question of The Oracle for clarification." echo " t - ask a true/false question" echo " o - ask the question about outcome (success/failure/partial success/etc.)" echo " m - ask the question related to mood, aspect, or theme (death/nature/treason/etc.)" echo " q - quit." while [[ 1 ]]; do read -p "Enter command> " cmd case $cmd in t) read -p "Your question: " q ans=$(shuf -n1 "$1/.oracle_yes_no") echo "Oracle says : $ans" qna+=("$q? $ans.") ;; o) read -p "Your question: " q ans=$(shuf -n1 "$1/.oracle_outcome") echo "Oracle says : $ans" qna+=("$q? $ans.") ;; m) read -p "Your question: " q ans=$(shuf -n1 "$1/.oracle_aspect") echo "Oracle says : $ans" qna+=("$q? $ans.") ;; q) break ;; *) echo "Command does not exit. Please try again." ;; esac done scenario_print while [[ 1 ]]; do read -p "Save the information to a file? (y/n): " cmd case $cmd in y) read -p "Enter file name: " name if [[ -f "$name" ]]; then while [[ 1 ]]; do read -p "File exists. Overwrite? (y/n) " ow case ow in y) scenario_print > "$name" break ;; n) break ;; *) echo "Command does not exist. Please try again." ;; esac done else scenario_print > "$name" break fi ;; n) break ;; *) echo "Command does not exist. Please try again." ;; esac done else echo "$1 is not a valid directory!" fi fi