#!/bin/bash
# SPDX-FileCopyrightText: 2025 artlog@l0g.eu
# SPDX-License-Identifier: AGPL-3.0-or-later
# header generated by lib/metascript.sh header
# metascript_version=v1.0.0

toolsdir=lib
pushd $toolsdir >/dev/null
toolsdir=$(pwd)
source metascript.sh
popd >/dev/null

usage() {
    cat <<EOF
copy a .we generated lab into minetest local game directory

name=name of generated .we without extension
game=name of game

EOF
}
metarun=metarun
# change default to sudo if needed
# metasudo=sudo

name="$1.we"
srcdir="lab/"
game="nm"

while [[ $# > 0 ]]
do
    case "$1" in
	name=*)
	    name=${1/name=}.we
	    ;;
	game=*)
	    game=${1/game=}
	    ;;
        *)
           parsemetaarg "$1"
        ;;
    esac
    shift
done

dest=~/.minetest/worlds/$game/schems
src=${srcdir}$name

enforce file $src exists
enforce dir $dest exists

if [[ -f $src ]]
then
    $defer cp $src $dest/
else
    log_error "missing $src"
fi
