1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      Datafile editing functions, for use by the datafile tools.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 #ifndef DATEDIT_H
20 #define DATEDIT_H
21 
22 #ifdef __cplusplus
23    extern "C" {
24 #endif
25 
26 
27 #define DAT_INFO  DAT_ID('i','n','f','o')
28 #define DAT_ORIG  DAT_ID('O','R','I','G')
29 #define DAT_DATE  DAT_ID('D','A','T','E')
30 #define DAT_XPOS  DAT_ID('X','P','O','S')
31 #define DAT_YPOS  DAT_ID('Y','P','O','S')
32 #define DAT_XSIZ  DAT_ID('X','S','I','Z')
33 #define DAT_YSIZ  DAT_ID('Y','S','I','Z')
34 #define DAT_PACK  DAT_ID('P','A','C','K')
35 #define DAT_SORT  DAT_ID('S','O','R','T')
36 #define DAT_HNAM  DAT_ID('H','N','A','M')
37 #define DAT_HPRE  DAT_ID('H','P','R','E')
38 #define DAT_BACK  DAT_ID('B','A','C','K')
39 #define DAT_DITH  DAT_ID('D','I','T','H')
40 #define DAT_TRAN  DAT_ID('T','R','A','N')
41 #define DAT_XGRD  DAT_ID('X','G','R','D')
42 #define DAT_YGRD  DAT_ID('Y','G','R','D')
43 #define DAT_XCRP  DAT_ID('X','C','R','P')
44 #define DAT_YCRP  DAT_ID('Y','C','R','P')
45 #define DAT_RELF  DAT_ID('R','E','L','F')
46 
47 
48 
49 typedef struct DATEDIT_OBJECT_INFO
50 {
51    int type;
52    char *desc;
53    void (*get_desc)(AL_CONST DATAFILE *dat, char *s);
54    void *(*makenew)(long *size);
55    int (*save)(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids, int strip, int sort, int verbose, int extra, PACKFILE *f);
56    void (*plot)(AL_CONST DATAFILE *dat, int x, int y);
57    int (*dclick)(DATAFILE *dat);
58    void (*dat2s)(DATAFILE *dat, AL_CONST char *name, FILE *file, FILE *header);
59 } DATEDIT_OBJECT_INFO;
60 
61 
62 
63 typedef struct DATEDIT_GRABBER_INFO
64 {
65    int type;
66    char *grab_ext;
67    char *export_ext;
68    DATAFILE *(*grab)(int type, AL_CONST char *filename, DATAFILE_PROPERTY **prop, int depth);  /* TODO: get rid of 'depth' */
69    int (*exporter)(AL_CONST DATAFILE *dat, AL_CONST char *filename);
70    char *prop_types;
71 } DATEDIT_GRABBER_INFO;
72 
73 
74 
75 typedef struct DATEDIT_MENU_INFO
76 {
77    MENU *menu;
78    int (*query)(int popup);
79    int flags;
80    int key;
81    char *prop_types;
82 } DATEDIT_MENU_INFO;
83 
84 
85 
86 #define DATEDIT_MENU_FILE        1
87 #define DATEDIT_MENU_OBJECT      2
88 #define DATEDIT_MENU_HELP        4
89 #define DATEDIT_MENU_POPUP       8
90 #define DATEDIT_MENU_TOP         16
91 
92 
93 extern DATEDIT_OBJECT_INFO *datedit_object_info[];
94 extern DATEDIT_GRABBER_INFO *datedit_grabber_info[];
95 extern DATEDIT_MENU_INFO *datedit_menu_info[];
96 
97 
98 void datedit_register_object(DATEDIT_OBJECT_INFO *info);
99 void datedit_register_grabber(DATEDIT_GRABBER_INFO *info);
100 void datedit_register_menu(DATEDIT_MENU_INFO *info);
101 
102 
103 extern PALETTE datedit_current_palette;
104 extern PALETTE datedit_last_read_pal;
105 extern DATAFILE datedit_info;
106 
107 
108 void datedit_init(void);
109 
110 void datedit_msg(AL_CONST char *fmt, ...);
111 void datedit_startmsg(AL_CONST char *fmt, ...);
112 void datedit_endmsg(AL_CONST char *fmt, ...);
113 void datedit_error(AL_CONST char *fmt, ...);
114 int datedit_ask(AL_CONST char *fmt, ...);
115 int datedit_select(AL_CONST char *(*list_getter)(int index, int *list_size), AL_CONST char *fmt, ...);
116 
117 char *datedit_pretty_name(AL_CONST char *name, AL_CONST char *ext, int force_ext);
118 int datedit_clean_typename(AL_CONST char *type);
119 AL_CONST char *datedit_get_property(DATAFILE_PROPERTY **prop, int type);
120 int datedit_numprop(DATAFILE_PROPERTY **prop, int type);
121 void datedit_insert_property(DATAFILE_PROPERTY **prop, int type, AL_CONST char *value);
122 void datedit_set_property(DATAFILE *dat, int type, AL_CONST char *value);
123 void datedit_find_character(BITMAP *bmp, int *x, int *y, int *w, int *h);
124 DATAFILE *datedit_construct(int type, void *dat, long size, DATAFILE_PROPERTY **prop);
125 AL_CONST char *datedit_desc(AL_CONST DATAFILE *dat);
126 void datedit_sort_datafile(DATAFILE *dat);
127 void datedit_sort_properties(DATAFILE_PROPERTY *prop);
128 long datedit_asc2ftime(AL_CONST char *time);
129 AL_CONST char *datedit_ftime2asc(long time);
130 AL_CONST char *datedit_ftime2asc_int(long time);
131 AL_CONST char *datedit_grab_ext(int type);
132 AL_CONST char *datedit_export_ext(int type);
133 
134 
135 
136 typedef struct DATEDIT_SAVE_DATAFILE_OPTIONS {
137    int pack;
138    int strip;
139    int sort;
140    int verbose;
141    int write_msg;
142    int backup;
143    int relative;
144 } DATEDIT_SAVE_DATAFILE_OPTIONS;
145 
146 
147 
148 DATAFILE *datedit_load_datafile(AL_CONST char *name, int compile_sprites, AL_CONST char *password);
149 int datedit_save_datafile(DATAFILE *dat, AL_CONST char *name, AL_CONST int *fixed_prop, AL_CONST DATEDIT_SAVE_DATAFILE_OPTIONS *options, AL_CONST char *password);
150 int datedit_save_header(AL_CONST DATAFILE *dat, AL_CONST char *name, AL_CONST char *headername, AL_CONST char *progname, AL_CONST char *prefix, int verbose);
151 
152 int datedit_export(AL_CONST DATAFILE *dat, AL_CONST char *name);
153 void datedit_export_name(AL_CONST DATAFILE *dat, AL_CONST char *name, AL_CONST char *ext, char *buf);
154 
155 DATAFILE *datedit_insert(DATAFILE *dat, DATAFILE **ret, AL_CONST char *name, int type, void *v, long size);
156 DATAFILE *datedit_delete(DATAFILE *dat, int i);
157 
158 void datedit_swap(DATAFILE *dat, int i1, int i2);
159 
160 
161 typedef struct DATEDIT_GRAB_PARAMETERS {
162    AL_CONST char *datafile;  /* absolute filename of the datafile              */
163    AL_CONST char *filename;  /* absolute filename of the original file         */
164    AL_CONST char *name;      /* name of the object                             */
165    int type;                 /* type of the object                             */
166    int x, y, w, h;           /* area to grab within the bitmap                 */
167    int colordepth;           /* color depth to grab to                         */
168    int relative;             /* whether to use relative filenames for DAT_ORIG */
169 } DATEDIT_GRAB_PARAMETERS;
170 
171 DATAFILE *datedit_grabnew(DATAFILE *dat, AL_CONST DATEDIT_GRAB_PARAMETERS *params);
172 int datedit_grabreplace(DATAFILE *dat, AL_CONST DATEDIT_GRAB_PARAMETERS *params);
173 int datedit_grabupdate(DATAFILE *dat, DATEDIT_GRAB_PARAMETERS *params);
174 DATAFILE *datedit_grab(DATAFILE_PROPERTY *prop, AL_CONST DATEDIT_GRAB_PARAMETERS *params);
175 
176 int datedit_update(DATAFILE *dat, AL_CONST char *datafile, int force, int verbose, int *changed);
177 
178 extern void (*grabber_sel_palette)(PALETTE pal);
179 extern void (*grabber_select_property)(int type);
180 extern void (*grabber_get_grid_size)(int *x, int *y);
181 extern void (*grabber_rebuild_list)(void *old, int clear);
182 extern void (*grabber_get_selection_info)(DATAFILE **dat, DATAFILE ***parent);
183 extern int (*grabber_foreach_selection)(int (*proc)(DATAFILE *, int *, int), int *count, int *param, int param2);
184 extern DATAFILE *(*grabber_single_selection)(void);
185 extern void (*grabber_set_selection)(void *object);
186 extern void (*grabber_busy_mouse)(int busy);
187 extern void (*grabber_modified)(int modified);
188 
189 
190 #define FILENAME_LENGTH      1024
191 #define MAX_BYTES_PER_CHAR   6
192 
193 extern char grabber_data_file[FILENAME_LENGTH];
194 extern BITMAP *grabber_graphic;
195 extern PALETTE grabber_palette;
196 
197 #define GRABBER_GRAPHIC_ORIGIN_SIZE  256
198 
199 extern char grabber_import_file[];
200 extern char grabber_graphic_origin[];
201 extern char grabber_graphic_date[];
202 
203 
204 #ifdef __cplusplus
205    }
206 #endif
207 
208 #endif
209