Add a test case for --drawplayers

(also fixes off-by-one error in clipping players to draw)
This commit is contained in:
sfan5 2025-02-19 18:13:07 +01:00
parent 7a0bc15d21
commit 46cb386fef
2 changed files with 19 additions and 7 deletions

View File

@ -859,8 +859,8 @@ void TileGenerator::renderPlayers(const std::string &input_path)
PlayerAttributes players(input); PlayerAttributes players(input);
for (auto &player : players) { for (auto &player : players) {
if (player.x < m_xMin * 16 || player.x > m_xMax * 16 || if (player.x < m_xMin * 16 || player.x >= (m_xMax+1) * 16 ||
player.z < m_zMin * 16 || player.z > m_zMax * 16) player.z < m_zMin * 16 || player.z >= (m_zMax+1) * 16)
continue; continue;
if (player.y < m_yMin || player.y > m_yMax) if (player.y < m_yMin || player.y > m_yMax)
continue; continue;
@ -869,6 +869,7 @@ void TileGenerator::renderPlayers(const std::string &input_path)
m_image->drawFilledRect(imageX - 1, imageY, 3, 1, m_playerColor); m_image->drawFilledRect(imageX - 1, imageY, 3, 1, m_playerColor);
m_image->drawFilledRect(imageX, imageY - 1, 1, 3, m_playerColor); m_image->drawFilledRect(imageX, imageY - 1, 1, 3, m_playerColor);
assert(!player.name.empty());
m_image->drawText(imageX + 2, imageY, player.name, m_playerColor); m_image->drawText(imageX + 2, imageY, player.name, m_playerColor);
} }
} }

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
set -eo pipefail set -eo pipefail
mapdir=./testmap
msg () { msg () {
echo echo
@ -14,15 +15,15 @@ encodepos () {
# create map file with sql statements # create map file with sql statements
writemap () { writemap () {
mkdir -p testmap rm -rf $mapdir
echo "backend = sqlite3" >testmap/world.mt mkdir $mapdir
echo "default:stone 255 0 0" >testmap/colors.txt echo "backend = sqlite3" >$mapdir/world.mt
rm -f testmap/map.sqlite echo "default:stone 10 10 10" >$mapdir/colors.txt
printf '%s\n' \ printf '%s\n' \
"CREATE TABLE d(d BLOB);" \ "CREATE TABLE d(d BLOB);" \
"INSERT INTO d VALUES (x'$(cat util/ci/test_block)');" \ "INSERT INTO d VALUES (x'$(cat util/ci/test_block)');" \
"$1" \ "$1" \
"DROP TABLE d;" | sqlite3 testmap/map.sqlite "DROP TABLE d;" | sqlite3 $mapdir/map.sqlite
} }
# check that a non-empty ($1=1) or empty map ($1=0) was written with the args ($2 ...) # check that a non-empty ($1=1) or empty map ($1=0) was written with the args ($2 ...)
@ -98,3 +99,13 @@ checkmap 1 --geometry 32:32+16+16 --min-y 32 --max-y $((32+16-1))
msg "new schema: empty map" msg "new schema: empty map"
writemap "$schema_new" writemap "$schema_new"
checkmap 0 checkmap 0
msg "drawplayers"
writemap "
$schema_new
INSERT INTO blocks SELECT 0, 0, 0, d FROM d;
"
mkdir $mapdir/players
printf '%s\n' "name = cat" "position = (80,0,80)" >$mapdir/players/cat
# we can't check that it actually worked, however
checkmap 1 --drawplayers --zoom 4