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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/**
** A group of shapes/chunks that can be used as a 'palette'.
**
** Written: 1/22/02 - JSF
**/
#ifndef INCL_SHAPEGROUP
#define INCL_SHAPEGROUP 1
/*
Copyright (C) 2002 The Exult Team
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 2
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <vector>
#include <string>
class Shape_group_file;
/*
* A group of shape/chunk #'s:
*/
class Shape_group : std::vector<int> // Not public on purpose.
{
std::string name; // What this group is called.
Shape_group_file *file; // Where this comes from.
public:
friend class Shape_group_file;
Shape_group(char *nm, Shape_group_file *f);
~Shape_group() { }
Shape_group_file *get_file()
{ return file; }
const char *get_name() const
{ return name.c_str(); }
void set_name(char *nm)
{ name = nm; }
int size()
{ return std::vector<int>::size(); }
int& operator[](int i)
{ return std::vector<int>::operator[](i); }
void del(int i)
{ std::vector<int>::erase(begin() + i); }
void swap(int i); // Swap entries i and i+1.
void add(int id); // Add ID, checking for duplicate 1st.
};
/*
* This class represents the file containing groups for a given shape
* or chunks file. It is read from the 'patch' or 'static' directory,
* and saved to the 'patch' directory.
*/
class Shape_group_file
{
std::string name; // Base filename.
std::vector<Shape_group *> groups;// List of groups from the file.
bool modified; // Changed since last save.
public:
friend class Shape_group;
Shape_group_file(const char *nm);
~Shape_group_file();
int size()
{ return groups.size(); }
Shape_group *get(int i)
{ return groups[i]; }
void add(Shape_group *grp) // Add a new group.
{ groups.push_back(grp); modified = true; }
void insert(Shape_group *grp, int i)
{ groups.insert(groups.begin() + i, grp); modified = true; }
bool is_modified()
{ return modified; }
int find(const char *nm); // Find group with given name.
// Remove and delete group.
void remove(int index, bool del = true);
void write(); // Write out (to 'patch' directory).
};
#endif
|