summaryrefslogtreecommitdiffstats
path: root/src/video/artpack.c
blob: 4b2239e9313d39e270f4cad45dcaf0e939b235bf (plain)
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
53
54
55
56
57
58
59
#include "video/video.h"
#include "filesystem/path.h"
#include "base/util.h"

#include "Nebu_scripting.h"
#include "Nebu_filesystem.h"

void initArtpacks(void) {
  const char *art_path;
  List *artList;
  List *p;
  int i;

  art_path = getDirectory( PATH_ART );
  artList = readDirectoryContents(art_path, NULL);
  if(artList->next == NULL) {
    fprintf(stderr, "[fatal] no art files found...exiting\n");
    exit(1); /* OK: critical, installation corrupt */
  }
  
  i = 1;
  for(p = artList; p->next != NULL; p = p->next) {
    if(strncmp((char*)p->data, "Makefile", 8)) {
      scripting_RunFormat("artpacks[%d] = \"%s\"", i, (char*) p->data);
      i++;
    }
  }
  scripting_Run("setupArtpacks()");
}

void loadArt(void) {
  char *path;
  char *artpack;

	runScript(PATH_SCRIPTS, "artpack.lua"); // load default art settings

	scripting_GetGlobal("settings", "current_artpack", NULL);
  scripting_GetStringResult(&artpack);
  fprintf(stderr, "[status] loading artpack '%s'\n", artpack);
	
  path = getArtPath(artpack, "artpack.lua");
  free(artpack);

  if(path != NULL) {
    scripting_RunFile(path);
    free(path);
  }

  initTexture(gScreen);
  initFonts();
}

void reloadArt(void) {
  printf("[status] reloading art\n");
  deleteTextures(gScreen);
  loadArt();
}