Browse Source

get listgen() half working; make ptui obsolete (??); shit is slow as balls lol (idk why aaaaaa)

head
Mia 8 months ago
parent
commit
2761db16ae
No known key found for this signature in database
GPG Key ID: 71C6B366DD22D9B5
  1. 4
      .gitmodules
  2. 3
      README
  3. 4
      env
  4. 0
      grid.state
  5. 1
      ptui
  6. 10
      rbase
  7. 69
      rgrid

4
.gitmodules vendored

@ -1,7 +1,3 @@ @@ -1,7 +1,3 @@
[submodule "psh-tui"]
path = ptui
url = https://git.unix.lgbt/Mia/ptui
branch = head
[submodule "rng"]
path = rng
url = https://git.unix.lgbt/Mia/psh-prng

3
README

@ -22,5 +22,4 @@ @@ -22,5 +22,4 @@
-- using $RANDOM has the flaw of simply not being POSIX'ly defined
-- some shells implement $RANDOM; and others do not, if used a backup is still required if a shell does not contain it
# notes
-- testing of rbr is done in a terminal with 45 lines and 207 columns
-- the ptui library is a submodule of this repo, to clone correctly run git with the '--recursive' flag
-- please clone with `--recursive` as this project depends on the submods to operate

4
env

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
# set various varibles
export MAX_ROOM_SIZE="10x15" # max size of room # TxW ; LxC
export COLUMNS=207 # should be configured by user
export LINES=45 # should be configured by user
export COLUMNS=259 # should be configured by user
export LINES=62 # should be configured by user

0
grid.state

1
ptui

@ -1 +0,0 @@ @@ -1 +0,0 @@
Subproject commit 2d36f68451957a90c6b43b766a97bb4bb6bc4873

10
rbase

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
#!/bin/sh
. ${PPath:-.}/ptui
# this script ($0) should be sourced and used like a lib
IFS=""
rparse() { # work with the below mparse() using recursing to combine all of $@
@ -40,11 +39,10 @@ EOF @@ -40,11 +39,10 @@ EOF
# -- rparse should allow for ?+1 arguments to be given thanks to the usage of `shift`
# index of some assests
export blank=' '
export wall=$(printf '#') # 1x1 block of 3's
export door=$(printf '|') # 1x1 block of |'s
export corner=$(printf '+') # 1x1 block of +'s
export topwall=$(printf '=') # 1x1 block of ='s # rparse
export avatar="${avatar:-M}" # the default av is a literal `M`
export wall='#' # 1x1 block of 3's
export door='|' # 1x1 block of |'s
export corner='+' # 1x1 block of +'s
export topwall='=' # 1x1 block of ='s # rparse
. ${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"
# ML = MaxLines; MC = MaxColumns

69
rgrid

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#!/bin/sh
. ${RPATH:-.}/rbase # pull in the base values
. ${RPATH:-.}/env
# some example code for producing an empty screen
# for i in $(seq $LINES); do
# for i in $(seq $COLUMNS); do
@ -14,9 +15,45 @@ s() { # s acts as seq replacement @@ -14,9 +15,45 @@ s() { # s acts as seq replacement
echo "$n"; : $((n+=1))
done
}
agrid() { # find the elements around $1 based on its pos ($l&$c)
:
listgen(){ # generate typelist
unset typelist
types="door;wall;topwall;corner;blank" # these are all the defined types
ndoor="2"
nwall="3"
ntopwall="3"
ncorner="4" # corners should be more likely than walls
nblank="8" # blank space should be the most likely
# how many times they /SHOULD/ appear in the list
IFS=";"; tln=0; for i in ${types}; do # produce a number stating how many should be in the list
: $((tln+=$(printf 'n%s' "$i")))
done
unset IFS
for i in $(s 1 ${tln}); do
ran=6;
until [ "$ran" -le 5 ]; do
ran=$(${RPATH:-.}/rng/ran)
until [ "${#ran}" -eq 1 ]; do
ran="${ran%?}"
done
done
n=0; IFS=";"; for i in ${types}; do
: $((n+=1))
[ "$n" -eq "$ran" ] && {
unset IFS
eval $(printf 'typelist="${typelist+$typelist;}%s"' "$i")
}
done
done
unset IFS
}
sgrid() { # print $1 while saving it to a grid state file
printf '%s' "$1"
[ "$2" -gt 1 ] && {
printf '%s' "$1" >> grid.state
} || { # >>
printf '%s' "$1" > grid.state
} # >
}
# L = lines; C = COLUMNS
listr() { # create a new typelist using the items in $2; MUST not contain $1
@ -44,25 +81,32 @@ listS(){ # return a number that determines the legth of the number of items @@ -44,25 +81,32 @@ listS(){ # return a number that determines the legth of the number of items
[ "$LINES" -a "$COLUMNS" ] || exit 10 # exit code 10 will be for rgrid errors
unset IFS
for l in $(s 1 $LINES); do # for each line
for c in $(s 1 $COLUMNS); do # left to right across screen
typelist="wall;door;topwall;corner;blank" # these are set in rbase
tln=5 # $tln is the number of items in typelist
ml=0; for l in $(s 1 $LINES); do # for each line
mc=0; for c in $(s 1 $COLUMNS); do # left to right across screen
listgen # generate the typelist
#echo "$typelist"
# basically the idea here is have a list of all possible things a 1x1 space can be
# wall,door,blank,etc; these are ofc effected by the blocks around them and the current pos
# basically use ran() and some pain to have it pick what a block should be
# the list should be dynamic based on the pos and blocks around it
# ie; placing a door when there is no where for it to lead makes no sense
[ "$c" -le 3 -o "$l" -lt 2 ] && { # must be at least 3 over on C to create a door
# must also be at least 1 L down; this should also be effected by the surrounding blocks
IFS=';'
listr "door" "${typelist}" ";"
}
#[ "$mc" -eq "$MC" ] && {
# listr "topwall" "${typelist}" ";"
#}
# now use ran to generate a random number
# $((ran*ran))
ran=0; until [ "$ran" -gt 0 -a "$ran" -eq "$ran" -a "$ran" -le "$tln" ]; do
ran=$(( $(${RPATH:-.}/rng/ran)*$(${RPATH:-.}/rng/ran) ))
until [ "${#ran}" -le $(listS) ]; do
#ran=$(( $(${RPATH:-.}/rng/ran)*$(${RPATH:-.}/rng/ran) ))
ran=$(${RPATH:-.}/rng/ran)
until [ "${#ran}" -le $(listS) ]; do
ran=${ran%?}
done # shorten $ran until it is the length of the number of items in $typelist
done
@ -71,11 +115,14 @@ for l in $(s 1 $LINES); do # for each line @@ -71,11 +115,14 @@ for l in $(s 1 $LINES); do # for each line
n=0; for i in ${typelist}; do
: $((n+=1))
[ "$n" -eq "$ran" ] && {
eval $(printf "printf '%%s' \"$%s\"" "$i")
[ "$i" = "topwall" -o "$i" = "corner" ] && {
: $((mc+=1))
} || mc=0
eval $(printf 'sgrid "$%s" %s' "$i" "$c")
break
}
done; unset IFS # now select the item and print it
done
echo
echo; echo >> grid.state
# increment a count for $ML and $MC somewhere
done # this prob makes mparse/rparse obsolete lmao

Loading…
Cancel
Save