Begin types

This commit is contained in:
bgiraudr 2022-05-03 00:40:09 +02:00
parent 90503c7e97
commit 42bf216c8c
10 changed files with 156 additions and 11 deletions

View File

@ -47,6 +47,7 @@ set(SOURCES
src/event.c
src/inventory.c
src/item.c
src/type.c
)
set(ASSETS_cg
@ -70,6 +71,7 @@ set(ASSETS_cg
assets-cg/items/items.txt
assets-cg/items/item.png
assets-cg/items/item2.png
assets-cg/table_type.csv
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)

View File

@ -1,6 +1,7 @@
import fxconv
import json
import pathlib
import csv
def convert(input, output, params, target):
if params["custom-type"] == "map":
@ -18,6 +19,9 @@ def convert(input, output, params, target):
elif params["custom-type"] == "items":
convert_items(input, output, params, target)
return 0
elif params["custom-type"] == "table_type":
convert_table_type(input, output, params, target)
return 0
else:
return 1
@ -116,9 +120,7 @@ def convert_map(input, output, params, target):
for x in range(w*h):
for i in range(nbTilelayer):
value = tile_value.get(data["layers"][i]["data"][x])
if value == TILE_SOLID:
maxValue = TILE_SOLID
break
#attention : priorité aux valeurs hautes : un bloc d'herbe sera prioritaire sur un bloc solide
if value == None: value = TILE_AIR
if value > maxValue: maxValue = value
if value == TILE_BRIDGE:
@ -315,4 +317,32 @@ def convert_items(input, output, params, target):
except KeyError:
raise Exception(f"convert_items() : L'item {data['name']} est mal configuré")
fxconv.elf(items, output, "_" + params["name"], **target)
fxconv.elf(items, output, "_" + params["name"], **target)
def convert_table_type(input, output, params, target):
data = csv.DictReader(open(input,'r'))
table_type = fxconv.Structure()
for i in data:
type = fxconv.Structure()
type += fxconv.string(i["type"])
type += fxconv.u32(list(i).index(i["type"]))
taille = len(i)
b,l,n = [],[],[]
for j in i:
id = list(i).index(j)
if(i[j]=="2"): b.append(id)
if(i[j]=="0,5"): l.append(id)
if(i[j]=="0"): n.append(id)
for a in range(len(b),taille):b.append(0)
for a in range(len(l),taille):l.append(0)
for a in range(len(n),taille):n.append(0)
type += b"".join(fxconv.u32(value) for value in b)
type += b"".join(fxconv.u32(value) for value in l)
type += b"".join(fxconv.u32(value) for value in n)
table_type += fxconv.ptr(type)
fxconv.elf(table_type, output, "_" + params["name"], **target)

View File

@ -38,3 +38,7 @@ battle_ui.png:
player_moves.txt:
custom-type: player_moves
name:levelupplayer
table_type.csv:
custom-type: table_type
name:table_type

5
assets-cg/table_type.csv Normal file
View File

@ -0,0 +1,5 @@
type,Administrateur,Modérateur,Rédacteur,Labélisateur
Administrateur,0,1,1,2
Modérateur,0,"0,5",2,2
Rédacteur,2,1,"0,5",1
Labélisateur,2,"0,5",1,0
1 type Administrateur Modérateur Rédacteur Labélisateur
2 Administrateur 0 1 1 2
3 Modérateur 0 0,5 2 2
4 Rédacteur 2 1 0,5 1
5 Labélisateur 2 0,5 1 0

View File

@ -5,4 +5,5 @@
#define NB_INTERIORS 2
#define NB_PLAYER_MOVES 3
#define NB_PLAYER_ITEMS 30
#define NB_PLAYER_ITEMS 30
#define NB_TYPES 4

View File

@ -17,4 +17,5 @@ void draw_dialog(struct Game *game);
struct Talkable* get_dialog_xy(struct Map *map, int x, int y);
char *word_boundary_before(char *str, char *limit);
char *skip_spaces(char *str);
void format_text(int x, int y, const int color, char const *format, ...);
void format_text(int x, int y, const int color, char const *format, ...);
void format_text_opt(int x, int y, int width, int height, const int color, char const *format, ...);

20
include/type.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "define.h"
struct Type {
char* name;
const int id;
int buff[NB_TYPES+1];
int less[NB_TYPES+1];
int null[NB_TYPES+1];
};
struct Types {
struct Type *type[NB_TYPES];
};
bool parseArray(int array[], char *nom);
float getTypeEffect(struct Type atk, struct Type def);
struct Type getTypeFromName(char* name);
struct Type getTypeFromId(int id);
void drawTypeEffects(struct Type type);

View File

@ -1,6 +1,7 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <string.h>
#include <gint/std/stdlib.h>
#include "engine.h"
#include "game.h"
@ -17,6 +18,7 @@
#include "inventory.h"
#include "item.h"
#include "event.h"
#include "type.h"
/*draw the current state of the game*/
void engine_draw(struct Game const *game) {
@ -30,7 +32,6 @@ void engine_draw(struct Game const *game) {
dprint(1,1,C_WHITE,"%d:%d",game->player->pos.x, game->player->pos.y);
dprint(1,20,C_WHITE,"%d",game->player->sprint);
dprint(1,40,C_WHITE,"%d",map_get_player_tile(game));
}
void engine_draw_map(struct Game const *game) {
@ -133,7 +134,9 @@ void engine_action(struct Game *game, int action) {
open_inventory(game, &game->player->inventory, "Consultation", true);
}
if(action == ACTION_F2) {
add_item_to_inventory(game, &game->player->inventory, get_item_id(1));
//add_item_to_inventory(game, &game->player->inventory, get_item_id(1));
srand(game->player->pos.x * game->player->pos.y);
drawTypeEffects(getTypeFromId(rand_range(1,5)));
}
if(action == ACTION_OPTN) {
draw_stats(game->player->stats);

View File

@ -12,8 +12,6 @@
#include "event.h"
#include "player.h"
#define LIMIT 35
struct Talkable default_value = {
.x = 0,
.y = 0,
@ -88,8 +86,20 @@ void format_text(int x, int y, const int color, char const *format, ...) {
vsnprintf(text_arg, 512, format, args);
va_end(args);
format_text_opt(x, y, DIALOG_WIDTH, LINE_HEIGHT, color, text_arg);
}
void format_text_opt(int x, int y, int width, int height, const int color, char const *format, ...) {
int const DIALOG_WIDTH = width, LINE_HEIGHT = height;
char text_arg[512];
va_list args;
va_start(args, format);
vsnprintf(text_arg, 512, format, args);
va_end(args);
char *text = (char *)malloc(strlen(text_arg)+1);
strcpy(text,text_arg);
strcpy(text, text_arg);
while(*text) {
char *end = (char *)drsize(text, NULL, DIALOG_WIDTH, NULL);

69
src/type.c Normal file
View File

@ -0,0 +1,69 @@
#include <stdbool.h>
#include <string.h>
#include "type.h"
#include <gint/keyboard.h>
#include <gint/display.h>
#include "util.h"
extern struct Types table_type;
struct Type default_type = {
.name = "-",
.id = 0,
.buff = {},
.less = {},
.null = {}
};
struct Type getTypeFromName(char* name) {
for(int i = 0; i < NB_TYPES; i++) {
if(!strcmp(table_type.type[i]->name, name)) return *table_type.type[i];
}
return default_type;
}
struct Type getTypeFromId(int id) {
for(int i = 0; i < NB_TYPES; i++) {
if(table_type.type[i]->id == id) return *table_type.type[i];
}
return default_type;
}
bool parseArray(int array[], char *nom) {
struct Type type = getTypeFromName(nom);
for(int i = 0; i < NB_TYPES+1; i++) {
if(array[i] == 0) return false;
if(array[i] == type.id) return true;
}
return false;
}
float getTypeEffect(struct Type atk, struct Type def) {
if(parseArray(atk.buff, def.name)) return 2;
if(parseArray(atk.less, def.name)) return 0.5;
if(parseArray(atk.null, def.name)) return 0;
return 1;
}
void drawTypeEffects(struct Type type) {
while(1) {
dclear(C_WHITE);
dprint(120,10,C_RED, "Table de %s", type.name);
dtext(55,40,C_BLUE, "Super efficace");
dtext(160,40,C_BLUE, "Peu efficace");
dtext(260,40,C_BLUE, "Non efficace");
for(int i = 0; i <= 3; i++) {
for(int j = 0; j <= NB_TYPES; j++) {
if(i==0) dprint(70+100*i, 60+20*j, C_BLACK, "%s", getTypeFromId(type.buff[j]).name);
if(i==1) dprint(70+100*i, 60+20*j, C_BLACK, "%s", getTypeFromId(type.less[j]).name);
if(i==2) dprint(70+100*i, 60+20*j, C_BLACK, "%s", getTypeFromId(type.null[j]).name);
}
}
dupdate();
pollevent();
if(keydown(KEY_OPTN)) break;
}
wait_for_input(KEY_SHIFT);
}