File: guidegenerator.h

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (386 lines) | stat: -rw-r--r-- 11,685 bytes parent folder | download | duplicates (3)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/***************************************************************************
                          guidegenerator.h  -  description
                             -------------------
    begin                : Tue Jan 23 2001
    copyright            : (C) 2001 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef guidegeneratorH
#define guidegeneratorH

#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <map>
#include <set>


#include "../itemrepository.h"
#include "../vehicletype.h"
#include "../buildingtype.h"
#include "../ascstring.h"
#include "../typen.h"
#include "../sgstream.h"

#include "groupfile.h"


#define VehicleType Vehicletype
#define RELATIVEIMGPATH "./"
#define RELATIVEBUILDINGSPATH "./"

typedef map<int, ASCString> Int2String;
//typedef map<int, Category*> GroupFileEntriesMap;
typedef set<ASCString> StringSet;
typedef set<int> IntSet;


class InfoPageUtil{

public:

static bool diffMove( const ASCString src, const ASCString dst );

static ASCString getTmpPath();

static void copyFile(const ASCString src, const ASCString dst);

static bool equalFiles(const ASCString src, const ASCString dst);

static void updateFile(ASCString fileName, ASCString exportPath);
};


/**
*@brief Abstract base class for building and unit guide generator
*@author Kevin Hirschmann
*/
class GuideGenerator {
public:
  /**
  *@brief Constructor for creating a new GuideGenerator
  *@param filePath The path to which the generated files are stored
  *@param menuCSSPath  The full path to the used css-file for the menu
  *@param setID The set of which the guide is created, if set to 0 guides for all sets will be created
  *@param mainCSSPath  The full path to the used css-file for the pages
  *@param createImg Determines if images shall be created.
  */

  GuideGenerator(ASCString filePath, ASCString menuCSSPath, int setID, ASCString mainCSSPath, ASCString techIDs, bool createImg, ASCString relMenuPath, bool upload = false, int imageSize = 0);

  /**
  *@brief Destructor
  */
  virtual ~GuideGenerator() {};
  /**
  *@brief Starts the guide generation
  *       
  */
  virtual void processSubjects() = 0;
  /**
  *@brief Returns the path to the image of subject with the corresponding ID 
  *@param ID The id of the subject to which the image path is to retrieve
  *@return  The file path of the image of the subject with corresponding ID
  */
  const ASCString& getImagePath(int ID);
  /**
  *@brief Returns the path to the css-File used by generated pages
  *        void diffCopy( const ASCString& src, const ASCString& dst );
  */
  const ASCString& getMainCSSPath() const;  
  /*
  *@brief Gets the width for the unit image
  */
  int getImageWidth() const{
    return imageWidth;
  }
  /*
  *@brief Tests if the generator is running in upload mode
  */
  bool generatesUpload() const{
    return createUpload;
  }
  /*
  *@brief Gets the filePath of the output
  */
  const ASCString getFilePath() const{
    return filePath;
  }
  
  const vector<IntRange>& getTechTreeIDs() const{
    return techTreeIDs;
  }

protected:
  /**
  *@brief A map containing: subject ids -> path to the corresponding image
  */
  Int2String graphicRefs;
  /**
  *@brief The path to which the pages of the guide are generated
  */
  ASCString filePath;
  /**
  *@brief The full path to the used css-file for the menu
  */
  ASCString menuCSSFile;
  /**
  *@brief The full path to the used css-file for the pages
  */
  ASCString mainCSSFile;
   
  /**
  *@brief Determines if images should be created.
  */
  bool createImg;
  /**
  *@brief Specifies the id of the set for which a guide is generated
  */
  int setID;
  /**
  *@brief imageWidth Determines the width of the unit image in pix
  */
  int imageWidth;
  /**
  *@brief createUpload Defines if an upload specific output shall be created
  *       This upload is placed in a special directory which contains only
  *       data which differs from previous generated data
  */
  bool createUpload;
  /**
  *@brief techTreeID Selects which branch of a technology is shown.
  *Each unit/builing can have multiple ways to research them
  *E.g. there is one branch for pbp and another for the asc campain
  */
  vector<IntRange> techTreeIDs;
  /**
  *@brief Default-Constructor
  */    
  GuideGenerator() {};  
    
  /**
  *@brief Determines the relative path from the menu to the single pages.
  *       Is prefixed to filelink in GroupFile
  */
  ASCString relMenuPath;
private:

};

  /**
  *@brief Class for generating the building guide
  *@author Kevin Hirschmann
  */
class BuildingGuideGen: public GuideGenerator {
public:
  /**
  *@brief Constructor for creating a new BuildingGuideGen(erator)
  *@param filePath The path to which the generated files are stored
  *@param cssPath  The full path to the used css-file
  *@param setID The set of which the guide is created, if set to 0 guides for all sets will be created
  *@param createImg Determines if images shall be created.
  *@param buildingsUnique Determines if the pages for a building shall be created only once or for each
  *       of its occurence in the set (different directions, different weather) 
  */
  BuildingGuideGen(ASCString filePath, ASCString menuCSSPath, int setID, ASCString mainCSSPath, ASCString techIDs, bool createImg,  ASCString relMenuPath, bool buildingsUnique = false, bool upload = false, int imageSize = 0);
  /*
  *@brief Destructor
  */
  virtual ~BuildingGuideGen();
  /*
  *@brief Creates a guide (aggregated of several specialistaions of BuildingInfoPage)
  */
  virtual void processSubjects();
  /**
  *@brief Creates the file name for the pages of a buildingtype (no index, no extension)
  **A full fileName is: filePath + constructFileName(...) + [INDEX] + extension
  */
  static ASCString constructFileName(const BuildingType& bt);  

private:
  /**
  *@brief Default-Constructor
  */
  BuildingGuideGen() {};
  /*
  *@brief Creates the group files
  */
  virtual void generateCategories() const;
  /**
  *@brief Creates the guide pages for one BuildingType
  *@param bt The building type for which the guide pages are created
  */
  void processBuilding(const BuildingType&  bt);
  
  /**
  *@brief The APPENDIX is used to distinguish between Building, Unit etc. files
  *       Necessary, because the file names are created from the ids which are only unique in their domain (e.g. buildingTypes)
  */
  static const ASCString APPENDIX;
  /**
  *@brief Determines if the pages for a building shall be created only once or for each
  *       of its occurence in the set (different directions, different weather)   
  */
  bool buildingsUnique;
  
  /**
  *@brief 
  *       
  */
  StringSet buildingNames;
  
  IntSet processedBuildingIds;
};

  /**
  *@brief Class for generating the unit guide
  *@author Kevin Hirschmann
  */
class UnitGuideGen: public GuideGenerator {
public:
  /**
  *@brief Constructor for creating a new BuildingGuideGen(erator)
  *@param filePath The path to which the generated files are stored
  *@param cssPath  The full path to the used css-file
  *@param setID The set of which the guide is created, if set to 0 guides for all sets will be created
  *@param createImg Determines if images shall be created.
  *@param imageSize Determines the width of the unit image in pix
  */
  UnitGuideGen(ASCString filePath, ASCString menuCSSPath, int setID, ASCString mainCSSPath, ASCString techIDs, bool createImg,  ASCString relMenuPath, bool upload = false, int imageSize = 0);
  /**
  *@brief Destructor
  */
  virtual ~UnitGuideGen();
  /*
  *@brief Creates a guide (aggregated of several specialistaions of UnitInfoPage)
  */
  virtual void processSubjects();
  /**
  *@brief Creates the file name for the pages of a VehicleType (no index, no extension)
  *A full fileName is: filePath + constructFileName(...) + [INDEX] + extension
  */
  static ASCString constructFileName(const VehicleType& vt);
  
  private:  
  /**
  *The label for the category trooper
  */
  static const ASCString TROOPER;
  /**
  *The label for the category sea units
  */
  static const ASCString SEAUNIT;
  /**
  *The label for the category air units
  */
  static const ASCString AIRUNIT;
  /**
  *The label for the category turret units
  */
  static const ASCString TURRETUNIT;
  /**
  *The label for the category ground unit
  */
  static const ASCString GROUNDUNIT;
  /**
  *The label for the category orbital unit
  */
  static const ASCString ORBITUNIT;
  

  /**
  *brief Default-Constructor
  */
  UnitGuideGen() {};
  /**
  *@brief Creates the guide pages for one VehicleType
  *@param vt The vehicle type for which the guide pages are created
  */  
  void processUnit(const VehicleType&  vt);
  /**
  *@brief Creates the group files
  */
  virtual void generateCategories() const;
  
  /**
  *@brief The APPENDIX is used to distinguish between Building, Unit etc. files
  *       Necessary, because the file names are created from the ids which are only unique in their domain (e.g. buildingTypes)
  */
  static const ASCString APPENDIX;
};


  /**
  *@brief Class for converting pcx-files
  */
class ImageConverter {
public:
  /**
  *@brief Standard-Constructor
  */
  ImageConverter();
  /**
  *@brief Creates a picture for a BuildingType
  *@param bt The building type for which the pic is created
  *@param filePath The path to the place where the pic will be stored
  */
  ASCString createPic(const BuildingType&  bt,  ASCString filePath);
  /**
  *@brief Creates a picture for a VehicleType
  *@param vt The vehicle type for which the pic is created
  *@param filePath The path to the place where the pic will be stored
  */
  ASCString createPic(const VehicleType&  vt,  ASCString filePath);

  /**
  *@brief Constructs the full path to the image of a BuildingType    
  *@param bt The building type for which an image is created
  *@param filePath The path where the images are stored
  *@return The full Path to the image: path + fileName + extension
  */
  ASCString constructImgPath(const BuildingType&  cbt, const ASCString filePath);
  
  /**
  *@brief Constructs the full path to the image of a VehicleType  
  *@param vt The building type for which an image is created
  *@param filePath The path where the images are stored
  *@return The full Path to the image: path + fileName + extension
  */
  ASCString constructImgPath(const VehicleType&  cbt, const ASCString filePath);
  
  ASCString constructImgFileName(const VehicleType&  vt);
  
  ASCString constructImgFileName(const BuildingType&  vt);
  
  
  
private:
  /**
  *@brief Converts a pcx-file of a building to a gif
  *@param fileName The file name for the created pic
  *@param filePath The place where the image will be stored
  *@param xsize The width of the created image
  *@param ysize The height of the created image
  */
  void convert(const ASCString&  fileName, Surface& s, ASCString filePath , int xsize = fieldsizex, int ysize = fieldsizey); 


};
#endif