creditsloader.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class CreditsLoader
  2. {
  3. protected static const string JSON_FILE_PATH = "scripts/data/credits.json";
  4. static void CreateTestJson()
  5. {
  6. string nameDepartment = "Department";
  7. string nameSection = "Section";
  8. string nameLine = "Line";
  9. JsonDataCredits data = new JsonDataCredits();
  10. data.Departments = new array<ref JsonDataCreditsDepartment>;
  11. for (int index_dep = 0; index_dep < 3; ++index_dep)
  12. {
  13. JsonDataCreditsDepartment department = new JsonDataCreditsDepartment();
  14. department.Sections = new array<ref JsonDataCreditsSection>();
  15. department.DepartmentName = (nameDepartment +" "+ index_dep);
  16. for (int index_sec = 0; index_sec < 4; ++index_sec)
  17. {
  18. JsonDataCreditsSection section = new JsonDataCreditsSection();
  19. section.SectionLines = new array<string>;
  20. section.SectionName = (nameSection +" "+ index_sec);
  21. int linesCount = Math.RandomInt(3, 10);
  22. for (int i = 0; i < linesCount; ++i)
  23. {
  24. section.SectionLines.Insert(nameLine +" "+ i);
  25. }
  26. department.Sections.Insert(section);
  27. }
  28. data.Departments.Insert(department);
  29. }
  30. string errorMessage;
  31. if (!JsonFileLoader<ref JsonDataCredits>.SaveFile(JSON_FILE_PATH, data, errorMessage))
  32. ErrorEx(errorMessage);
  33. }
  34. static JsonDataCredits GetData()
  35. {
  36. string errorMessage;
  37. JsonDataCredits data;
  38. if (!JsonFileLoader<ref JsonDataCredits>.LoadFile(JSON_FILE_PATH, data, errorMessage))
  39. ErrorEx(errorMessage);
  40. return data;
  41. }
  42. }