-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.c
52 lines (40 loc) · 1015 Bytes
/
settings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by Avihoo on 28/06/2020.
//
#include "settings.h"
#include <SDL.h>
void initSettings()
{
SDL_RWops *file = SDL_RWFromFile(SETTINGS_FILE_NAME, "r");
if (!file)
{
defaultSettings();
return;
}
settings readSettings;
SDL_RWread(file, &readSettings, sizeof(settings), 1);
if (readSettings.version == SETTINGS_VERSION)
{
currentSettings = readSettings;
}
else
{
defaultSettings();
}
SDL_RWclose(file);
}
void saveSettings()
{
SDL_RWops *file = SDL_RWFromFile(SETTINGS_FILE_NAME, "w");
SDL_RWwrite(file, ¤tSettings, sizeof(currentSettings), 1);
SDL_RWclose(file);
}
void defaultSettings()
{
currentSettings.version = SETTINGS_VERSION;
currentSettings.blockSize = DEFAULT_BLOCK_SIZE;
currentSettings.movementKeyboardCooldown = DEFAULT_MOVEMENT_KEYBOARD_COOLDOWN;
currentSettings.rotationKeyboardCooldown = DEFAULT_ROTATION_KEYBOARD_COOLDOWN;
currentSettings.dropKeyboardCooldown = DEFAULT_DROP_KEYBOARD_COOLDOWN;
currentSettings.soundVolume = DEFAULT_VOLUME;
}