mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 03:18:14 +00:00
UPDATE: Implementing examples commands -WIP-
This commit is contained in:
@@ -111,14 +111,15 @@ static void SortStringsByName(char **items, int count);
|
|||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// Examples path for building
|
// Paths required for examples management
|
||||||
// TODO: Avoid hardcoding path values...
|
// TODO: Avoid hardcoding path values...
|
||||||
char *exBasePath = "C:/GitHub/raylib/examples";
|
char *exBasePath = "C:/GitHub/raylib/examples";
|
||||||
char *exWebPath = "C:/GitHub/raylib.com/examples";
|
char *exWebPath = "C:/GitHub/raylib.com/examples";
|
||||||
char *exTemplateFilePath = "C:/GitHub/raylib/examples/examples_template.c";
|
char *exTemplateFilePath = "C:/GitHub/raylib/examples/examples_template.c";
|
||||||
|
char *exTemplateScreenshot = "C:/GitHub/raylib/examples/examples_template.png";
|
||||||
char *exCollectionList = "C:/GitHub/raylib/examples/examples_list.txt";
|
char *exCollectionList = "C:/GitHub/raylib/examples/examples_list.txt";
|
||||||
|
|
||||||
char inFileName[1024] = { 0 }; // Example input filename
|
char inFileName[1024] = { 0 }; // Example input filename (to be added)
|
||||||
|
|
||||||
char exName[64] = { 0 }; // Example name, without extension: core_basic_window
|
char exName[64] = { 0 }; // Example name, without extension: core_basic_window
|
||||||
char exCategory[32] = { 0 }; // Example category: core
|
char exCategory[32] = { 0 }; // Example category: core
|
||||||
@@ -146,7 +147,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// TODO: Additional security checks for file name?
|
// TODO: Additional security checks for file name?
|
||||||
|
|
||||||
strcpy(inFileName, argv[2]); // Register filename for creation
|
strcpy(exName, argv[2]); // Register filename for new example creation
|
||||||
|
strncpy(exCategory, exName, TextFindIndex(exName, "_"));
|
||||||
opCode = 1;
|
opCode = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,23 +161,28 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
if (IsFileExtension(argv[2], ".c")) // Check for valid file extension: input
|
if (IsFileExtension(argv[2], ".c")) // Check for valid file extension: input
|
||||||
{
|
{
|
||||||
// TODO: Parse category name from filename provided!
|
if (FileExists(inFileName))
|
||||||
|
{
|
||||||
strcpy(inFileName, argv[2]); // Register filename for creation
|
strcpy(inFileName, argv[2]); // Register filename for addition
|
||||||
|
strcpy(exName, GetFileNameWithoutExt(argv[2])); // Register example name
|
||||||
|
strncpy(exCategory, exName, TextFindIndex(exName, "_"));
|
||||||
opCode = 2;
|
opCode = 2;
|
||||||
}
|
}
|
||||||
|
else LOG("WARNING: Input file not found, include path\n");
|
||||||
|
}
|
||||||
else LOG("WARNING: Input file extension not recognized (.c)\n");
|
else LOG("WARNING: Input file extension not recognized (.c)\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(argv[1], "rename") == 0)
|
else if (strcmp(argv[1], "rename") == 0)
|
||||||
{
|
{
|
||||||
if (argc == 2) LOG("WARNING: No filename provided to create\n");
|
if (argc == 2) LOG("WARNING: No filename provided to be renamed\n");
|
||||||
else if (argc == 3) LOG("WARNING: No enough arguments provided\n");
|
|
||||||
else if (argc > 4) LOG("WARNING: Too many arguments provided\n");
|
else if (argc > 4) LOG("WARNING: Too many arguments provided\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Register exName, exCategory and exRename
|
strcpy(exName, argv[2]); // Register example name
|
||||||
|
strncpy(exCategory, exName, TextFindIndex(exName, "_"));
|
||||||
|
strcpy(exRename, argv[3]);
|
||||||
|
// TODO: Consider rename with change of category
|
||||||
opCode = 3;
|
opCode = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +193,7 @@ int main(int argc, char *argv[])
|
|||||||
else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
|
else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(inFileName, argv[2]); // Register filename for removal
|
strcpy(exName, argv[2]); // Register filename for removal
|
||||||
opCode = 4;
|
opCode = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,43 +207,65 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
case 1: // Create: New example from template
|
case 1: // Create: New example from template
|
||||||
{
|
{
|
||||||
// Copy template file as new example
|
// Create: raylib/examples/<category>/<category>_example_name.c
|
||||||
FileCopy(exTemplateFilePath, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
|
FileCopy(exTemplateFilePath, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
|
||||||
}
|
}
|
||||||
case 2: // Add: Example from command-line input filename
|
case 2: // Add: Example from command-line input filename
|
||||||
{
|
{
|
||||||
if ((opCode != 1) && FileExists(inFileName))
|
|
||||||
{
|
|
||||||
FileCopy(inFileName, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate all required files
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
// Create: raylib/examples/<category>/<category>_example_name.c
|
// Create: raylib/examples/<category>/<category>_example_name.c
|
||||||
// Create: raylib/examples/<category>/<category>_example_name.png
|
if (opCode != 1) FileCopy(inFileName, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
|
||||||
FileCopy("C:/GitHub/raylib/examples/examples_template.png",
|
|
||||||
TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName)); // To be updated manually!
|
|
||||||
|
|
||||||
// Copy: raylib/examples/<category>/resources/*.* ---> To be updated manually!
|
// Create: raylib/examples/<category>/<category>_example_name.png
|
||||||
|
FileCopy(exTemplateScreenshot, TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName)); // WARNING: To be updated manually!
|
||||||
|
|
||||||
|
// Copy: raylib/examples/<category>/resources/... // WARNING: To be updated manually!
|
||||||
|
|
||||||
|
// Check if example is already listed
|
||||||
|
|
||||||
|
// If not, add to the main examples_list
|
||||||
|
|
||||||
// TODO: Update the required files to add new example in the required position (ordered by category and name),
|
// TODO: Update the required files to add new example in the required position (ordered by category and name),
|
||||||
// it could require some logic to make it possible...
|
// it could require some logic to make it possible...
|
||||||
|
|
||||||
// Edit: raylib/examples/Makefile --> Add new example
|
// Edit: raylib/examples/Makefile --> Add new example
|
||||||
|
char *mkText = LoadFileText(TextFormat("%s/Makefile", exBasePath));
|
||||||
|
int exListStartIndex = TextFindIndex(mkText, "#EXAMPLES_LIST_START");
|
||||||
|
int exListEndIndex = TextFindIndex(mkText, "#EXAMPLES_LIST_END");
|
||||||
|
char *mkTextUpdate = (char *)RL_CALLOC(2*1024*1024, 1); // 2MB
|
||||||
|
memcpy(mkTextUpdate, mkText, exListStartIndex);
|
||||||
|
// TODO: Update required lines...
|
||||||
|
//SaveFileText(TextFormat("%s/Makefile", exBasePath), mkTextUpdate);
|
||||||
|
UnloadFileText(mkText);
|
||||||
|
RL_FREE(mkTextUpdate);
|
||||||
|
|
||||||
// Edit: raylib/examples/Makefile.Web --> Add new example
|
// Edit: raylib/examples/Makefile.Web --> Add new example
|
||||||
|
|
||||||
// Edit: raylib/examples/README.md --> Add new example
|
// Edit: raylib/examples/README.md --> Add new example
|
||||||
|
// TODO: Use [examples_list.txt] to update/regen README.md
|
||||||
|
|
||||||
// Create: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
|
// Create: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
|
||||||
// Edit: raylib/projects/VS2022/raylib.sln --> Add new example
|
FileCopy(TextFormat("%s/../projects/VS2022/examples/core_basic_window.vcxproj", exBasePath),
|
||||||
// Edit: raylib.com/common/examples.js --> Add new example
|
TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
|
||||||
|
FileTextReplace(, "core_basic_window", exName);
|
||||||
|
FileTextReplace(, "..\..\examples\core", TextFormat("..\..\examples\%s", exCategory));
|
||||||
|
|
||||||
|
// Edit: raylib/projects/VS2022/raylib.sln --> Add new example project
|
||||||
|
system(TextFormat("dotnet solution raylib.sln add %s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
|
||||||
|
|
||||||
|
// Edit: raylib.com/common/examples.js --> Add new example
|
||||||
|
//Entries format: exampleEntry('⭐️☆☆☆' , 'core' , 'basic_window'),
|
||||||
|
char *jsText = LoadFileText(TextFormat("%s/../common/examples.js", exWebPath));
|
||||||
|
int exListStartIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_START");
|
||||||
|
int exListEndIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_END");
|
||||||
|
|
||||||
|
UnloadFileText(jsText);
|
||||||
|
|
||||||
|
// Recompile example (on raylib side)
|
||||||
|
// NOTE: Tools requirements: emscripten, w64devkit
|
||||||
// Compile to: raylib.com/examples/<category>/<category>_example_name.html
|
// Compile to: raylib.com/examples/<category>/<category>_example_name.html
|
||||||
// Compile to: raylib.com/examples/<category>/<category>_example_name.data
|
// Compile to: raylib.com/examples/<category>/<category>_example_name.data
|
||||||
// Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
|
// Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
|
||||||
// Compile to: raylib.com/examples/<category>/<category>_example_name.js
|
// Compile to: raylib.com/examples/<category>/<category>_example_name.js
|
||||||
|
|
||||||
// Recompile example (on raylib side)
|
|
||||||
// NOTE: Tools requirements: emscripten, w64devkit
|
|
||||||
system(TextFormat("%s/../build_example_web.bat %s\%s", exBasePath, exCategory, exName));
|
system(TextFormat("%s/../build_example_web.bat %s\%s", exBasePath, exCategory, exName));
|
||||||
|
|
||||||
// Copy results to web side
|
// Copy results to web side
|
||||||
|
Reference in New Issue
Block a user