Advertisement
gravitowl

store

Dec 21st, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. local storeURL = "https://raw.githubusercontent.com/MentaalAchtergesteld/CC-SCRIPTS/refs/heads/main/store.json";
  2. local screenWidth, screenHeight = term.getSize();
  3.  
  4. local function fetchScripts()
  5. print("Fetching list of available scripts...")
  6. local response = http.get(storeURL);
  7. if not response then
  8. error("Failed to fetch script list.");
  9. end
  10.  
  11. local content = response.readAll();
  12. response.close();
  13.  
  14. local decoded = textutils.unserializeJSON(content);
  15. if not decoded then
  16. error("Failed to decode JSON data.");
  17. end
  18.  
  19. return decoded;
  20. end
  21.  
  22. local function drawScriptsList(scripts, selectedIndex)
  23. term.clear();
  24. term.setCursorPos(1,1);
  25. print("=== Script Store ===");
  26.  
  27. for i=1, math.min(screenHeight - 2, #scripts) do
  28. local scriptIndex = i + (selectedIndex - 1);
  29. if scriptIndex > #scripts then break end
  30.  
  31. local script = scripts[scriptIndex];
  32. if scriptIndex == selectedIndex then
  33. term.setTextColor(colors.yellow);
  34. else
  35. term.setTextColor(colors.white);
  36. end
  37.  
  38. print(string.format("[%d] %s", scriptIndex, script.name));
  39. end
  40.  
  41. term.setTextColor(colors.white);
  42. end
  43.  
  44. local function main()
  45. local scripts = fetchScripts();
  46. local selectedIndex = 1;
  47.  
  48. local running = true;
  49.  
  50. while running do
  51. drawScriptsList(scripts, selectedIndex);
  52. end
  53. end
  54.  
  55. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement