File: tileset_list.cpp

package info (click to toggle)
btanks 0.9.8083-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, forky, sid, trixie
  • size: 43,616 kB
  • sloc: cpp: 46,425; ansic: 12,005; xml: 4,262; python: 313; sh: 13; makefile: 13
file content (35 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tileset_list.h"
#include "mrt/exception.h"
#include "mrt/fs_node.h"

void TilesetList::clear() {
	_tilesets.clear();
	_last_gid = 0;
}

const int TilesetList::add(const std::string &name, const int gid, const int size) {
	if (gid == 0)
		throw_ex(("adding tileset with gid 0 is prohibited"));
	
	LOG_DEBUG(("add('%s', %d, %d) the latest gid was %d", name.c_str(), gid, size, _last_gid));
	int egid = gid;
	if (egid <= _last_gid) {
		LOG_DEBUG(("fixing invalid gid %d (the lowest value is %d)", gid, _last_gid));
		egid = _last_gid + 1;
	}

	_tilesets.push_back(Tilesets::value_type(name, egid));
	if (egid + size - 1 > _last_gid)
		_last_gid = egid + size - 1;
	
	return egid;
}

const int TilesetList::exists(const std::string &name) const {
	size_t n = size();
	for(size_t i = 0; i < n; ++i) {
		if (_tilesets[i].first == name || mrt::FSNode::get_filename(_tilesets[i].first, false) == name) //small hack allowing shortnames of the tilesets to be used here
			return _tilesets[i].second;
	}
	return 0;
}