From b217494352ccc09e55c3b14416d50257559dfd69 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Fri, 1 May 2020 17:31:49 +0200
Subject: [PATCH] Fixing a bug with the dialog holder callback and adding the
fisherman
---
CMakeLists.txt | 2 +-
Makefile | 3 ++-
assets/sprites/npc/fisherman.png | Bin 0 -> 1227 bytes
include/components/dialog_holder.h | 1 +
include/setup.h | 4 +++
prefabs/game.gcprefab | 21 ++++++++++++++++
src/components/dialog_holder.c | 13 ++++++----
src/components/dialog_methods.c | 7 ++++++
src/game_loader.c | 2 ++
src/npc/fisherman.c | 39 +++++++++++++++++++++++++++++
src/npc/mia.c | 6 -----
11 files changed, 85 insertions(+), 13 deletions(-)
create mode 100644 assets/sprites/npc/fisherman.png
create mode 100644 src/npc/fisherman.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1a35d22..9201ff8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -298,7 +298,7 @@ add_executable(my_rpg
include/components/attack_component.h
src/systems/combat_methods.c
src/combat/attacks.c
- src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c)
+ src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c src/npc/fisherman.c)
add_compile_options(-W -Wall -Wextra -Wshadow)
diff --git a/Makefile b/Makefile
index 650767b..d032ad6 100644
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,8 @@ SRC = src/main.c \
src/player_utilities.c \
src/systems/inventory.c \
src/systems/game_over.c \
- src/npc/mia.c
+ src/npc/mia.c \
+ src/npc/fisherman.c
OBJ = $(SRC:%.c=%.o)
diff --git a/assets/sprites/npc/fisherman.png b/assets/sprites/npc/fisherman.png
new file mode 100644
index 0000000000000000000000000000000000000000..ea05b1e4c8a411f478b8bf2b3d99ea5d38a3d54a
GIT binary patch
literal 1227
zcmV;+1T_1JP){~XR;kSeFd!YW*wA%BNB>4)u;rr8-tg{@mwV9U
zO#+vDa#wIS1>05kZYIS3zNnY4huj~U*!TBEeZ1kzr{nsW5FaieeLWnGQimb`>pqzU
zdiT6Y>rI8M`4;itR^4JM(~d(!`AG|(Oy(1R0y-!Th=SN-p0wmL0BFgxTG
z76b@E+Uj0_(ZT|ZknqqGED2zO9?Zt{>+lPNoiqM)zSMn)Un2D0zkh%}#8ZL{j2!ab
z$CY?S$OGqK8{!!uyLlw^dw7@NAUJ|%*uV8bECL;Xqx3tUhp
z9FO3Aq0S6kvW-y|!KaA{Bl0KN>XMN05+QM{8hygasHuT7ur~_rTU*0ZcHO
zqxcl3l=%@AfCQu7#i#tjtidl3-0AH7`Q+9KP(ovzSeMJkyIYB81bN8LUoPHN`4PcW
zLSyAo)8xDBP_6#A33)%KS~6YABBMPBNagTkq}^hl=>(?$^sxi
zN(7W27esuj@
zepK5aaXj1eBVeaq`O&L>w7xGsVm^rfVhekJR>v?nWF_fC8VPQ
z{d~{xl%VMjjDs+q5<*875xf#g|FyIzz;jj!0d5*Pu}LtMA&J%?PRl#6=-^xgiv&ya
zqa(@{ZOV^;v|wR=B!rY7fuM-wJDMNi$NbX)(iCe~vw)`rH6);a9T)I8_nB&UlmjF<
pxb4}pD56Qug0=-naPrms=og?DN>yiQA;SOw002ovPDHLkV1h{;Fp&TN
literal 0
HcmV?d00001
diff --git a/include/components/dialog_holder.h b/include/components/dialog_holder.h
index dfc9e9d..bf050ae 100644
--- a/include/components/dialog_holder.h
+++ b/include/components/dialog_holder.h
@@ -50,5 +50,6 @@ void dialog_next(gc_engine *engine);
struct dialog_line *dialog_add_line(struct dialog_holder *this, char *name, \
char *text, struct dialog_input *inputs);
void show_dialog_if_hidden(gc_engine *engine);
+struct dialog_holder *dialog_get_current(gc_engine *engine);
#endif //MY_RPG_DIALOG_HOLDER_H
diff --git a/include/setup.h b/include/setup.h
index 5c1800e..7dc1f4e 100644
--- a/include/setup.h
+++ b/include/setup.h
@@ -72,5 +72,9 @@ gc_vector2 pos, enum gc_mousekeys key);
bool mia_fish(gc_engine *engine, gc_entity *entity, \
gc_vector2 pos, enum gc_mousekeys key);
+void fisherman_setup(gc_engine *engine);
+bool fisherman_next(gc_engine *engine, gc_entity *entity, \
+gc_vector2 pos, enum gc_mousekeys key);
+
void load_data(gc_scene *scene, const gc_data *datas);
extern const struct gc_data game_data[];
\ No newline at end of file
diff --git a/prefabs/game.gcprefab b/prefabs/game.gcprefab
index 1248951..6a990a2 100644
--- a/prefabs/game.gcprefab
+++ b/prefabs/game.gcprefab
@@ -145,6 +145,7 @@
+
@@ -236,6 +237,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/dialog_holder.c b/src/components/dialog_holder.c
index 48ec71c..4b95d71 100644
--- a/src/components/dialog_holder.c
+++ b/src/components/dialog_holder.c
@@ -79,17 +79,20 @@ bool dialog_parse_inputs(struct dialog_line *txt, gc_scene *scene, node *n)
struct dialog_line *dialog_parse_text(gc_scene *scene, node *n)
{
struct dialog_line *txt = malloc(sizeof(struct dialog_line));
- char *callback;
+ char *clb;
if (!txt)
return (NULL);
txt->name = my_strdup(n->name);
txt->text = xml_getproperty(n, "line");
txt->input_count = xml_getchildcount_filtered(n, "input");
- callback = xml_gettempprop(n, "callback");
- txt->callback = scene->get_data(scene, "dialog_callback", callback);
- if (callback && !txt->callback)
- my_printf("Couldn't find an callback with the name: %s.\n", callback);
+ clb = xml_gettempprop(n, "clb");
+ if (clb) {
+ txt->callback = scene->get_data(scene, "dialog_callback", clb);
+ if (!txt->callback)
+ my_printf("Couldn't find an clb with the name: %s.\n", clb);
+ } else
+ txt->callback = NULL;
txt->inputs = NULL;
if (txt->input_count == 0)
return (txt);
diff --git a/src/components/dialog_methods.c b/src/components/dialog_methods.c
index a870c0c..6eeb4df 100644
--- a/src/components/dialog_methods.c
+++ b/src/components/dialog_methods.c
@@ -32,4 +32,11 @@ struct dialog_input *inputs)
this->text[count] = line;
this->text[count + 1] = NULL;
return (line);
+}
+
+struct dialog_holder *dialog_get_current(gc_engine *engine)
+{
+ struct dialog_manager *manager = GETSYS(engine, dialog_manager);
+
+ return (manager->current_dialog);
}
\ No newline at end of file
diff --git a/src/game_loader.c b/src/game_loader.c
index 46a866f..90c4536 100644
--- a/src/game_loader.c
+++ b/src/game_loader.c
@@ -58,6 +58,8 @@ const struct gc_data game_data[] = {
{"input", "mia_save", &mia_save, NULL},
{"input", "mia_fish", &mia_fish, NULL},
{"dialog_callback", "mia_setup", &mia_setup, NULL},
+ {"dialog_callback", "fisherman_setup", &fisherman_setup, NULL},
+ {"input", "fisherman_next", &fisherman_next, NULL},
{NULL, NULL, NULL, NULL}
};
diff --git a/src/npc/fisherman.c b/src/npc/fisherman.c
new file mode 100644
index 0000000..eb84729
--- /dev/null
+++ b/src/npc/fisherman.c
@@ -0,0 +1,39 @@
+/*
+** EPITECH PROJECT, 2020
+** my_rpg
+** File description:
+** fisherman.c
+*/
+
+#include "components/dialog_holder.h"
+#include "systems/game_manager_system.h"
+#include "engine.h"
+
+
+void fisherman_setup(gc_engine *engine)
+{
+ struct dialog_holder *holder = dialog_get_current(engine);
+
+ holder->text[2] = NULL;
+}
+
+bool fisherman_next(gc_engine *engine, gc_entity *entity, \
+gc_vector2 pos, enum gc_mousekeys key)
+{
+ struct dialog_holder *dialog = dialog_get_current(engine);
+
+ if (!dialog)
+ return (false);
+ dialog_add_line(dialog, "Fisherman", "Sometimes I catch \
+fishes with\na strange ability:", NULL);
+ dialog_add_line(dialog, "Fisherman", "they can throw a powerful Water\n\
+Jet at their enemies.", NULL);
+ dialog_add_line(dialog, "Fisherman", "This kind of fish seems \
+to come from the\nsource of the river, something must be there.", NULL);
+ dialog_add_line(dialog, "Fisherman", "You should check it out!", NULL);
+ dialog_add_line(dialog, "Fisherman", "If you pass nearby Mia, tell her\n\
+that I will show up at...", NULL);
+ dialog_add_line(dialog, "Fisherman", "her house for dinner tonight.", NULL);
+ GETSYS(engine, game_manager_system)->has_message = true;
+ return (true);
+}
\ No newline at end of file
diff --git a/src/npc/mia.c b/src/npc/mia.c
index d8b2233..a0e8110 100644
--- a/src/npc/mia.c
+++ b/src/npc/mia.c
@@ -10,12 +10,6 @@
#include
#include "engine.h"
-struct dialog_holder *dialog_get_current(gc_engine *engine)
-{
- struct dialog_manager *manager = GETSYS(engine, dialog_manager);
-
- return (manager->current_dialog);
-}
void mia_setup(gc_engine *engine)
{