]> git.lizzy.rs Git - dragonblocks-bedrock.git/blob - src/util.cpp
Some structure Changes
[dragonblocks-bedrock.git] / src / util.cpp
1 #include <stdlib.h>
2 #include <cstring>
3 #include <cstdio>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <cstdio>
8 #include <string>
9
10 #include "util.h"
11 #include "game.h"
12
13 using namespace std;
14 int random(int min, int max){
15         return min + rand() % (max - min + 1);
16 }
17 color::color(const char *htmlcolor){
18         unsigned int r, g, b;
19         sscanf(htmlcolor, "#%2x%2x%2x", &r, &g, &b);
20         red = (float) r / 255;
21         green = (float) g / 255;
22         blue = (float) b / 255;
23 }
24 color::color(float r, float g, float b){
25         red = r;
26         green = g;
27         blue = b;
28 }
29 void create_dir_if_not_exists(string d){
30         const char *dir = d.c_str();
31         struct stat dir_exists_st = {0};        
32         if(stat(dir, &dir_exists_st) == -1){
33                 Game::log((string)dir + " doesn't exist, creating", INFO);
34                 #ifdef _WIN32
35                 mkdir(dir);
36                 #else
37                 mkdir(dir, 0700);
38                 #endif
39         }
40 }