gsgp/util/inv-count

41 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
#
# Counts number of items in the inventory
#
# Copyright (C) 2011 Mike Gerwitz
#
# This file is part of gsgp. This program is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
mypath=$( dirname $0 )
. "$mypath/common-inv"
if [ $# -lt 1 ]; then
echo "Usage: $0 ITEM"
fi
# we should be provided with the id, not the tag
item_id="$1"
inv_item_file="$( $mypath/getinvpath )/$item_id"
# if the file does not exit, then we clearly have 0 of the item in our inventory
if [ ! -r "$inv_item_file" ]; then
echo 0
exit
fi
# count the number of items in the inventory
wc -l < "$inv_item_file" || echo 0