diff --git a/.vscode/settings.json b/.vscode/settings.json index b5601daaa..c71a2653d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,62 @@ { "files.associations": { "*.mdx": "markdown" - } + }, + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false } \ No newline at end of file diff --git a/public/usage-examples/json/data_driven_dungeon-1-example-oop.cs b/public/usage-examples/json/data_driven_dungeon-1-example-oop.cs new file mode 100644 index 000000000..ab11c4b37 --- /dev/null +++ b/public/usage-examples/json/data_driven_dungeon-1-example-oop.cs @@ -0,0 +1,79 @@ +using System; +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +namespace DataDrivenDungeon +{ + public class DungeonManager + { + private Json _levelData; + + public DungeonManager(string fileName) + { + _levelData = JsonFromFile(fileName); + } + + public string LevelName => JsonReadString(_levelData, "level_name"); + public int Difficulty => JsonReadInteger(_levelData, "difficulty"); + public string Theme => JsonReadString(_levelData, "theme"); + + public void Draw() + { + ClearScreen(ColorBlack()); + DrawText($"Level: {LevelName}", ColorWhite(), 20, 20); + DrawText($"Difficulty: {Difficulty}", ColorWhite(), 20, 40); + DrawText($"Theme: {Theme}", ColorWhite(), 20, 60); + + // Accessing the 'spawn_points' array and looping through objects + Json spawnPoints = JsonReadArray(_levelData, "spawn_points"); + for (int i = 0; i < JsonArraySize(spawnPoints); i++) + { + Json entry = JsonReadObjectAtIndex(spawnPoints, i); + string entryType = JsonReadString(entry, "type"); + double x = JsonReadNumber(entry, "x"); + double y = JsonReadNumber(entry, "y"); + + Color drawColor = (entryType == "Player") ? ColorGreen() : ColorRed(); + FillRectangle(drawColor, x, y, 32, 32); + DrawText(entryType, ColorWhite(), (float)x, (float)y - 15); + } + + // Accessing the 'loot' array + Json lootPoints = JsonReadArray(_levelData, "loot"); + for (int i = 0; i < JsonArraySize(lootPoints); i++) + { + Json item = JsonReadObjectAtIndex(lootPoints, i); + string lootName = JsonReadString(item, "item"); + double x = JsonReadNumber(item, "x"); + double y = JsonReadNumber(item, "y"); + + FillCircle(ColorGold(), (float)x, (float)y, 8); + DrawText(lootName, ColorGold(), (float)x - 20, (float)y - 20); + } + } + + public void Cleanup() + { + FreeJson(_levelData); + } + } + + public class Program + { + public static void Main() + { + DungeonManager dungeon = new DungeonManager("level_data.json"); + OpenWindow($"Dungeon Navigator: {dungeon.LevelName}", 800, 600); + + while (!QuitRequested()) + { + ProcessEvents(); + dungeon.Draw(); + RefreshScreen(60); + } + + dungeon.Cleanup(); + CloseAllWindows(); + } + } +} diff --git a/public/usage-examples/json/data_driven_dungeon-1-example-top-level.cs b/public/usage-examples/json/data_driven_dungeon-1-example-top-level.cs new file mode 100644 index 000000000..8113fe281 --- /dev/null +++ b/public/usage-examples/json/data_driven_dungeon-1-example-top-level.cs @@ -0,0 +1,54 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Data-Driven dungeon loading logic +Json levelInfo = JsonFromFile("level_data.json"); + +// Access strings and ints +string levelName = JsonReadString(levelInfo, "level_name"); +int difficulty = JsonReadInteger(levelInfo, "difficulty"); +string theme = JsonReadString(levelInfo, "theme"); + +OpenWindow($"Dungeon: {levelName}", 800, 600); + +while (!QuitRequested()) +{ + ProcessEvents(); + ClearScreen(ColorBlack()); + + DrawText($"Level Name: {levelName}", ColorWhite(), 20, 20); + DrawText($"Difficulty: {difficulty}", ColorWhite(), 20, 40); + DrawText($"Theme: {theme}", ColorWhite(), 20, 60); + + // Reading nested objects from an array + Json spawnPoints = JsonReadArray(levelInfo, "spawn_points"); + for (int i = 0; i < JsonArraySize(spawnPoints); i++) + { + Json entry = JsonReadObjectAtIndex(spawnPoints, i); + string type = JsonReadString(entry, "type"); + double x = JsonReadNumber(entry, "x"); + double y = JsonReadNumber(entry, "y"); + + Color drawColor = (type == "Player") ? ColorGreen() : ColorRed(); + FillRectangle(drawColor, x, y, 32, 32); + DrawText(type, ColorWhite(), (float)x, (float)y - 15); + } + + // Reading loot points + Json lootItems = JsonReadArray(levelInfo, "loot"); + for (int i = 0; i < JsonArraySize(lootItems); i++) + { + Json item = JsonReadObjectAtIndex(lootItems, i); + string itemName = JsonReadString(item, "item"); + double x = JsonReadNumber(item, "x"); + double y = JsonReadNumber(item, "y"); + + FillCircle(ColorGold(), (float)x, (float)y, 8); + DrawText(itemName, ColorGold(), (float)x - 20, (float)y - 20); + } + + RefreshScreen(60); +} + +FreeJson(levelInfo); +CloseAllWindows(); diff --git a/public/usage-examples/json/data_driven_dungeon-1-example.cpp b/public/usage-examples/json/data_driven_dungeon-1-example.cpp new file mode 100644 index 000000000..143ae0034 --- /dev/null +++ b/public/usage-examples/json/data_driven_dungeon-1-example.cpp @@ -0,0 +1,62 @@ +#include "splashkit.h" + +int main() +{ + // Load the dungeon room data from the JSON file + json level_info = json_from_file("level_data.json"); + + // Reading top-level strings and integers + string level_name = json_read_string(level_info, "level_name"); + int difficulty = json_read_number_as_int(level_info, "difficulty"); + string theme = json_read_string(level_info, "theme"); + + open_window("Data-Driven Dungeon: " + level_name, 800, 600); + + while (!quit_requested()) + { + process_events(); + clear_screen(color_black()); + + // Display Dungeon metadata + draw_text("Level: " + level_name, color_white(), 20, 20); + draw_text("Difficulty: " + std::to_string(difficulty), color_white(), 20, 40); + draw_text("Theme: " + theme, color_white(), 20, 60); + + // Accessing the 'spawn_points' array and looping through objects + vector spawn_points; + json_read_array(level_info, "spawn_points", spawn_points); + for (int i = 0; i < spawn_points.size(); i++) + { + json entry = spawn_points[i]; + string entity_type = json_read_string(entry, "type"); + double x = json_read_number(entry, "x"); + double y = json_read_number(entry, "y"); + + color draw_color = (entity_type == "Player") ? color_green() : color_red(); + fill_rectangle(draw_color, x, y, 32, 32); + draw_text(entity_type, color_white(), x, y - 15); + } + + // Create loot sprites based on the loot array in the JSON + vector loot_list; + json_read_array(level_info, "loot", loot_list); + for (int i = 0; i < loot_list.size(); i++) + { + json item = loot_list[i]; + string item_name = json_read_string(item, "item"); + double x = json_read_number(item, "x"); + double y = json_read_number(item, "y"); + + fill_circle(color_gold(), x, y, 8); + draw_text(item_name, color_gold(), x - 20, y - 20); + } + + refresh_screen(60); + } + + // Clean up + free_json(level_info); + close_all_windows(); + + return 0; +} diff --git a/public/usage-examples/json/data_driven_dungeon-1-example.png b/public/usage-examples/json/data_driven_dungeon-1-example.png new file mode 100644 index 000000000..51b313cba Binary files /dev/null and b/public/usage-examples/json/data_driven_dungeon-1-example.png differ diff --git a/public/usage-examples/json/data_driven_dungeon-1-example.py b/public/usage-examples/json/data_driven_dungeon-1-example.py new file mode 100644 index 000000000..9c3c7fb38 --- /dev/null +++ b/public/usage-examples/json/data_driven_dungeon-1-example.py @@ -0,0 +1,52 @@ +from splashkit import * + +def main(): + # Load the JSON file + level_info = json_from_file("level_data.json") + + # Read basic data fields + level_name = json_read_string(level_info, "level_name") + difficulty = json_read_integer(level_info, "difficulty") + theme = json_read_string(level_info, "theme") + + open_window(f"Data-Driven Dungeon: {level_name}", 800, 600) + + while not quit_requested(): + process_events() + clear_screen(color_black()) + + # Display metadata on screen + draw_text(f"Level Name: {level_name}", color_white(), 20, 20) + draw_text(f"Difficulty Score: {difficulty}", color_white(), 20, 40) + draw_text(f"Dungeon Theme: {theme}", color_white(), 20, 60) + + # Access arrays and objects nested inside the JSON + spawn_points = json_read_array(level_info, "spawn_points") + for i in range(json_array_size(spawn_points)): + entry = json_read_object_at_index(spawn_points, i) + entity_type = json_read_string(entry, "type") + x = json_read_number(entry, "x") + y = json_read_number(entry, "y") + + draw_color = color_green() if entity_type == "Player" else color_red() + fill_rectangle(draw_color, x, y, 32, 32) + draw_text(entity_type, color_white(), x, y - 15) + + # Iterate through loot array + loot_items = json_read_array(level_info, "loot") + for i in range(json_array_size(loot_items)): + item = json_read_object_at_index(loot_items, i) + item_name = json_read_string(item, "item") + x = json_read_number(item, "x") + y = json_read_number(item, "y") + + fill_circle(color_gold(), x, y, 8) + draw_text(item_name, color_gold(), x - 20, y - 20) + + refresh_screen_with_target_fps(60) + + # Note: free_json(level_info) is implicitly handled in splashkit-python wrapper but explicit cleanup is good practice + close_all_windows() + +if __name__ == "__main__": + main() diff --git a/public/usage-examples/json/data_driven_dungeon-1-example.txt b/public/usage-examples/json/data_driven_dungeon-1-example.txt new file mode 100644 index 000000000..3233e6d0a --- /dev/null +++ b/public/usage-examples/json/data_driven_dungeon-1-example.txt @@ -0,0 +1 @@ +Data-Driven Dungeon Integration Example diff --git a/public/usage-examples/json/level_data.json b/public/usage-examples/json/level_data.json new file mode 100644 index 000000000..5e0a6a7db --- /dev/null +++ b/public/usage-examples/json/level_data.json @@ -0,0 +1,16 @@ +{ + "level_name": "Skeleton Crypt", + "difficulty": 2, + "theme": "Gothic", + "dungeon_width": 800, + "dungeon_height": 600, + "spawn_points": [ + {"type": "Player", "x": 100, "y": 100}, + {"type": "Skeleton", "x": 400, "y": 300}, + {"type": "Skeleton", "x": 600, "y": 450} + ], + "loot": [ + {"item": "Health Potion", "x": 150, "y": 120}, + {"item": "Rusty Key", "x": 750, "y": 50} + ] +} diff --git a/scripts/json-files/api.json b/scripts/json-files/api.json index c0ac71b90..a7b1968e1 100644 --- a/scripts/json-files/api.json +++ b/scripts/json-files/api.json @@ -53363,6 +53363,38 @@ "brief": "SplashKit Json allows you to create and read JSON objects.", "description": "Splashkit's JSON library allows you to easily create or read JSON objects and\nmanipulate them to/from a JSON string or from a file containing a JSON\nstring. Create a new JSON object with a call to `create_json()` and\nread or write data to it by calling methods like\n`json_add_string(json j, string key, string value)` and\n`json_read_string(json j, string key)`.", "functions": [ + { + "signature": "json data_driven_dungeon();", + "name": "data_driven_dungeon", + "description": "Demonstrates loading a dungeon level from a JSON file, including parsing arrays of objects for spawn points and loot items.", + "brief": "Data-Driven Dungeon Integration Example", + "unique_global_name": "data_driven_dungeon", + "group": "json", + "static": "json", + "parameters": {}, + "return": { + "type": "json", + "description": "Returns a json object.", + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "attributes": { + "group": "json", + "static": "json" + }, + "signatures": { + "python": [ + "def data_driven_dungeon();" + ], + "cpp": [ + "json data_driven_dungeon()" + ], + "csharp": [], + "pascal": [] + } + }, { "signature": "json create_json();", "name": "create_json", @@ -63274,6 +63306,38 @@ "brief": "SplashKit Collisions library allow you to perform tests between\nbitmaps, sprites and shapes to determin if a collision has occured.Provides matrix functions to work on 2d coordinates.Provides vector functions to work on vectors.", "description": "", "functions": [ + { + "signature": "void celestial_mechanics();", + "name": "celestial_mechanics", + "description": "Orbital mechanics example demonstrating N-body gravity simulation with planetary bodies.", + "brief": "Celestial Mechanics Integration Example", + "unique_global_name": "celestial_mechanics", + "group": "physics", + "static": "physics", + "parameters": {}, + "return": { + "type": "void", + "description": "N/A", + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "attributes": { + "group": "physics", + "static": "physics" + }, + "signatures": { + "python": [ + "def celestial_mechanics():" + ], + "cpp": [ + "void celestial_mechanics()" + ], + "csharp": [], + "pascal": [] + } + }, { "signature": "bool bitmap_circle_collision(bitmap bmp,const point_2d &pt,const circle &circ);", "name": "bitmap_circle_collision", diff --git a/scripts/json-files/guides-groups.json b/scripts/json-files/guides-groups.json index 7fe7bccde..36a7e3fb5 100644 --- a/scripts/json-files/guides-groups.json +++ b/scripts/json-files/guides-groups.json @@ -2,9 +2,9 @@ "animations", "audio", "beyond-splashkit", - "camera", + "Camera", "color", - "graphics", + "Graphics", "input", "interface", "json", diff --git a/scripts/json-files/usage-example-references.json b/scripts/json-files/usage-example-references.json index c41688ec6..8728c0e53 100644 --- a/scripts/json-files/usage-example-references.json +++ b/scripts/json-files/usage-example-references.json @@ -2,7 +2,7 @@ "audio": [ { "funcKey": "play_music_named", - "title": "Music Playback", + "title": "Music Playback\r", "url": "/api/audio/#play-music-named", "functions": [ "audio_ready", @@ -14,7 +14,7 @@ }, { "funcKey": "resume_music", - "title": "Pausing and Resuming Game Music", + "title": "Pausing and Resuming Game Music\r", "url": "/api/audio/#resume-music", "functions": [ "audio_ready", @@ -38,6 +38,31 @@ ] } ], + "color": [ + { + "funcKey": "saturation_of", + "title": "Draws a rectangle in a random colour. The colour's saturation value is displayed on screen", + "url": "/api/color/#saturation-of", + "functions": [ + "open_window", + "random_rgb_color", + "round", + "rectangle_from", + "clear_screen", + "color_white", + "fill_rectangle_record", + "draw_text_no_font_no_size", + "color_black", + "red_of", + "green_of", + "blue_of", + "alpha_of", + "refresh_screen", + "delay", + "close_all_windows" + ] + } + ], "geometry": [ { "funcKey": "center_point", @@ -142,7 +167,7 @@ }, { "funcKey": "closest_point_on_circle", - "title": "Closest Point to Mouse on Circle", + "title": "Closest Point to Mouse on Circle\r", "url": "/api/geometry/#closest-point-on-circle", "functions": [ "open_window", @@ -161,6 +186,25 @@ "close_all_windows" ] }, + { + "funcKey": "lines_intersect", + "title": "Simple Line Intersect Check", + "url": "/api/geometry/#lines-intersect", + "functions": [ + "open_window", + "Point2D", + "line_from_point_to_point", + "draw_line_record", + "color_red", + "draw_text_no_font_no_size", + "color_black", + "color_blue", + "color_green", + "refresh_screen", + "delay", + "close_all_windows" + ] + }, { "funcKey": "line_intersects_rect", "title": "Avoid the Rectangle", @@ -256,25 +300,6 @@ "close_all_windows" ] }, - { - "funcKey": "lines_intersect", - "title": "Simple Line Intersect Check", - "url": "/api/geometry/#lines-intersect", - "functions": [ - "open_window", - "Point2D", - "line_from_point_to_point", - "draw_line_record", - "color_red", - "draw_text_no_font_no_size", - "color_black", - "color_blue", - "color_green", - "refresh_screen", - "delay", - "close_all_windows" - ] - }, { "funcKey": "point_at", "title": "Flower Grid", @@ -312,7 +337,7 @@ { "funcKey": "point_in_circle", "title": "Mouse in a Circle", - "url": "/api/geometry/#point-in-circle", + "url": "/api/geometry/#point-in-circle-functions", "functions": [ "open_window", "circle_at_from_points", @@ -331,7 +356,7 @@ { "funcKey": "point_in_rectangle", "title": "Cursor Jail", - "url": "/api/geometry/#point-in-rectangle", + "url": "/api/geometry/#point-in-rectangle-functions", "functions": [ "rectangle_from", "create_timer", @@ -377,7 +402,7 @@ { "funcKey": "point_on_line", "title": "Mouse Point On Line?", - "url": "/api/geometry/#point-on-line", + "url": "/api/geometry/#point-on-line-functions", "functions": [ "line_from", "open_window", @@ -508,7 +533,7 @@ }, { "funcKey": "random_window_point", - "title": "Random Portals", + "title": "Random Portals\r", "url": "/api/geometry/#random-window-point", "functions": [ "open_window", @@ -524,6 +549,32 @@ "close_window" ] }, + { + "funcKey": "rectangle_around", + "title": "A perpetually moving circle which increases and decreases in size, surrounded by a rectangle shape", + "url": "/api/geometry/#rectangle-around-functions", + "functions": [ + "open_window", + "create_timer", + "start_timer", + "quit_requested", + "point_at", + "cosine", + "sine", + "circle_at", + "timer_ticks", + "reset_timer", + "process_events", + "clear_screen_to_white", + "draw_rectangle_record", + "color_black", + "rectangle_around_circle", + "fill_circle_record", + "color_red", + "refresh_screen", + "close_all_windows" + ] + }, { "funcKey": "same_point", "title": "Point 2D Guessing Game", @@ -561,10 +612,28 @@ "close_all_windows" ] }, + { + "funcKey": "bitmap_center", + "title": "Draw a bitmap with a red dot at its center\r", + "url": "/api/graphics/#bitmap-center", + "functions": [ + "open_window", + "load_bitmap", + "clear_screen", + "color_white", + "draw_bitmap", + "fill_circle_record", + "color_red", + "circle_at", + "refresh_screen", + "delay", + "close_all_windows" + ] + }, { "funcKey": "clear_screen", "title": "Background Color", - "url": "/api/graphics/#clear-screen", + "url": "/api/graphics/#clear-screen-functions", "functions": [ "open_window", "color_blue", @@ -575,7 +644,7 @@ }, { "funcKey": "draw_bitmap_named", - "title": "SplashKit Logo", + "title": "SplashKit Logo\r", "url": "/api/graphics/#draw-bitmap-named", "functions": [ "open_window", @@ -597,10 +666,30 @@ "SplashKit" ] }, + { + "funcKey": "draw_circle", + "title": "Circle Showcase\r", + "url": "/api/graphics/#draw-circle-functions", + "functions": [ + "open_window", + "clear_screen", + "color_white", + "fill_circle", + "color_red", + "color_blue", + "color_green", + "color_orange", + "color_purple", + "random_rgb_color", + "refresh_screen", + "delay", + "close_all_windows" + ] + }, { "funcKey": "draw_circle_on_bitmap", "title": "Creating a Red Planet", - "url": "/api/graphics/#draw-circle-on-bitmap", + "url": "/api/graphics/#draw-circle-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -621,7 +710,7 @@ { "funcKey": "draw_circle_on_window", "title": "Bubbles", - "url": "/api/graphics/#draw-circle-on-window", + "url": "/api/graphics/#draw-circle-on-window-functions", "functions": [ "open_window", "clear_screen", @@ -655,7 +744,7 @@ { "funcKey": "draw_ellipse", "title": "Radiating Wave", - "url": "/api/graphics/#draw-ellipse", + "url": "/api/graphics/#draw-ellipse-functions", "functions": [ "open_window", "clear_screen", @@ -669,7 +758,7 @@ { "funcKey": "draw_line", "title": "Colourful Starburst", - "url": "/api/graphics/#draw-line", + "url": "/api/graphics/#draw-line-functions", "functions": [ "open_window", "clear_screen", @@ -691,7 +780,7 @@ { "funcKey": "draw_line_on_bitmap", "title": "Drawing a Route on a Map", - "url": "/api/graphics/#draw-line-on-bitmap", + "url": "/api/graphics/#draw-line-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -712,7 +801,7 @@ { "funcKey": "draw_line_on_window", "title": "Basic Line Drawing", - "url": "/api/graphics/#draw-line-on-window", + "url": "/api/graphics/#draw-line-on-window-functions", "functions": [ "open_window", "clear_screen", @@ -734,7 +823,7 @@ { "funcKey": "draw_pixel", "title": "Cursor Trail", - "url": "/api/graphics/#draw-pixel", + "url": "/api/graphics/#draw-pixel-functions", "functions": [ "point_at", "color_blue", @@ -756,7 +845,7 @@ { "funcKey": "draw_quad", "title": "Ninja Star", - "url": "/api/graphics/#draw-quad", + "url": "/api/graphics/#draw-quad-functions", "functions": [ "quad_from", "open_window", @@ -774,7 +863,7 @@ { "funcKey": "draw_quad_on_bitmap", "title": "3D Cube", - "url": "/api/graphics/#draw-quad-on-bitmap", + "url": "/api/graphics/#draw-quad-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -794,7 +883,7 @@ { "funcKey": "draw_quad_on_window", "title": "Halved Ninja Star", - "url": "/api/graphics/#draw-quad-on-window", + "url": "/api/graphics/#draw-quad-on-window-functions", "functions": [ "quad_from", "open_window", @@ -814,7 +903,7 @@ { "funcKey": "draw_rectangle", "title": "Rectangle Staircase", - "url": "/api/graphics/#draw-rectangle", + "url": "/api/graphics/#draw-rectangle-functions", "functions": [ "open_window", "clear_screen", @@ -828,7 +917,7 @@ { "funcKey": "draw_triangle", "title": "Triangle Coordinates", - "url": "/api/graphics/#draw-triangle", + "url": "/api/graphics/#draw-triangle-functions", "functions": [ "open_window", "clear_screen_to_white", @@ -847,7 +936,7 @@ { "funcKey": "draw_triangle_on_bitmap", "title": "Mountain Peaks", - "url": "/api/graphics/#draw-triangle-on-bitmap", + "url": "/api/graphics/#draw-triangle-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -866,7 +955,7 @@ { "funcKey": "draw_triangle_on_window", "title": "Colourful Bunting Flags", - "url": "/api/graphics/#draw-triangle-on-window", + "url": "/api/graphics/#draw-triangle-on-window-functions", "functions": [ "open_window", "clear_screen", @@ -880,7 +969,7 @@ { "funcKey": "fill_circle", "title": "Basic Blue Circle", - "url": "/api/graphics/#fill-circle", + "url": "/api/graphics/#fill-circle-functions", "functions": [ "open_window", "clear_screen", @@ -894,7 +983,7 @@ { "funcKey": "fill_circle_on_bitmap", "title": "Rainbow Caterpillar", - "url": "/api/graphics/#fill-circle-on-bitmap", + "url": "/api/graphics/#fill-circle-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -920,7 +1009,7 @@ { "funcKey": "fill_circle_on_window", "title": "Traffic Lights", - "url": "/api/graphics/#fill-circle-on-window", + "url": "/api/graphics/#fill-circle-on-window-functions", "functions": [ "open_window", "clear_screen", @@ -936,7 +1025,7 @@ { "funcKey": "fill_ellipse", "title": "Basic Blue Ellipse", - "url": "/api/graphics/#fill-ellipse", + "url": "/api/graphics/#fill-ellipse-functions", "functions": [ "open_window", "clear_screen", @@ -955,7 +1044,7 @@ { "funcKey": "fill_ellipse_on_bitmap", "title": "Water Ripples", - "url": "/api/graphics/#fill-ellipse-on-bitmap", + "url": "/api/graphics/#fill-ellipse-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -973,7 +1062,7 @@ { "funcKey": "fill_quad", "title": "Coloured Star", - "url": "/api/graphics/#fill-quad", + "url": "/api/graphics/#fill-quad-functions", "functions": [ "quad_from", "open_window", @@ -991,7 +1080,7 @@ { "funcKey": "fill_quad_on_bitmap", "title": "Microsoft Windows Logo", - "url": "/api/graphics/#fill-quad-on-bitmap", + "url": "/api/graphics/#fill-quad-on-bitmap-functions", "functions": [ "open_window", "create_bitmap", @@ -1009,7 +1098,7 @@ { "funcKey": "fill_quad_on_window", "title": "Halved Coloured Star", - "url": "/api/graphics/#fill-quad-on-window", + "url": "/api/graphics/#fill-quad-on-window-functions", "functions": [ "quad_from", "open_window", @@ -1029,7 +1118,7 @@ { "funcKey": "fill_rectangle", "title": "Basic Blue Rectangle", - "url": "/api/graphics/#fill-rectangle", + "url": "/api/graphics/#fill-rectangle-functions", "functions": [ "open_window", "clear_screen_to_white", @@ -1041,8 +1130,8 @@ }, { "funcKey": "fill_rectangle_on_bitmap", - "title": "Cityscape", - "url": "/api/graphics/#fill-rectangle-on-bitmap", + "title": "Cityscape\r", + "url": "/api/graphics/#fill-rectangle-on-bitmap-functions", "functions": [ "open_window", "load_bitmap", @@ -1060,7 +1149,7 @@ { "funcKey": "fill_rectangle_on_window", "title": "Filled Rectangles on Separate Windows", - "url": "/api/graphics/#fill-rectangle-on-window", + "url": "/api/graphics/#fill-rectangle-on-window-functions", "functions": [ "open_window", "move_window_to", @@ -1100,7 +1189,7 @@ { "funcKey": "fill_triangle", "title": "Basic Red Triangle", - "url": "/api/graphics/#fill-triangle", + "url": "/api/graphics/#fill-triangle-functions", "functions": [ "open_window", "clear_screen_to_white", @@ -1112,8 +1201,8 @@ }, { "funcKey": "fill_triangle_on_bitmap", - "title": "Hooray! A Red Hat", - "url": "/api/graphics/#fill-triangle-on-bitmap", + "title": "Hooray! A Red Hat\r", + "url": "/api/graphics/#fill-triangle-on-bitmap-functions", "functions": [ "open_window", "emojis", @@ -1133,7 +1222,7 @@ { "funcKey": "fill_triangle_on_window", "title": "Filled Triangles on Separate Windows", - "url": "/api/graphics/#fill-triangle-on-window", + "url": "/api/graphics/#fill-triangle-on-window-functions", "functions": [ "open_window", "move_window_to", @@ -1172,7 +1261,7 @@ }, { "funcKey": "free_font", - "title": "Freeing Fonts", + "title": "Freeing Fonts\r", "url": "/api/graphics/#free-font", "functions": [ "open_window", @@ -1189,10 +1278,29 @@ "close_all_windows" ] }, + { + "funcKey": "get_font_style", + "title": "The program automatically cycles through font styles for a given font (also displaying example text), with the numerical value of each style being shown on screen\r", + "url": "/api/graphics/#get-font-style-functions", + "functions": [ + "open_window", + "font_named", + "quit_requested", + "process_events", + "set_font_style", + "clear_screen_to_white", + "draw_text_no_font_no_size", + "color_black", + "draw_text", + "refresh_screen", + "delay", + "close_all_windows" + ] + }, { "funcKey": "has_font", "title": "Checking for Font using Variable", - "url": "/api/graphics/#has-font", + "url": "/api/graphics/#has-font-functions", "functions": [ "write", "font_named", @@ -1211,7 +1319,7 @@ }, { "funcKey": "load_font", - "title": "Using Fonts", + "title": "Using Fonts\r", "url": "/api/graphics/#load-font", "functions": [ "open_window", @@ -1225,7 +1333,7 @@ { "funcKey": "refresh_screen", "title": "House Drawing", - "url": "/api/graphics/#refresh-screen", + "url": "/api/graphics/#refresh-screen-functions", "functions": [ "open_window", "clear_screen", @@ -1242,7 +1350,7 @@ }, { "funcKey": "text_width_font_named", - "title": "Underline Text using Text Width", + "title": "Underline Text using Text Width\r", "url": "/api/graphics/#text-width-font-named", "functions": [ "open_window", @@ -1259,6 +1367,38 @@ ] } ], + "json": [ + { + "funcKey": "data_driven_dungeon", + "title": "Data-Driven Dungeon Integration Example\r", + "url": "/api/json/#data-driven-dungeon", + "functions": [ + "main", + "json_from_file", + "json_read_string", + "json_read_integer", + "open_window", + "quit_requested", + "process_events", + "clear_screen", + "color_black", + "draw_text", + "color_white", + "json_read_array", + "json_array_size", + "json_read_object_at_index", + "json_read_number", + "color_green", + "color_red", + "fill_rectangle", + "fill_circle", + "color_gold", + "refresh_screen_with_target_fps", + "free_json", + "close_all_windows" + ] + } + ], "networking": [ { "funcKey": "dec_to_hex", @@ -1303,8 +1443,8 @@ "physics": [ { "funcKey": "sprite_bitmap_collision", - "title": "Does SplashKit have bugs?", - "url": "/api/physics/#sprite-bitmap-collision", + "title": "Does SplashKit have bugs?\r", + "url": "/api/physics/#sprite-bitmap-collision-functions", "functions": [ "open_window", "load_bitmap", @@ -1323,7 +1463,7 @@ }, { "funcKey": "sprite_collision", - "title": "Colliding Sprites", + "title": "Colliding Sprites\r", "url": "/api/physics/#sprite-collision", "functions": [ "open_window", @@ -1342,7 +1482,7 @@ }, { "funcKey": "sprite_point_collision", - "title": "Determine Sprite Collisions with Points", + "title": "Determine Sprite Collisions with Points\r", "url": "/api/physics/#sprite-point-collision", "functions": [ "open_window", @@ -1365,7 +1505,7 @@ }, { "funcKey": "sprite_rectangle_collision", - "title": "Detect Sprite Collisions with Rectangles", + "title": "Detect Sprite Collisions with Rectangles\r", "url": "/api/physics/#sprite-rectangle-collision", "functions": [ "open_window", @@ -1390,7 +1530,7 @@ "raspberry": [ { "funcKey": "raspi_i2c_write_data", - "title": "LED Text Scrolling", + "title": "LED Text Scrolling\r", "url": "/api/raspberry/#raspi-i2c-write-data", "functions": [ "write_line", @@ -1407,8 +1547,8 @@ "sprites": [ { "funcKey": "create_sprite", - "title": "Creating a Player Sprite", - "url": "/api/sprites/#create-sprite", + "title": "Creating a Player Sprite\r", + "url": "/api/sprites/#create-sprite-functions", "functions": [ "open_window", "load_bitmap", @@ -1425,8 +1565,8 @@ }, { "funcKey": "draw_sprite", - "title": "Drawing a Player Sprite", - "url": "/api/sprites/#draw-sprite", + "title": "Drawing a Player Sprite\r", + "url": "/api/sprites/#draw-sprite-functions", "functions": [ "open_window", "load_bitmap", @@ -1443,7 +1583,7 @@ }, { "funcKey": "free_sprite", - "title": "Freeing a Sprite", + "title": "Freeing a Sprite\r", "url": "/api/sprites/#free-sprite", "functions": [ "open_window", @@ -1465,7 +1605,7 @@ }, { "funcKey": "sprite_set_position", - "title": "Setting Sprite Position", + "title": "Setting Sprite Position\r", "url": "/api/sprites/#sprite-set-position", "functions": [ "open_window", @@ -1485,7 +1625,7 @@ }, { "funcKey": "sprite_set_velocity", - "title": "Setting Velocity of Sprite", + "title": "Setting Velocity of Sprite\r", "url": "/api/sprites/#sprite-set-velocity", "functions": [ "open_window", @@ -1507,7 +1647,7 @@ }, { "funcKey": "sprite_set_x", - "title": "Setting Sprite X-coordinate", + "title": "Setting Sprite X-coordinate\r", "url": "/api/sprites/#sprite-set-x", "functions": [ "open_window", @@ -1524,7 +1664,7 @@ }, { "funcKey": "sprite_set_y", - "title": "Setting Sprite Y-coordinate", + "title": "Setting Sprite Y-coordinate\r", "url": "/api/sprites/#sprite-set-y", "functions": [ "open_window", @@ -1541,7 +1681,7 @@ }, { "funcKey": "sprite_x", - "title": "Sprite x-coordinate", + "title": "Sprite x-coordinate\r", "url": "/api/sprites/#sprite-x", "functions": [ "open_window", @@ -1561,7 +1701,7 @@ }, { "funcKey": "sprite_y", - "title": "Sprite y-coordinate", + "title": "Sprite y-coordinate\r", "url": "/api/sprites/#sprite-y", "functions": [ "open_window", @@ -1585,7 +1725,7 @@ { "funcKey": "write", "title": "Progress Bar Simulation", - "url": "/api/terminal/#write", + "url": "/api/terminal/#write-functions", "functions": [ "write_line", "delay" @@ -1621,7 +1761,7 @@ { "funcKey": "write_line", "title": "Hello World string", - "url": "/api/terminal/#write-line", + "url": "/api/terminal/#write-line-functions", "functions": [] }, { @@ -1673,7 +1813,7 @@ }, { "funcKey": "current_ticks", - "title": "How many ticks?", + "title": "How many ticks?\r", "url": "/api/utilities/#current-ticks", "functions": [ "write_line", @@ -1733,7 +1873,7 @@ { "funcKey": "rnd", "title": "Coin Flip", - "url": "/api/utilities/#rnd", + "url": "/api/utilities/#rnd-functions", "functions": [ "write_line", "delay", @@ -1790,5 +1930,30 @@ "write_line" ] } + ], + "windows": [ + { + "funcKey": "close_window", + "title": "Starts a countdown to close the window at the push of a button.", + "url": "/api/windows/#close-window-functions", + "functions": [ + "open_window", + "create_timer", + "quit_requested", + "process_events", + "clear_window", + "color_white", + "button_at_position", + "rectangle_from", + "start_timer", + "draw_text_font_as_string", + "color_black", + "timer_ticks", + "reset_timer", + "draw_interface", + "refresh_window", + "close_all_windows" + ] + } ] } \ No newline at end of file diff --git a/scripts/usage-example-scraping.cjs b/scripts/usage-example-scraping.cjs index 0ec5376cf..1ed827666 100644 --- a/scripts/usage-example-scraping.cjs +++ b/scripts/usage-example-scraping.cjs @@ -8,12 +8,46 @@ const path = require('path'); // Handle and transform file paths const srcDirectory = "./public/usage-examples"; //directory to be scraped const outputDirectory = "./scripts/json-files/usage-example-references.json" //directory where "Usage Example" functions will be savedc +const apiJsonPath = "./scripts/json-files/api.json"; + +function getApiJsonData() { + try { + const apiJsonFile = fs.readFileSync(apiJsonPath, "utf8"); + return JSON.parse(apiJsonFile); + } catch (err) { + console.warn(kleur.yellow("Warning: unable to load api.json for usage example URL mapping. Falling back to default anchors.")); + return {}; + } +} + +function getUsageExampleApiUrl(folderKey, funcKey, apiJsonData) { + const defaultUrl = `/api/${folderKey}/#${funcKey.replaceAll("_", "-")}`; + const category = apiJsonData[folderKey]; + if (!category || !Array.isArray(category.functions)) { + return defaultUrl; + } + + const matches = category.functions.filter(func => func.name === funcKey); + + // Overloaded functions are grouped under a "-functions" section anchor. + if (matches.length > 1) { + return `/api/${folderKey}/#${funcKey.replaceAll("_", "-")}-functions`; + } + + if (matches.length === 1) { + const anchor = (matches[0].unique_global_name || funcKey).replaceAll("_", "-"); + return `/api/${folderKey}/#${anchor}`; + } + + return defaultUrl; +} // ------------------------------------------------------------------------------ // Scraping all of the folders in usage example and retrieving the functions and title // ------------------------------------------------------------------------------ function getAvailableExamplesFunctionUsage(dir) { const result = {}; + const apiJsonData = getApiJsonData(); const fileNameRegex = /^([a-zA-Z_][a-zA-Z0-9_]*)-/; const ignoreKey = new Set(["if", "else", "elif", "while", "for", "range", "int", "str", "match"]); @@ -55,7 +89,7 @@ function getAvailableExamplesFunctionUsage(dir) { funcEntry = { funcKey: funcKey, title: title, - url: `/api/${folderKey}/#${funcKey.replaceAll("_", "-")}`, + url: getUsageExampleApiUrl(folderKey, funcKey, apiJsonData), functions: [] }; result[folderKey].push(funcEntry);