RoomBuilder (rbr) is a pure POSIX sh library to create "rooms" for the upcoming mia roguelike
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

#!/bin/sh
# this script ($0) should be sourced and used like a lib
IFS=""
rparse() { # work with the below mparse() using recursing to combine all of $@
unset out
for i in "$@"; do
out=$(mparse "$out" "$1")
shift 1
done; echo "$out"
}
mparse() { # multi-column parse
sa="$2"
IFS=$(printf '\n\b')
set -- $(printf '%s\n' "$1")
IFS=""; n=0; while read -r two; do
: $((n+=1)); [ "$n" -gt 9 ] && {
shift 1
: $((n-=1))
}
printf '%s\n' $(eval "printf '%s\n' \$$n")$two
done << EOF
$(printf '%s\n' "$sa")
EOF
}
# this combines the contents of two groups of lines
# -- a line contains a group of columns; these column's need to be determined before drawing
# -- mparse combines to groups of lists so as to allow lines to be ""redefined""
# -- rparse uses recursion to combine all groups in $@
# IE
# $1:
# =|
# =|
# $2:
# =
# =
# -- would become
# =|=
# =|=
# -- rparse should allow for ?+1 arguments to be given thanks to the usage of `shift`
# index of some assests
export blank=' '
export sdoor='|' # 1x1 block of |'s
export topdoor='━' # 1x1 block of ─
export corner='+' # 1x1 block of +'s
export swall='#' # 1x1 block of #
export topwall='═' # 1x1 block of ═
export path='' # 1x1 path block
export floor='' # 1x1 floor block
# example:
# +════━══════+
# # #
# | #
# # #
# # #
# +═══════════+
# dash has issues with unicode
. ${RPATH:-.}/env # env file is used for various rendering data as well as the term size # user should manually configure this
IFS="x"; set -- ${MAX_ROOM_SIZE}; export ML="$1"; export MC="$2"
IFS="x"; set -- ${MIN_ROOM_SIZE}; export MiL="$1"; export MiC="$2"
# ML = MaxLines; MC = MaxColumns # [i] = min