Starter project for SDL2.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <minIni.h>
  4. #include <SDL_filesystem.h>
  5. #include <SDL_keyboard.h>
  6. #include "../IZ_action.h"
  7. #include "IZ_config.h"
  8. void IZ_GetConfigPath(char* config_path) {
  9. //const char* config_path_dir = SDL_GetPrefPath("Modal Studios", APP_NAME);
  10. const char* config_path_dir = SDL_GetBasePath();
  11. memcpy_s(config_path, 128, config_path_dir, 128);
  12. strcat_s(config_path, 128, "config.ini");
  13. }
  14. void IZ_SaveConfig(IZ_Config* config) {
  15. char config_path[128];
  16. IZ_GetConfigPath(config_path);
  17. FILE* fp;
  18. fopen_s(&fp, config_path, "w");
  19. fprintf_s(fp, "[Video]\n");
  20. fprintf_s(fp, "Width=%u\n", config->video.width);
  21. fprintf_s(fp, "Height=%u\n", config->video.height);
  22. fprintf_s(fp, "\n");
  23. for (uint8_t p = 0; p < PLAYERS; p += 1) {
  24. fprintf_s(fp, "[Controls.%u.Keyboard]\n", p);
  25. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  26. fprintf_s(fp, "%s=%s\n", ACTION_NAMES[i], SDL_GetKeyName(config->controls[p].keyboard[i]));
  27. }
  28. }
  29. }
  30. void IZ_LoadConfig(IZ_Config* config) {
  31. char config_path[128];
  32. IZ_GetConfigPath(config_path);
  33. config->video.width = ini_getl("Video", "Width", 640l, config_path);
  34. config->video.height = ini_getl("Video", "Height", 480l, config_path);
  35. char buffer[128];
  36. char section_name[20] = "Controls.0.Keyboard";
  37. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  38. section_name[9] = (char) (48 + i);
  39. ini_gets(section_name, ACTION_NAMES[i], SDL_GetKeyName(IZ_DEFAULT_KEYBOARD_CONTROLS[i]), buffer, 128, config_path);
  40. config->controls[0].keyboard[i] = SDL_GetKeyFromName(buffer);
  41. }
  42. }