Moved tile interactions over.
This commit is contained in:
@ -5,6 +5,11 @@
|
|||||||
"options": "Options",
|
"options": "Options",
|
||||||
"exit": "Exit"
|
"exit": "Exit"
|
||||||
},
|
},
|
||||||
|
"tiles": {
|
||||||
|
"water": {
|
||||||
|
"interact": "A refreshing body of water."
|
||||||
|
}
|
||||||
|
},
|
||||||
"entities": {
|
"entities": {
|
||||||
"sign": {
|
"sign": {
|
||||||
"name": "Sign"
|
"name": "Sign"
|
||||||
|
@ -20,9 +20,7 @@
|
|||||||
#include "game/state/overworld.h"
|
#include "game/state/overworld.h"
|
||||||
|
|
||||||
#include "rpg/conversation/conversation.h"
|
#include "rpg/conversation/conversation.h"
|
||||||
#include "rpg/conversation/testconversation.h"
|
|
||||||
#include "asset/assetlanguage.h"
|
#include "asset/assetlanguage.h"
|
||||||
#include "locale/language.h"
|
|
||||||
|
|
||||||
game_t GAME;
|
game_t GAME;
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
conversation.c
|
conversation.c
|
||||||
testconversation.c
|
conversationinteractentity.c
|
||||||
conversationinteract.c
|
conversationinteracttile.c
|
||||||
)
|
)
|
@ -17,12 +17,12 @@ void conversationInit() {
|
|||||||
void conversationSet(
|
void conversationSet(
|
||||||
const conversationcallback_t init,
|
const conversationcallback_t init,
|
||||||
const conversationcallback_t update,
|
const conversationcallback_t update,
|
||||||
void *user
|
const conversationdata_t data
|
||||||
) {
|
) {
|
||||||
CONVERSATION.init = init;
|
CONVERSATION.init = init;
|
||||||
CONVERSATION.update = update;
|
CONVERSATION.update = update;
|
||||||
CONVERSATION.index = CONVERSATION_NOT_INITIALIZED;
|
CONVERSATION.index = CONVERSATION_NOT_INITIALIZED;
|
||||||
CONVERSATION.user = user;
|
CONVERSATION.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void conversationUpdate() {
|
void conversationUpdate() {
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawn.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "rpg/world/tile.h"
|
||||||
|
|
||||||
#define CONVERSATION_NEXT ((uint16_t)-1)
|
#define CONVERSATION_NEXT ((uint16_t)-1)
|
||||||
#define CONVERSATION_CONTINUE ((uint16_t)-2)
|
#define CONVERSATION_CONTINUE ((uint16_t)-2)
|
||||||
@ -21,11 +22,21 @@ typedef uint16_t (*conversationcallback_t) (
|
|||||||
conversation_t *convo, const uint16_t
|
conversation_t *convo, const uint16_t
|
||||||
);
|
);
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct {
|
||||||
|
entity_t *entity;
|
||||||
|
} entityInteract;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
tile_t tile;
|
||||||
|
} tileInteract;
|
||||||
|
} conversationdata_t;
|
||||||
|
|
||||||
typedef struct _conversation_t {
|
typedef struct _conversation_t {
|
||||||
uint16_t index;
|
uint16_t index;
|
||||||
conversationcallback_t init;
|
conversationcallback_t init;
|
||||||
conversationcallback_t update;
|
conversationcallback_t update;
|
||||||
void *user;
|
conversationdata_t data;
|
||||||
} conversation_t;
|
} conversation_t;
|
||||||
|
|
||||||
extern conversation_t CONVERSATION;
|
extern conversation_t CONVERSATION;
|
||||||
@ -40,12 +51,12 @@ void conversationInit();
|
|||||||
*
|
*
|
||||||
* @param init The initialization callback.
|
* @param init The initialization callback.
|
||||||
* @param update The update callback.
|
* @param update The update callback.
|
||||||
* @param user The user data.
|
* @param data The user data.
|
||||||
*/
|
*/
|
||||||
void conversationSet(
|
void conversationSet(
|
||||||
const conversationcallback_t init,
|
const conversationcallback_t init,
|
||||||
const conversationcallback_t update,
|
const conversationcallback_t update,
|
||||||
void *user
|
const conversationdata_t data
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2024 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "conversation.h"
|
|
||||||
|
|
||||||
uint16_t conversationInteractInit(conversation_t *convo, const uint16_t i);
|
|
||||||
uint16_t conversationInteractUpdate(conversation_t *convo, const uint16_t i);
|
|
@ -5,17 +5,20 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "conversationinteract.h"
|
#include "conversationinteractentity.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
#include "locale/language.h"
|
#include "locale/language.h"
|
||||||
#include "ui/textbox.h"
|
#include "ui/textbox.h"
|
||||||
|
|
||||||
uint16_t conversationInteractInit(conversation_t *convo, const uint16_t i) {
|
uint16_t conversationInteractEntityInit(
|
||||||
|
conversation_t *convo,
|
||||||
|
const uint16_t i
|
||||||
|
) {
|
||||||
assertNotNull(convo, "Conversation is NULL!");
|
assertNotNull(convo, "Conversation is NULL!");
|
||||||
assertNotNull(convo->user, "Conversation user is NULL!");
|
assertNotNull(convo->data.entityInteract.entity, "Conversation user is NULL!");
|
||||||
|
|
||||||
entity_t *e = (entity_t*)convo->user;
|
entity_t *e = (entity_t*)convo->data.entityInteract.entity;
|
||||||
switch(e->type) {
|
switch(e->type) {
|
||||||
case ENTITY_TYPE_SIGN:
|
case ENTITY_TYPE_SIGN:
|
||||||
textboxSetText("entities.sign.name", e->sign.text);
|
textboxSetText("entities.sign.name", e->sign.text);
|
||||||
@ -31,7 +34,10 @@ uint16_t conversationInteractInit(conversation_t *convo, const uint16_t i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t conversationInteractUpdate(conversation_t *convo, const uint16_t i) {
|
uint16_t conversationInteractEntityUpdate(
|
||||||
|
conversation_t *convo,
|
||||||
|
const uint16_t i
|
||||||
|
) {
|
||||||
switch(i) {
|
switch(i) {
|
||||||
case 0:
|
case 0:
|
||||||
return textboxIsOpen() ? CONVERSATION_CONTINUE : CONVERSATION_DONE;
|
return textboxIsOpen() ? CONVERSATION_CONTINUE : CONVERSATION_DONE;
|
31
src/dawn/rpg/conversation/conversationinteractentity.h
Normal file
31
src/dawn/rpg/conversation/conversationinteractentity.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "conversation.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the conversation object for an entity interaction.
|
||||||
|
*
|
||||||
|
* @param convo The conversation object to initialize.
|
||||||
|
* @param i The index to initialize the conversation at.
|
||||||
|
* @return The next index to run.
|
||||||
|
*/
|
||||||
|
uint16_t conversationInteractEntityInit(
|
||||||
|
conversation_t *convo, const uint16_t i
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the conversation object for an entity interaction.
|
||||||
|
*
|
||||||
|
* @param convo The conversation object to update.
|
||||||
|
* @param i The index to update the conversation at.
|
||||||
|
* @return The next index to run.
|
||||||
|
*/
|
||||||
|
uint16_t conversationInteractEntityUpdate(
|
||||||
|
conversation_t *convo, const uint16_t i
|
||||||
|
);
|
47
src/dawn/rpg/conversation/conversationinteracttile.c
Normal file
47
src/dawn/rpg/conversation/conversationinteracttile.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "conversationinteractentity.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "locale/language.h"
|
||||||
|
#include "ui/textbox.h"
|
||||||
|
|
||||||
|
uint16_t conversationInteractTileInit(
|
||||||
|
conversation_t *convo,
|
||||||
|
const uint16_t i
|
||||||
|
) {
|
||||||
|
assertNotNull(convo, "Conversation is NULL!");
|
||||||
|
|
||||||
|
switch(convo->data.tileInteract.tile) {
|
||||||
|
case TILE_WATER:
|
||||||
|
textboxSetText(
|
||||||
|
NULL,
|
||||||
|
"tiles.water.interact"
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Invalid tile interaction!");
|
||||||
|
return CONVERSATION_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t conversationInteractTileUpdate(
|
||||||
|
conversation_t *convo,
|
||||||
|
const uint16_t i
|
||||||
|
) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
return textboxIsOpen() ? CONVERSATION_CONTINUE : CONVERSATION_DONE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CONVERSATION_INVALID;
|
||||||
|
}
|
||||||
|
}
|
31
src/dawn/rpg/conversation/conversationinteracttile.h
Normal file
31
src/dawn/rpg/conversation/conversationinteracttile.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "conversation.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the conversation object for a tile interaction.
|
||||||
|
*
|
||||||
|
* @param convo The conversation object to initialize.
|
||||||
|
* @param i The index to initialize the conversation at.
|
||||||
|
* @return The next index to run.
|
||||||
|
*/
|
||||||
|
uint16_t conversationInteractTileInit(
|
||||||
|
conversation_t *convo, const uint16_t i
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the conversation object for a tile interaction.
|
||||||
|
*
|
||||||
|
* @param convo The conversation object to update.
|
||||||
|
* @param i The index to update the conversation at.
|
||||||
|
* @return The next index to run.
|
||||||
|
*/
|
||||||
|
uint16_t conversationInteractTileUpdate(
|
||||||
|
conversation_t *convo, const uint16_t i
|
||||||
|
);
|
@ -1,30 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2024 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "testconversation.h"
|
|
||||||
|
|
||||||
uint16_t conversationTestInit(conversation_t *convo, const uint16_t i) {
|
|
||||||
switch(i) {
|
|
||||||
case 0:
|
|
||||||
printf("Test conversation start\n");
|
|
||||||
return CONVERSATION_CONTINUE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return CONVERSATION_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t conversationTestUpdate(conversation_t *convo, const uint16_t i) {
|
|
||||||
switch(i) {
|
|
||||||
case 0:
|
|
||||||
printf("Conversation update\n");
|
|
||||||
return CONVERSATION_DONE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return CONVERSATION_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2024 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "conversation.h"
|
|
||||||
|
|
||||||
uint16_t conversationTestInit(conversation_t *convo, const uint16_t i);
|
|
||||||
uint16_t conversationTestUpdate(conversation_t *convo, const uint16_t i);
|
|
@ -9,8 +9,8 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "game/game.h"
|
#include "game/game.h"
|
||||||
#include "locale/language.h"
|
#include "locale/language.h"
|
||||||
#include "rpg/conversation/conversationinteract.h"
|
#include "rpg/conversation/conversationinteractentity.h"
|
||||||
#include "ui/textbox.h"
|
#include "rpg/conversation/conversationinteracttile.h"
|
||||||
|
|
||||||
void entityInteractEntity(
|
void entityInteractEntity(
|
||||||
entity_t *source,
|
entity_t *source,
|
||||||
@ -29,17 +29,17 @@ void entityInteractEntity(
|
|||||||
source->x, source->y
|
source->x, source->y
|
||||||
);
|
);
|
||||||
conversationSet(
|
conversationSet(
|
||||||
conversationInteractInit,
|
conversationInteractEntityInit,
|
||||||
conversationInteractUpdate,
|
conversationInteractEntityUpdate,
|
||||||
target
|
(conversationdata_t){ .entityInteract = { .entity = target } }
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ENTITY_TYPE_SIGN:
|
case ENTITY_TYPE_SIGN:
|
||||||
conversationSet(
|
conversationSet(
|
||||||
conversationInteractInit,
|
conversationInteractEntityInit,
|
||||||
conversationInteractUpdate,
|
conversationInteractEntityUpdate,
|
||||||
target
|
(conversationdata_t){ .entityInteract = { .entity = target } }
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -66,8 +66,12 @@ void entityInteractTile(
|
|||||||
|
|
||||||
switch(tile) {
|
switch(tile) {
|
||||||
case TILE_WATER:
|
case TILE_WATER:
|
||||||
textboxSetText(NULL, "A refreshing pool of water.");
|
|
||||||
source->state = ENTITY_STATE_TALKING;
|
source->state = ENTITY_STATE_TALKING;
|
||||||
|
conversationSet(
|
||||||
|
conversationInteractTileInit,
|
||||||
|
conversationInteractTileUpdate,
|
||||||
|
(conversationdata_t){ .tileInteract = { .tile = tile } }
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user