- File operations work on "data/" folder or ".jrf" file
- [NEW] fopenres() works on .jrf resources, fopen on normal files
This commit is contained in:
47
mini.cpp
47
mini.cpp
@@ -1,5 +1,5 @@
|
||||
#include "mini.h"
|
||||
#include <stdio.h>
|
||||
#include "jfile.h"
|
||||
#include <string.h>
|
||||
#include "lua.h"
|
||||
#include "gif.c"
|
||||
@@ -27,6 +27,7 @@ surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
|
||||
FILE *file = NULL;
|
||||
//uint8_t file_mode = 0;
|
||||
bool file_ignore_comma=true;
|
||||
|
||||
char *lua_files=NULL;
|
||||
@@ -80,25 +81,6 @@ Uint8 key_just_pressed = 0;
|
||||
int mouse_x, mouse_y, mouse_wheel;
|
||||
Uint32 mouse_buttons;
|
||||
|
||||
struct bmp_header_t {
|
||||
uint16_t header; // 'BM' 0x4D42
|
||||
uint32_t file_size;
|
||||
uint32_t reserved; // ignore
|
||||
uint32_t bmp_offset; // This is where the bmp data starts
|
||||
uint32_t header_size; // Must be 40
|
||||
int32_t bmp_width;
|
||||
int32_t bmp_height;
|
||||
uint16_t num_color_planes; // Must be 1
|
||||
uint16_t bpp;
|
||||
uint32_t compression; // expected 0
|
||||
uint32_t image_size; // warning, can be 0. Do not trust. Only useful for compressed BMPs (in my experience, it's always the size in bytes (not pixels) of the bmp)
|
||||
int32_t hres; // ignore
|
||||
int32_t vres; // ignore
|
||||
uint32_t num_colors; // warning, can be 0. if 0, num_colors = 2^bpp
|
||||
uint32_t num_important_colors; // ignore
|
||||
};
|
||||
|
||||
|
||||
char* get_value_from_line(char* line) {
|
||||
char* equal_character = strchr(line, '=');
|
||||
if (equal_character == NULL) return NULL;
|
||||
@@ -107,7 +89,8 @@ char* get_value_from_line(char* line) {
|
||||
}
|
||||
|
||||
void read_ini() {
|
||||
FILE *f = fopen("game.ini", "r");
|
||||
int size;
|
||||
FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r");
|
||||
char line[256];
|
||||
if (f == NULL) return;
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
@@ -172,6 +155,13 @@ uint8_t loadsurf(const char* filename) {
|
||||
while (i<10 && surfaces[i].p != NULL) ++i;
|
||||
//[TODO] Gestionar el cas en que no queden surfaces lliures
|
||||
|
||||
int size;
|
||||
uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
||||
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
free(buffer);
|
||||
|
||||
/*
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -184,6 +174,7 @@ uint8_t loadsurf(const char* filename) {
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
free(buffer);
|
||||
}
|
||||
*/
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -310,6 +301,12 @@ void color(uint8_t color) {
|
||||
}
|
||||
|
||||
uint32_t *loadpal(const char* filename) {
|
||||
int size;
|
||||
uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
||||
uint32_t *pal = LoadPalette(buffer);
|
||||
free(buffer);
|
||||
return pal;
|
||||
/*
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -324,7 +321,7 @@ uint32_t *loadpal(const char* filename) {
|
||||
//memcpy(palette, pal, 1024);
|
||||
//free(pal);
|
||||
}
|
||||
return NULL;
|
||||
return NULL;*/
|
||||
}
|
||||
|
||||
void setpal(uint32_t *pal) {
|
||||
@@ -912,6 +909,12 @@ void fopen(const char *filename, uint8_t mode) {
|
||||
file = fopen(filename, mode==0?"r":"w");
|
||||
}
|
||||
|
||||
void fopenres(const char *filename) {
|
||||
if (file != NULL) fclose(file);
|
||||
int size;
|
||||
file = file_getfilepointer(filename, size);
|
||||
}
|
||||
|
||||
void fclose() {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user