Skip to content

Commit b01c8a7

Browse files
committed
UPDATE: Implementing examples commands -WIP-
1 parent a369056 commit b01c8a7

File tree

1 file changed

+58
-29
lines changed

1 file changed

+58
-29
lines changed

examples/rexm.c

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ static void SortStringsByName(char **items, int count);
111111
//------------------------------------------------------------------------------------
112112
int main(int argc, char *argv[])
113113
{
114-
// Examples path for building
114+
// Paths required for examples management
115115
// TODO: Avoid hardcoding path values...
116116
char *exBasePath = "C:/GitHub/raylib/examples";
117117
char *exWebPath = "C:/GitHub/raylib.com/examples";
118118
char *exTemplateFilePath = "C:/GitHub/raylib/examples/examples_template.c";
119+
char *exTemplateScreenshot = "C:/GitHub/raylib/examples/examples_template.png";
119120
char *exCollectionList = "C:/GitHub/raylib/examples/examples_list.txt";
120121

121-
char inFileName[1024] = { 0 }; // Example input filename
122+
char inFileName[1024] = { 0 }; // Example input filename (to be added)
122123

123124
char exName[64] = { 0 }; // Example name, without extension: core_basic_window
124125
char exCategory[32] = { 0 }; // Example category: core
@@ -146,7 +147,8 @@ int main(int argc, char *argv[])
146147
{
147148
// TODO: Additional security checks for file name?
148149

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, "_"));
150152
opCode = 1;
151153
}
152154
}
@@ -159,23 +161,28 @@ int main(int argc, char *argv[])
159161
{
160162
if (IsFileExtension(argv[2], ".c")) // Check for valid file extension: input
161163
{
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");
166172
}
167173
else LOG("WARNING: Input file extension not recognized (.c)\n");
168174
}
169175
}
170176
else if (strcmp(argv[1], "rename") == 0)
171177
{
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");
174179
else if (argc > 4) LOG("WARNING: Too many arguments provided\n");
175180
else
176181
{
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
179186
opCode = 3;
180187
}
181188
}
@@ -186,57 +193,79 @@ int main(int argc, char *argv[])
186193
else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
187194
else
188195
{
189-
strcpy(inFileName, argv[2]); // Register filename for removal
196+
strcpy(exName, argv[2]); // Register filename for removal
190197
opCode = 4;
191198
}
192199
}
193200
else if (strcmp(argv[1], "validate") == 0)
194201
{
195-
opCode = 5;
202+
opCode = 5;
196203
}
197204
}
198205

199206
switch (opCode)
200207
{
201208
case 1: // Create: New example from template
202209
{
203-
// Copy template file as new example
210+
// Create: raylib/examples/<category>/<category>_example_name.c
204211
FileCopy(exTemplateFilePath, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
205212
}
206213
case 2: // Add: Example from command-line input filename
207214
{
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-
//--------------------------------------------------------------------------------
215215
// Create: raylib/examples/<category>/<category>_example_name.c
216+
if (opCode != 1) FileCopy(inFileName, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
217+
216218
// 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!
219220

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
221226

222227
// TODO: Update the required files to add new example in the required position (ordered by category and name),
223228
// it could require some logic to make it possible...
224229

225230
// 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+
226241
// Edit: raylib/examples/Makefile.Web --> Add new example
227-
// Edit: raylib/examples/README.md --> Add new example
228242

243+
// Edit: raylib/examples/README.md --> Add new example
244+
// TODO: Use [examples_list.txt] to update/regen README.md
245+
229246
// 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+
231255
// 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);
232262

263+
// Recompile example (on raylib side)
264+
// NOTE: Tools requirements: emscripten, w64devkit
233265
// Compile to: raylib.com/examples/<category>/<category>_example_name.html
234266
// Compile to: raylib.com/examples/<category>/<category>_example_name.data
235267
// Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
236268
// Compile to: raylib.com/examples/<category>/<category>_example_name.js
237-
238-
// Recompile example (on raylib side)
239-
// NOTE: Tools requirements: emscripten, w64devkit
240269
system(TextFormat("%s/../build_example_web.bat %s\%s", exBasePath, exCategory, exName));
241270

242271
// Copy results to web side

0 commit comments

Comments
 (0)