@@ -111,14 +111,15 @@ static void SortStringsByName(char **items, int count);
111
111
//------------------------------------------------------------------------------------
112
112
int main (int argc , char * argv [])
113
113
{
114
- // Examples path for building
114
+ // Paths required for examples management
115
115
// TODO: Avoid hardcoding path values...
116
116
char * exBasePath = "C:/GitHub/raylib/examples" ;
117
117
char * exWebPath = "C:/GitHub/raylib.com/examples" ;
118
118
char * exTemplateFilePath = "C:/GitHub/raylib/examples/examples_template.c" ;
119
+ char * exTemplateScreenshot = "C:/GitHub/raylib/examples/examples_template.png" ;
119
120
char * exCollectionList = "C:/GitHub/raylib/examples/examples_list.txt" ;
120
121
121
- char inFileName [1024 ] = { 0 }; // Example input filename
122
+ char inFileName [1024 ] = { 0 }; // Example input filename (to be added)
122
123
123
124
char exName [64 ] = { 0 }; // Example name, without extension: core_basic_window
124
125
char exCategory [32 ] = { 0 }; // Example category: core
@@ -146,7 +147,8 @@ int main(int argc, char *argv[])
146
147
{
147
148
// TODO: Additional security checks for file name?
148
149
149
- strcpy (inFileName , argv [2 ]); // Register filename for creation
150
+ strcpy (exName , argv [2 ]); // Register filename for new example creation
151
+ strncpy (exCategory , exName , TextFindIndex (exName , "_" ));
150
152
opCode = 1 ;
151
153
}
152
154
}
@@ -159,23 +161,28 @@ int main(int argc, char *argv[])
159
161
{
160
162
if (IsFileExtension (argv [2 ], ".c" )) // Check for valid file extension: input
161
163
{
162
- // TODO: Parse category name from filename provided!
163
-
164
- strcpy (inFileName , argv [2 ]); // Register filename for creation
165
- opCode = 2 ;
164
+ if (FileExists (inFileName ))
165
+ {
166
+ strcpy (inFileName , argv [2 ]); // Register filename for addition
167
+ strcpy (exName , GetFileNameWithoutExt (argv [2 ])); // Register example name
168
+ strncpy (exCategory , exName , TextFindIndex (exName , "_" ));
169
+ opCode = 2 ;
170
+ }
171
+ else LOG ("WARNING: Input file not found, include path\n" );
166
172
}
167
173
else LOG ("WARNING: Input file extension not recognized (.c)\n" );
168
174
}
169
175
}
170
176
else if (strcmp (argv [1 ], "rename" ) == 0 )
171
177
{
172
- if (argc == 2 ) LOG ("WARNING: No filename provided to create\n" );
173
- else if (argc == 3 ) LOG ("WARNING: No enough arguments provided\n" );
178
+ if (argc == 2 ) LOG ("WARNING: No filename provided to be renamed\n" );
174
179
else if (argc > 4 ) LOG ("WARNING: Too many arguments provided\n" );
175
180
else
176
181
{
177
- // TODO: Register exName, exCategory and exRename
178
-
182
+ strcpy (exName , argv [2 ]); // Register example name
183
+ strncpy (exCategory , exName , TextFindIndex (exName , "_" ));
184
+ strcpy (exRename , argv [3 ]);
185
+ // TODO: Consider rename with change of category
179
186
opCode = 3 ;
180
187
}
181
188
}
@@ -186,57 +193,79 @@ int main(int argc, char *argv[])
186
193
else if (argc > 3 ) LOG ("WARNING: Too many arguments provided\n" );
187
194
else
188
195
{
189
- strcpy (inFileName , argv [2 ]); // Register filename for removal
196
+ strcpy (exName , argv [2 ]); // Register filename for removal
190
197
opCode = 4 ;
191
198
}
192
199
}
193
200
else if (strcmp (argv [1 ], "validate" ) == 0 )
194
201
{
195
- opCode = 5 ;
202
+ opCode = 5 ;
196
203
}
197
204
}
198
205
199
206
switch (opCode )
200
207
{
201
208
case 1 : // Create: New example from template
202
209
{
203
- // Copy template file as new example
210
+ // Create: raylib/examples/<category>/<category>_example_name.c
204
211
FileCopy (exTemplateFilePath , TextFormat ("%s/%s/%s.c" , exBasePath , exCategory , exName ));
205
212
}
206
213
case 2 : // Add: Example from command-line input filename
207
214
{
208
- if ((opCode != 1 ) && FileExists (inFileName ))
209
- {
210
- FileCopy (inFileName , TextFormat ("%s/%s/%s.c" , exBasePath , exCategory , exName ));
211
- }
212
-
213
- // Generate all required files
214
- //--------------------------------------------------------------------------------
215
215
// Create: raylib/examples/<category>/<category>_example_name.c
216
+ if (opCode != 1 ) FileCopy (inFileName , TextFormat ("%s/%s/%s.c" , exBasePath , exCategory , exName ));
217
+
216
218
// Create: raylib/examples/<category>/<category>_example_name.png
217
- FileCopy ("C:/GitHub/raylib/examples/examples_template.png" ,
218
- TextFormat ("%s/%s/%s.png" , exBasePath , exCategory , exName )); // To be updated manually!
219
+ FileCopy (exTemplateScreenshot , TextFormat ("%s/%s/%s.png" , exBasePath , exCategory , exName )); // WARNING: To be updated manually!
219
220
220
- // Copy: raylib/examples/<category>/resources/*.* ---> To be updated manually!
221
+ // Copy: raylib/examples/<category>/resources/... // WARNING: To be updated manually!
222
+
223
+ // Check if example is already listed
224
+
225
+ // If not, add to the main examples_list
221
226
222
227
// TODO: Update the required files to add new example in the required position (ordered by category and name),
223
228
// it could require some logic to make it possible...
224
229
225
230
// Edit: raylib/examples/Makefile --> Add new example
231
+ char * mkText = LoadFileText (TextFormat ("%s/Makefile" , exBasePath ));
232
+ int exListStartIndex = TextFindIndex (mkText , "#EXAMPLES_LIST_START" );
233
+ int exListEndIndex = TextFindIndex (mkText , "#EXAMPLES_LIST_END" );
234
+ char * mkTextUpdate = (char * )RL_CALLOC (2 * 1024 * 1024 , 1 ); // 2MB
235
+ memcpy (mkTextUpdate , mkText , exListStartIndex );
236
+ // TODO: Update required lines...
237
+ //SaveFileText(TextFormat("%s/Makefile", exBasePath), mkTextUpdate);
238
+ UnloadFileText (mkText );
239
+ RL_FREE (mkTextUpdate );
240
+
226
241
// Edit: raylib/examples/Makefile.Web --> Add new example
227
- // Edit: raylib/examples/README.md --> Add new example
228
242
243
+ // Edit: raylib/examples/README.md --> Add new example
244
+ // TODO: Use [examples_list.txt] to update/regen README.md
245
+
229
246
// Create: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
230
- // Edit: raylib/projects/VS2022/raylib.sln --> Add new example
247
+ FileCopy (TextFormat ("%s/../projects/VS2022/examples/core_basic_window.vcxproj" , exBasePath ),
248
+ TextFormat ("%s/../projects/VS2022/examples/%s.vcxproj" , exBasePath , exName ));
249
+ FileTextReplace (, "core_basic_window" , exName );
250
+ FileTextReplace (, "..\..\examples\core" , TextFormat ("..\..\examples\%s" , exCategory ));
251
+
252
+ // Edit: raylib/projects/VS2022/raylib.sln --> Add new example project
253
+ system (TextFormat ("dotnet solution raylib.sln add %s/../projects/VS2022/examples/%s.vcxproj" , exBasePath , exName ));
254
+
231
255
// Edit: raylib.com/common/examples.js --> Add new example
256
+ //Entries format: exampleEntry('⭐️☆☆☆' , 'core' , 'basic_window'),
257
+ char * jsText = LoadFileText (TextFormat ("%s/../common/examples.js" , exWebPath ));
258
+ int exListStartIndex = TextFindIndex (jsText , "//EXAMPLE_DATA_LIST_START" );
259
+ int exListEndIndex = TextFindIndex (jsText , "//EXAMPLE_DATA_LIST_END" );
260
+
261
+ UnloadFileText (jsText );
232
262
263
+ // Recompile example (on raylib side)
264
+ // NOTE: Tools requirements: emscripten, w64devkit
233
265
// Compile to: raylib.com/examples/<category>/<category>_example_name.html
234
266
// Compile to: raylib.com/examples/<category>/<category>_example_name.data
235
267
// Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
236
268
// Compile to: raylib.com/examples/<category>/<category>_example_name.js
237
-
238
- // Recompile example (on raylib side)
239
- // NOTE: Tools requirements: emscripten, w64devkit
240
269
system (TextFormat ("%s/../build_example_web.bat %s\%s" , exBasePath , exCategory , exName ));
241
270
242
271
// Copy results to web side
0 commit comments