Compare commits
7
Commits
b498a12458
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3948607b1e | ||
|
|
6c180372fe | ||
|
|
fed04b66b8 | ||
|
|
a4ca718070 | ||
|
|
8dbd3e1dd2 | ||
|
|
7a9a2b9832 | ||
|
|
e8757c33e3 |
No files matched your search
@@ -4,18 +4,14 @@
|
|||||||
"type": "BATTLE_START",
|
"type": "BATTLE_START",
|
||||||
"enemies": [
|
"enemies": [
|
||||||
{
|
{
|
||||||
"stats": {
|
|
||||||
"attack": 8, "defense": 4, "magic": 0, "speed": 5, "luck": 2,
|
"attack": 8, "defense": 4, "magic": 0, "speed": 5, "luck": 2,
|
||||||
"healthMax": 30, "mpMax": 0
|
"healthMax": 30, "mpMax": 0,
|
||||||
},
|
|
||||||
"abilities": ["fire"]
|
"abilities": ["fire"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"stats": {
|
|
||||||
"attack": 6, "defense": 3, "magic": 0, "speed": 7, "luck": 2,
|
"attack": 6, "defense": 3, "magic": 0, "speed": 7, "luck": 2,
|
||||||
"healthMax": 20, "mpMax": 0
|
"healthMax": 20, "mpMax": 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
// Placeholder for the new-game intro flow - just shows a modal for now.
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "MODAL",
|
||||||
|
"title": "New Game",
|
||||||
|
"message": "This is a placeholder for the new game intro.",
|
||||||
|
"blocking": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"members": {
|
||||||
|
"hero": {
|
||||||
|
"attack": 10,
|
||||||
|
"defense": 5,
|
||||||
|
"magic": 0,
|
||||||
|
"speed": 10,
|
||||||
|
"luck": 0,
|
||||||
|
"healthMax": 30,
|
||||||
|
"mpMax": 10
|
||||||
|
},
|
||||||
|
"companion": {
|
||||||
|
"attack": 8,
|
||||||
|
"defense": 6,
|
||||||
|
"magic": 4,
|
||||||
|
"speed": 8,
|
||||||
|
"luck": 1,
|
||||||
|
"healthMax": 25,
|
||||||
|
"mpMax": 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,161 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
|
errorret_t battleFighterParseStatField(
|
||||||
|
yyjson_val *obj,
|
||||||
|
const char_t *key,
|
||||||
|
uint16_t *out
|
||||||
|
) {
|
||||||
|
yyjson_val *val = yyjson_obj_get(obj, key);
|
||||||
|
if(!yyjson_is_int(val)) {
|
||||||
|
errorThrow("Fighter: missing/invalid '%s'", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const int64_t num = yyjson_get_sint(val);
|
||||||
|
if(num < 0 || num > UINT16_MAX) {
|
||||||
|
errorThrow("Fighter: '%s' must be between 0 and %u", key, UINT16_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = (uint16_t)num;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t battleFighterParseOptionalIntField(
|
||||||
|
yyjson_val *obj,
|
||||||
|
const char_t *key,
|
||||||
|
const int32_t defaultValue,
|
||||||
|
int32_t *out
|
||||||
|
) {
|
||||||
|
yyjson_val *val = yyjson_obj_get(obj, key);
|
||||||
|
if(val == NULL) {
|
||||||
|
*out = defaultValue;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!yyjson_is_int(val)) errorThrow("Fighter: invalid '%s'", key);
|
||||||
|
*out = (int32_t)yyjson_get_sint(val);
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t battleFighterParse(battlefighter_t *fighter, yyjson_val *obj) {
|
||||||
|
assertNotNull(fighter, "Fighter cannot be NULL");
|
||||||
|
assertNotNull(obj, "JSON object cannot be NULL");
|
||||||
|
|
||||||
|
int32_t teamNum;
|
||||||
|
errorChain(battleFighterParseOptionalIntField(
|
||||||
|
obj, "team", BATTLE_FIGHTER_TEAM_ALLY, &teamNum
|
||||||
|
));
|
||||||
|
if(teamNum < 0 || teamNum >= BATTLE_FIGHTER_TEAM_COUNT) {
|
||||||
|
errorThrow("Fighter: invalid 'team'");
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t controllerNum;
|
||||||
|
errorChain(battleFighterParseOptionalIntField(
|
||||||
|
obj, "controller", BATTLE_FIGHTER_CONTROLLER_PLAYER, &controllerNum
|
||||||
|
));
|
||||||
|
if(controllerNum < 0 || controllerNum >= BATTLE_FIGHTER_CONTROLLER_COUNT) {
|
||||||
|
errorThrow("Fighter: invalid 'controller'");
|
||||||
|
}
|
||||||
|
|
||||||
|
battlefighterstats_t stats;
|
||||||
|
errorChain(battleFighterParseStatField(obj, "attack", &stats.attack));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "defense", &stats.defense));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "magic", &stats.magic));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "speed", &stats.speed));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "luck", &stats.luck));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "healthMax", &stats.healthMax));
|
||||||
|
errorChain(battleFighterParseStatField(obj, "mpMax", &stats.mpMax));
|
||||||
|
|
||||||
|
battleFighterInit(
|
||||||
|
fighter, (battlefighterteam_t)teamNum,
|
||||||
|
(battlefightercontroller_t)controllerNum, stats
|
||||||
|
);
|
||||||
|
|
||||||
|
int32_t statusNum;
|
||||||
|
errorChain(battleFighterParseOptionalIntField(
|
||||||
|
obj, "status", BATTLE_FIGHTER_STATUS_NORMAL, &statusNum
|
||||||
|
));
|
||||||
|
if(statusNum < 0 || statusNum >= BATTLE_FIGHTER_STATUS_COUNT) {
|
||||||
|
errorThrow("Fighter: invalid 'status'");
|
||||||
|
}
|
||||||
|
fighter->status = (battlefighterstatus_t)statusNum;
|
||||||
|
|
||||||
|
int32_t health;
|
||||||
|
errorChain(
|
||||||
|
battleFighterParseOptionalIntField(obj, "health", stats.healthMax, &health)
|
||||||
|
);
|
||||||
|
if(health < 0 || health > stats.healthMax) {
|
||||||
|
errorThrow("Fighter: 'health' out of range");
|
||||||
|
}
|
||||||
|
fighter->stats.health = (uint16_t)health;
|
||||||
|
|
||||||
|
int32_t mp;
|
||||||
|
errorChain(battleFighterParseOptionalIntField(obj, "mp", stats.mpMax, &mp));
|
||||||
|
if(mp < 0 || mp > stats.mpMax) {
|
||||||
|
errorThrow("Fighter: 'mp' out of range");
|
||||||
|
}
|
||||||
|
fighter->stats.mp = (uint16_t)mp;
|
||||||
|
|
||||||
|
yyjson_val *abilities = yyjson_obj_get(obj, "abilities");
|
||||||
|
if(abilities != NULL) {
|
||||||
|
if(
|
||||||
|
!yyjson_is_arr(abilities) ||
|
||||||
|
yyjson_arr_size(abilities) > BATTLE_FIGHTER_ABILITY_COUNT_MAX
|
||||||
|
) {
|
||||||
|
errorThrow(
|
||||||
|
"Fighter: 'abilities' must have 0-%u entries",
|
||||||
|
BATTLE_FIGHTER_ABILITY_COUNT_MAX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
yyjson_arr_iter iter = yyjson_arr_iter_with(abilities);
|
||||||
|
yyjson_val *abilityVal;
|
||||||
|
while((abilityVal = yyjson_arr_iter_next(&iter)) != NULL) {
|
||||||
|
const char_t *name = yyjson_get_str(abilityVal);
|
||||||
|
battlemoveid_t ability =
|
||||||
|
name == NULL ? BATTLE_MOVE_ID_NULL : battleMoveGetIdByName(name);
|
||||||
|
if(ability == BATTLE_MOVE_ID_NULL) {
|
||||||
|
errorThrow("Fighter: invalid entry in 'abilities'");
|
||||||
|
}
|
||||||
|
battleFighterAbilityAdd(fighter, ability);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
yyjson_mut_val *battleFighterSerialize(
|
||||||
|
const battlefighter_t *fighter,
|
||||||
|
yyjson_mut_doc *doc
|
||||||
|
) {
|
||||||
|
assertNotNull(fighter, "Fighter cannot be NULL");
|
||||||
|
assertNotNull(doc, "Doc cannot be NULL");
|
||||||
|
|
||||||
|
yyjson_mut_val *obj = yyjson_mut_obj(doc);
|
||||||
|
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "team", fighter->team);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "controller", fighter->controller);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "status", fighter->status);
|
||||||
|
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "attack", fighter->stats.attack);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "defense", fighter->stats.defense);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "magic", fighter->stats.magic);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "speed", fighter->stats.speed);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "luck", fighter->stats.luck);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "healthMax", fighter->stats.healthMax);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "mpMax", fighter->stats.mpMax);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "health", fighter->stats.health);
|
||||||
|
yyjson_mut_obj_add_uint(doc, obj, "mp", fighter->stats.mp);
|
||||||
|
|
||||||
|
yyjson_mut_val *abilities = yyjson_mut_arr(doc);
|
||||||
|
for(uint8_t i = 0; i < fighter->abilityCount; i++) {
|
||||||
|
yyjson_mut_arr_add_str(doc, abilities, BATTLE_MOVES[fighter->abilities[i]].name);
|
||||||
|
}
|
||||||
|
yyjson_mut_obj_add_val(doc, obj, "abilities", abilities);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
void battleFighterInit(
|
void battleFighterInit(
|
||||||
battlefighter_t *fighter,
|
battlefighter_t *fighter,
|
||||||
const battlefighterteam_t team,
|
const battlefighterteam_t team,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
|
#include "yyjson.h"
|
||||||
#include "rpg/battle/move/battlemove.h"
|
#include "rpg/battle/move/battlemove.h"
|
||||||
#include "rpg/battle/fighter/battlefighterstatus.h"
|
#include "rpg/battle/fighter/battlefighterstatus.h"
|
||||||
#include "rpg/battle/fighter/battlefighterteam.h"
|
#include "rpg/battle/fighter/battlefighterteam.h"
|
||||||
@@ -45,6 +46,42 @@ void battleFighterInit(
|
|||||||
const battlefighterstats_t stats
|
const battlefighterstats_t stats
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic battlefighter_t parser, shared by every place that builds a
|
||||||
|
* fighter from JSON (party.jsonc roster members, BATTLE_START enemy
|
||||||
|
* definitions, save-file party members) - see battleFighterSerialize for
|
||||||
|
* the inverse. Reads 'team'/'controller'/'status' as ints (each optional,
|
||||||
|
* defaulting to ALLY/PLAYER/NORMAL respectively - a caller that needs a
|
||||||
|
* different team/controller, e.g. BATTLE_START's enemies, sets those
|
||||||
|
* fields on fighter after this returns), 'attack'/'defense'/'magic'/
|
||||||
|
* 'speed'/'luck'/'healthMax'/'mpMax' as required ints in [0, UINT16_MAX],
|
||||||
|
* 'health'/'mp' as optional ints defaulting to healthMax/mpMax (a fresh
|
||||||
|
* fighter), and an optional 'abilities' array of move name strings. Does
|
||||||
|
* not touch fighter->id - set it (or leave it) before calling, same as
|
||||||
|
* battleFighterInit.
|
||||||
|
*
|
||||||
|
* @param fighter Pointer to the fighter to fill in.
|
||||||
|
* @param obj The JSON object to read fields from.
|
||||||
|
* @return Error if a required field is missing/invalid, or an abilities
|
||||||
|
* entry doesn't name a real move.
|
||||||
|
*/
|
||||||
|
errorret_t battleFighterParse(battlefighter_t *fighter, yyjson_val *obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inverse of battleFighterParse: builds a new JSON object (not yet
|
||||||
|
* attached anywhere - the caller attaches it, e.g. via
|
||||||
|
* yyjson_mut_arr_add_val/yyjson_mut_obj_add_val) with every field
|
||||||
|
* battleFighterParse reads except id (see its doc comment for why).
|
||||||
|
*
|
||||||
|
* @param fighter The fighter to serialize.
|
||||||
|
* @param doc The mutable document to allocate the object in.
|
||||||
|
* @return The newly built object.
|
||||||
|
*/
|
||||||
|
yyjson_mut_val *battleFighterSerialize(
|
||||||
|
const battlefighter_t *fighter,
|
||||||
|
yyjson_mut_doc *doc
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the fighter is in a state where it can still act (i.e.
|
* Returns true if the fighter is in a state where it can still act (i.e.
|
||||||
* is not dead).
|
* is not dead).
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
#include "rpg/battle/fighter/battlefighterstats.h"
|
||||||
|
|
||||||
|
#define BATTLE_FIGHTER_SPECIES_NAME_MAX 16
|
||||||
|
#define BATTLE_FIGHTER_SPECIES_COUNT_MAX 250
|
||||||
|
|
||||||
|
typedef uint8_t battlespeciesid_t;
|
||||||
|
|
||||||
|
#define BATTLE_SPECIES_ID_NULL ((battlespeciesid_t)0)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char_t name[BATTLE_FIGHTER_SPECIES_NAME_MAX];
|
||||||
|
battlefighterstats_t baseStats;
|
||||||
|
} battlefighterspecies_t;
|
||||||
+140
-26
@@ -8,50 +8,125 @@
|
|||||||
#include "party.h"
|
#include "party.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
#include "save/save.h"
|
#include "save/save.h"
|
||||||
|
#include "asset/asset.h"
|
||||||
|
#include "asset/loader/assetloader.h"
|
||||||
|
|
||||||
void partyInit(void) {
|
errorret_t partyInit(party_t *party) {
|
||||||
party_t *party = &SAVE.slot.party;
|
assertNotNull(party, "Party cannot be NULL");
|
||||||
|
|
||||||
memoryZero(party, sizeof(party_t));
|
memoryZero(party, sizeof(party_t));
|
||||||
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
|
||||||
party->members[i].id = i;
|
|
||||||
}
|
|
||||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||||
party->order[i] = PARTY_ORDER_EMPTY;
|
party->order[i] = PARTY_ORDER_EMPTY;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t partyGetAvailableMember(void) {
|
assetentry_t *entry = assetLock("party.jsonc", ASSET_LOADER_TYPE_JSON, NULL);
|
||||||
const party_t *party = &SAVE.slot.party;
|
errorret_t result = assetRequireLoaded(entry);
|
||||||
|
if(errorIsNotOk(result)) {
|
||||||
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
assetUnlockEntry(entry);
|
||||||
if(party->members[i].status == BATTLE_FIGHTER_STATUS_NULL) return i;
|
errorChain(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0xFF;
|
yyjson_val *root = yyjson_doc_get_root(entry->data.json);
|
||||||
|
yyjson_val *members = yyjson_obj_get(root, "members");
|
||||||
|
if(!yyjson_is_obj(members)) {
|
||||||
|
assetUnlockEntry(entry);
|
||||||
|
errorThrow("party.jsonc: missing/invalid 'members' object");
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t memberCount = yyjson_obj_size(members);
|
||||||
|
if(memberCount > PARTY_MEMBER_COUNT_MAX) {
|
||||||
|
assetUnlockEntry(entry);
|
||||||
|
errorThrow(
|
||||||
|
"party.jsonc: defines more than PARTY_MEMBER_COUNT_MAX (%u) members",
|
||||||
|
PARTY_MEMBER_COUNT_MAX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t idx = 0;
|
||||||
|
yyjson_val *key;
|
||||||
|
yyjson_val *memberObj;
|
||||||
|
yyjson_obj_iter iter = yyjson_obj_iter_with(members);
|
||||||
|
while((key = yyjson_obj_iter_next(&iter))) {
|
||||||
|
memberObj = yyjson_obj_iter_get_val(key);
|
||||||
|
|
||||||
|
if(yyjson_get_len(key) >= PARTY_KEY_LENGTH_MAX) {
|
||||||
|
assetUnlockEntry(entry);
|
||||||
|
errorThrow(
|
||||||
|
"party.jsonc: member key '%s' exceeds PARTY_KEY_LENGTH_MAX (%u)",
|
||||||
|
yyjson_get_str(key), PARTY_KEY_LENGTH_MAX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringCopy(party->keys[idx], yyjson_get_str(key), PARTY_KEY_LENGTH_MAX - 1);
|
||||||
|
|
||||||
|
battlefighter_t *member = &party->members[idx];
|
||||||
|
member->id = idx;
|
||||||
|
errorret_t parseResult = battleFighterParse(member, memberObj);
|
||||||
|
if(errorIsNotOk(parseResult)) {
|
||||||
|
assetUnlockEntry(entry);
|
||||||
|
errorChain(parseResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
assetUnlockEntry(entry);
|
||||||
|
|
||||||
|
// TEST: only the first defined member starts active, in the first party
|
||||||
|
// position - replace once there's a real starting-party/character-
|
||||||
|
// creation flow. Deliberately separate from the roster seeding above:
|
||||||
|
// order (not a member's presence in the roster) is what determines who's
|
||||||
|
// currently in the party.
|
||||||
|
if(memberCount > 0) party->order[0] = 0;
|
||||||
|
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
battlefighter_t *partyAddMember(
|
uint8_t partyGetMemberIndexByKey(const char_t *key) {
|
||||||
const battlefighterstats_t stats
|
assertNotNull(key, "Key cannot be NULL");
|
||||||
) {
|
|
||||||
|
const party_t *party = &SAVE.slot.party;
|
||||||
|
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
||||||
|
if(stringEquals(party->keys[i], key)) return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PARTY_MEMBER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char_t *partyGetMemberKey(const uint8_t memberIndex) {
|
||||||
|
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
|
||||||
|
return SAVE.slot.party.keys[memberIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t partyIsMemberActive(const uint8_t memberIndex) {
|
||||||
|
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
|
||||||
|
|
||||||
|
const party_t *party = &SAVE.slot.party;
|
||||||
|
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||||
|
if(party->order[i] == memberIndex) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void partyAddMember(const uint8_t memberIndex) {
|
||||||
|
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
|
||||||
|
|
||||||
party_t *party = &SAVE.slot.party;
|
party_t *party = &SAVE.slot.party;
|
||||||
|
assertTrue(
|
||||||
const uint8_t index = partyGetAvailableMember();
|
party->members[memberIndex].status != BATTLE_FIGHTER_STATUS_NULL,
|
||||||
if(index == 0xFF) return NULL;
|
"Member does not exist in the roster"
|
||||||
|
|
||||||
battlefighter_t *member = &party->members[index];
|
|
||||||
battleFighterInit(
|
|
||||||
member, BATTLE_FIGHTER_TEAM_ALLY, BATTLE_FIGHTER_CONTROLLER_PLAYER, stats
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(partyIsMemberActive(memberIndex)) return;
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||||
if(party->order[i] != PARTY_ORDER_EMPTY) continue;
|
if(party->order[i] != PARTY_ORDER_EMPTY) continue;
|
||||||
party->order[i] = index;
|
party->order[i] = memberIndex;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return member;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
battlefighter_t *partyGetOrderMember(const uint8_t slot) {
|
battlefighter_t *partyGetOrderMember(const uint8_t slot) {
|
||||||
@@ -72,3 +147,42 @@ void partySetOrder(const uint8_t slot, const uint8_t memberIndex) {
|
|||||||
|
|
||||||
SAVE.slot.party.order[slot] = memberIndex;
|
SAVE.slot.party.order[slot] = memberIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void partyRemoveMember(const uint8_t memberIndex) {
|
||||||
|
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
|
||||||
|
|
||||||
|
party_t *party = &SAVE.slot.party;
|
||||||
|
|
||||||
|
uint8_t removedSlot = PARTY_ORDER_EMPTY;
|
||||||
|
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||||
|
if(party->order[i] != memberIndex) continue;
|
||||||
|
removedSlot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(removedSlot == PARTY_ORDER_EMPTY) return;
|
||||||
|
|
||||||
|
for(uint8_t i = removedSlot; i < PARTY_ACTIVE_SIZE_MAX - 1; i++) {
|
||||||
|
party->order[i] = party->order[i + 1];
|
||||||
|
}
|
||||||
|
party->order[PARTY_ACTIVE_SIZE_MAX - 1] = PARTY_ORDER_EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void partyHealMember(const uint8_t memberIndex) {
|
||||||
|
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
|
||||||
|
|
||||||
|
battlefighter_t *member = &SAVE.slot.party.members[memberIndex];
|
||||||
|
if(member->status == BATTLE_FIGHTER_STATUS_NULL) return;
|
||||||
|
|
||||||
|
member->status = BATTLE_FIGHTER_STATUS_NORMAL;
|
||||||
|
member->stats.health = member->stats.healthMax;
|
||||||
|
member->stats.mp = member->stats.mpMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
void partyHealAll(void) {
|
||||||
|
const party_t *party = &SAVE.slot.party;
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
||||||
|
if(party->members[i].status == BATTLE_FIGHTER_STATUS_NULL) continue;
|
||||||
|
partyHealMember(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
+78
-20
@@ -7,44 +7,75 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "rpg/battle/fighter/battlefighter.h"
|
#include "rpg/battle/fighter/battlefighter.h"
|
||||||
|
#include "yyjson.h"
|
||||||
|
|
||||||
#define PARTY_MEMBER_COUNT_MAX 4
|
#define PARTY_MEMBER_COUNT_MAX 10
|
||||||
#define PARTY_ACTIVE_SIZE_MAX 3
|
#define PARTY_ACTIVE_SIZE_MAX 4
|
||||||
|
#define PARTY_KEY_LENGTH_MAX 32
|
||||||
#define PARTY_ORDER_EMPTY 0xFF
|
#define PARTY_ORDER_EMPTY 0xFF
|
||||||
|
#define PARTY_MEMBER_NOT_FOUND 0xFF
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
battlefighter_t members[PARTY_MEMBER_COUNT_MAX];
|
battlefighter_t members[PARTY_MEMBER_COUNT_MAX];
|
||||||
|
char_t keys[PARTY_MEMBER_COUNT_MAX][PARTY_KEY_LENGTH_MAX];
|
||||||
uint8_t order[PARTY_ACTIVE_SIZE_MAX];
|
uint8_t order[PARTY_ACTIVE_SIZE_MAX];
|
||||||
// TODO: Whether party members are "front" or "back".
|
|
||||||
} party_t;
|
} party_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the current save slot's party (SAVE.slot.party) with an
|
* Initializes party with an empty order, then seeds every roster slot
|
||||||
* empty roster and order.
|
* directly from party.jsonc's "members" object (each key/value pair fills
|
||||||
|
* the next members[]/keys[] slot in the object's iteration order, key
|
||||||
|
* copied into keys[] and value parsed via battleFighterParse) - unlike
|
||||||
|
* partyAddMember, this never touches order itself except for one
|
||||||
|
* placeholder default: if party.jsonc defines at least one member,
|
||||||
|
* order[0] is set to 0 (the first member starts active in the first party
|
||||||
|
* position). Replace this default once there's a real starting-party/
|
||||||
|
* character-creation flow.
|
||||||
|
*
|
||||||
|
* @param party The party to initialize.
|
||||||
|
* @return Error if party.jsonc fails to load/parse, defines more members
|
||||||
|
* than PARTY_MEMBER_COUNT_MAX has room for, or a key exceeds
|
||||||
|
* PARTY_KEY_LENGTH_MAX.
|
||||||
*/
|
*/
|
||||||
void partyInit(void);
|
errorret_t partyInit(party_t *party);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an available (unused) member slot index in the current save slot's
|
* Looks up a roster member's index by its party.jsonc key (see
|
||||||
* party.
|
* party_t.keys).
|
||||||
*
|
*
|
||||||
* @return The index of an available slot, or 0xFF if the party is full.
|
* @param key The member's key to search for.
|
||||||
|
* @return The matching roster index, or PARTY_MEMBER_NOT_FOUND if no
|
||||||
|
* member has that key.
|
||||||
*/
|
*/
|
||||||
uint8_t partyGetAvailableMember(void);
|
uint8_t partyGetMemberIndexByKey(const char_t *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a member to the current save slot's party roster in the next
|
* Gets a roster member's party.jsonc key by index (see party_t.keys).
|
||||||
* available slot. Party members are always allies controlled by the
|
|
||||||
* player. If there is a free active order slot, the new member is placed
|
|
||||||
* into it.
|
|
||||||
*
|
*
|
||||||
* @param stats The member's base combat stats, including healthMax/mpMax.
|
* @param memberIndex The roster member index to query.
|
||||||
* @return Pointer to the newly added party member, or NULL if the party is
|
* @return The member's key - "" if memberIndex is past however many
|
||||||
* already full.
|
* members party.jsonc actually defines.
|
||||||
*/
|
*/
|
||||||
battlefighter_t *partyAddMember(
|
const char_t *partyGetMemberKey(const uint8_t memberIndex);
|
||||||
const battlefighterstats_t stats
|
|
||||||
);
|
/**
|
||||||
|
* Checks whether memberIndex currently occupies a slot in the current save
|
||||||
|
* slot's party order (i.e. is actively in the party right now).
|
||||||
|
*
|
||||||
|
* @param memberIndex The roster member index to check.
|
||||||
|
* @return True if memberIndex appears anywhere in order.
|
||||||
|
*/
|
||||||
|
bool_t partyIsMemberActive(const uint8_t memberIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an existing roster member (see partyInit - every roster slot
|
||||||
|
* always exists once initialized) to the current save slot's active party
|
||||||
|
* order, in the first free order slot. No-op if memberIndex is already
|
||||||
|
* active, or if there is no free order slot.
|
||||||
|
*
|
||||||
|
* @param memberIndex The roster member index to activate.
|
||||||
|
*/
|
||||||
|
void partyAddMember(const uint8_t memberIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the roster member currently occupying an active order slot in the
|
* Gets the roster member currently occupying an active order slot in the
|
||||||
@@ -66,3 +97,30 @@ battlefighter_t *partyGetOrderMember(const uint8_t slot);
|
|||||||
* PARTY_ORDER_EMPTY to clear the slot.
|
* PARTY_ORDER_EMPTY to clear the slot.
|
||||||
*/
|
*/
|
||||||
void partySetOrder(const uint8_t slot, const uint8_t memberIndex);
|
void partySetOrder(const uint8_t slot, const uint8_t memberIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes memberIndex from the current save slot's active party order -
|
||||||
|
* the roster member itself is untouched (it still exists, per partyInit;
|
||||||
|
* it's simply no longer active) - shifting every later order entry down
|
||||||
|
* one slot to close the gap, so order stays packed with no holes between
|
||||||
|
* active members. No-op if memberIndex isn't currently active.
|
||||||
|
*
|
||||||
|
* @param memberIndex The roster member index to deactivate.
|
||||||
|
*/
|
||||||
|
void partyRemoveMember(const uint8_t memberIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully restores a roster member's health/mp to their max and clears a
|
||||||
|
* dead status back to normal - unlike battleFighterHeal, this can revive
|
||||||
|
* a dead member (there's no combat context here to keep them down). No-op
|
||||||
|
* if the slot is empty.
|
||||||
|
*
|
||||||
|
* @param memberIndex The roster member index to heal.
|
||||||
|
*/
|
||||||
|
void partyHealMember(const uint8_t memberIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls partyHealMember for every occupied slot in the current save
|
||||||
|
* slot's party roster.
|
||||||
|
*/
|
||||||
|
void partyHealAll(void);
|
||||||
@@ -115,6 +115,28 @@ void battleStateSelectionPlayerAttack(const uint8_t targetIndex) {
|
|||||||
BATTLE.stateData.selection.selectionIndex++;
|
BATTLE.stateData.selection.selectionIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void battleStateSelectionGoBack(void) {
|
||||||
|
battlestateselection_t *state = &BATTLE.stateData.selection;
|
||||||
|
uint8_t index = state->selectionIndex;
|
||||||
|
|
||||||
|
while(index > 0) {
|
||||||
|
index--;
|
||||||
|
|
||||||
|
const uint8_t fighterIndex = BATTLE.fighterOrder[index];
|
||||||
|
battlefighter_t *fighter = BATTLE.fighters[fighterIndex];
|
||||||
|
if(fighter == NULL) continue;
|
||||||
|
if(fighter->controller != BATTLE_FIGHTER_CONTROLLER_PLAYER) continue;
|
||||||
|
if(!battleStateSelectionFighterHasDecided(fighterIndex)) continue;
|
||||||
|
|
||||||
|
battlemoveaction_t *action = &BATTLE.actionsPending[fighterIndex];
|
||||||
|
action->move = BATTLE_MOVE_ID_NULL;
|
||||||
|
BATTLE.actionsPendingCount--;
|
||||||
|
|
||||||
|
state->selectionIndex = index;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void battleStateSelectionPlayerFlee(void) {
|
void battleStateSelectionPlayerFlee(void) {
|
||||||
battlefighter_t *fighter = battleStateSelectionGetCurrentFighter();
|
battlefighter_t *fighter = battleStateSelectionGetCurrentFighter();
|
||||||
if(fighter == NULL) return;
|
if(fighter == NULL) return;
|
||||||
|
|||||||
@@ -109,3 +109,12 @@ void battleStateSelectionPlayerAttack(const uint8_t targetIndex);
|
|||||||
* BATTLE_STATE_SELECTION and awaiting a decision.
|
* BATTLE_STATE_SELECTION and awaiting a decision.
|
||||||
*/
|
*/
|
||||||
void battleStateSelectionPlayerFlee(void);
|
void battleStateSelectionPlayerFlee(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewinds the selection cursor to the nearest earlier player-controlled
|
||||||
|
* fighter that has already decided a move this round, clearing its
|
||||||
|
* pending action so it can be re-decided. AI-decided fighters along the
|
||||||
|
* way are left alone (skipped over, not rewound onto). No-ops if there's
|
||||||
|
* no such fighter (e.g. already at the first decision of the round).
|
||||||
|
*/
|
||||||
|
void battleStateSelectionGoBack(void);
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
cutscene.c
|
cutscene.c
|
||||||
|
cutsceneref.c
|
||||||
cutscenesystem.c
|
cutscenesystem.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ void cutsceneAppend(
|
|||||||
const cutsceneitem_t *items,
|
const cutsceneitem_t *items,
|
||||||
const uint8_t count
|
const uint8_t count
|
||||||
) {
|
) {
|
||||||
assertNotNull(scene, "Scene cannot be NULL");
|
|
||||||
cutsceneAppendAt(scene, scene->itemCount, items, count);
|
cutsceneAppendAt(scene, scene->itemCount, items, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,26 +147,6 @@ void cutsceneAppendNext(
|
|||||||
cutsceneAppendAt(scene, (uint8_t)(currentIndex + 1), items, count);
|
cutsceneAppendAt(scene, (uint8_t)(currentIndex + 1), items, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneRemoveFront(
|
|
||||||
cutscene_t *scene,
|
|
||||||
const uint8_t count
|
|
||||||
) {
|
|
||||||
assertNotNull(scene, "Scene cannot be NULL");
|
|
||||||
assertTrue(count <= scene->itemCount, "count exceeds itemCount");
|
|
||||||
|
|
||||||
const size_t tailCount = (size_t)scene->itemCount - count;
|
|
||||||
// count == 0 has nothing to shift (and would pass dest == src into
|
|
||||||
// memoryMove, which asserts against that as a no-op call).
|
|
||||||
if(count > 0 && tailCount > 0) {
|
|
||||||
memoryMove(
|
|
||||||
&scene->items[0],
|
|
||||||
&scene->items[count],
|
|
||||||
tailCount * sizeof(cutsceneitem_t)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
scene->itemCount -= count;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t cutsceneLoadParse(
|
errorret_t cutsceneLoadParse(
|
||||||
const char_t *path,
|
const char_t *path,
|
||||||
cutscene_t *scene,
|
cutscene_t *scene,
|
||||||
@@ -178,6 +157,7 @@ errorret_t cutsceneLoadParse(
|
|||||||
assertNotNull(scene, "Scene cannot be NULL");
|
assertNotNull(scene, "Scene cannot be NULL");
|
||||||
assertNotNull(items, "Items cannot be NULL");
|
assertNotNull(items, "Items cannot be NULL");
|
||||||
|
|
||||||
|
// Lock the asset, require it loaded.
|
||||||
assetentry_t *entry = assetLock(path, ASSET_LOADER_TYPE_JSON, NULL);
|
assetentry_t *entry = assetLock(path, ASSET_LOADER_TYPE_JSON, NULL);
|
||||||
errorret_t result = assetRequireLoaded(entry);
|
errorret_t result = assetRequireLoaded(entry);
|
||||||
if(errorIsNotOk(result)) {
|
if(errorIsNotOk(result)) {
|
||||||
@@ -185,11 +165,12 @@ errorret_t cutsceneLoadParse(
|
|||||||
errorChain(result);
|
errorChain(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse straight out of the entry's own doc while still locked - every
|
// Parse the loaded JSON
|
||||||
// cutsceneitem_t field that could reference it owns its string data by
|
errorret_t parseResult = cutsceneParseDoc(
|
||||||
// value, so nothing needs to survive past this call and the entry can
|
entry->data.json, scene, items, itemsMax
|
||||||
// just be unlocked like any other asset once parsing finishes.
|
);
|
||||||
errorret_t parseResult = cutsceneParseDoc(entry->data.json, scene, items, itemsMax);
|
|
||||||
|
// Free up the asset entry.
|
||||||
assetUnlockEntry(entry);
|
assetUnlockEntry(entry);
|
||||||
errorChain(parseResult);
|
errorChain(parseResult);
|
||||||
|
|
||||||
|
|||||||
@@ -128,30 +128,13 @@ void cutsceneAppendNext(
|
|||||||
const uint8_t count
|
const uint8_t count
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes count items from the front of scene->items, shifting the
|
|
||||||
* remainder down to index 0 and shrinking scene->itemCount to match. Used
|
|
||||||
* by cutsceneSystemNext/cutsceneGoTo to reclaim already-run items' slots
|
|
||||||
* instead of leaving them as dead weight forever - see
|
|
||||||
* CUTSCENE_SYSTEM.currentItem's doc comment, since the currently-running
|
|
||||||
* item is always scene->items[0] once a cutscene has started.
|
|
||||||
*
|
|
||||||
* @param scene Cutscene to remove from.
|
|
||||||
* @param count Number of items to remove from the front - must be
|
|
||||||
* <= scene->itemCount.
|
|
||||||
*/
|
|
||||||
void cutsceneRemoveFront(
|
|
||||||
cutscene_t *scene,
|
|
||||||
const uint8_t count
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a cutscene JSON asset by path and parses it into scene/items (see
|
* Loads a cutscene JSON asset by path and parses it into scene/items (see
|
||||||
* cutsceneParseDoc) - the common "lock the asset, require it loaded,
|
* cutsceneParseDoc) - the common "lock the asset, require it loaded,
|
||||||
* parse its 'items' array, unlock it again" sequence shared by every
|
* parse its 'items' array, unlock it again" sequence shared by every
|
||||||
* place that resolves a cutscene by file path (cutsceneSystemLoad,
|
* place that resolves a cutscene by file path (cutsceneSystemLoad,
|
||||||
* cutsceneCutsceneResolve, cutsceneInsertResolveAndSplice,
|
* cutsceneCutsceneResolve, cutsceneInsertResolveAndSplice,
|
||||||
* battleStateExecutingInit, cutsceneGoTo's reload). Purely propagates the
|
* battleStateExecutingInit, cutsceneSystemGoTo's reload). Purely propagates the
|
||||||
* error on failure (like cutsceneParseDoc) - this is core cutscene logic,
|
* error on failure (like cutsceneParseDoc) - this is core cutscene logic,
|
||||||
* not UI, so it doesn't reach for uiFatalErrorOpen itself; each caller
|
* not UI, so it doesn't reach for uiFatalErrorOpen itself; each caller
|
||||||
* decides how to surface the failure (typically errorCatch(errorPrint())
|
* decides how to surface the failure (typically errorCatch(errorPrint())
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cutsceneref.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
|
||||||
|
void cutsceneRefReset(
|
||||||
|
cutsceneref_t *refs,
|
||||||
|
entity_t *interact,
|
||||||
|
entity_t *interacted
|
||||||
|
) {
|
||||||
|
assertNotNull(refs, "Refs cannot be null");
|
||||||
|
|
||||||
|
refs->entityInteract = interact;
|
||||||
|
refs->entityInteracted = interacted;
|
||||||
|
refs->entityLastCreated = NULL;
|
||||||
|
refs->entityLastRef = NULL;
|
||||||
|
refs->areaLastCreated = CUTSCENE_REF_AREA_LAST_CREATED;
|
||||||
|
refs->textMiniLastCreated = CUTSCENE_REF_TEXT_MINI_LAST_CREATED;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef struct entity_s entity_t;
|
||||||
|
|
||||||
|
#define CUTSCENE_REF_AREA_LAST_CREATED ((uint8_t)0xFF)
|
||||||
|
#define CUTSCENE_REF_TEXT_MINI_LAST_CREATED ((uint8_t)0xFA)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
entity_t *entityInteract;
|
||||||
|
entity_t *entityInteracted;
|
||||||
|
entity_t *entityLastCreated;
|
||||||
|
entity_t *entityLastRef;
|
||||||
|
uint8_t areaLastCreated;
|
||||||
|
uint8_t textMiniLastCreated;
|
||||||
|
} cutsceneref_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets refs to an empty state.
|
||||||
|
*
|
||||||
|
* @param refs Refs to reset.
|
||||||
|
* @param interact The entity that initiated the interaction, or NULL.
|
||||||
|
* @param interacted The entity being interacted with, or NULL.
|
||||||
|
*/
|
||||||
|
void cutsceneRefReset(
|
||||||
|
cutsceneref_t *refs,
|
||||||
|
entity_t *interact,
|
||||||
|
entity_t *interacted
|
||||||
|
);
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "ui/overlay/uifatalerror.h"
|
#include "ui/overlay/uifatalerror.h"
|
||||||
|
#include "save/slot/saveslot.h"
|
||||||
|
|
||||||
cutscenesystem_t CUTSCENE_SYSTEM;
|
cutscenesystem_t CUTSCENE_SYSTEM;
|
||||||
|
|
||||||
@@ -20,16 +21,18 @@ void cutsceneSystemInit() {
|
|||||||
CUTSCENE_SYSTEM.loadedScene.itemsMax = CUTSCENE_LOADED_ITEMS_MAX;
|
CUTSCENE_SYSTEM.loadedScene.itemsMax = CUTSCENE_LOADED_ITEMS_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cutsceneSystemUpdate() {
|
||||||
|
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
||||||
|
|
||||||
|
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
||||||
|
if(cutsceneItemUpdate(item, &CUTSCENE_SYSTEM.data)) cutsceneSystemNext();
|
||||||
|
}
|
||||||
|
|
||||||
void cutsceneSystemDispose() {
|
void cutsceneSystemDispose() {
|
||||||
CUTSCENE_SYSTEM.scene = NULL;
|
CUTSCENE_SYSTEM.scene = NULL;
|
||||||
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
CUTSCENE_SYSTEM.currentItem = CUTSCENE_CURRENT_ITEM_NONE;
|
||||||
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
||||||
CUTSCENE_SYSTEM.entityInteract = NULL;
|
cutsceneRefReset(&CUTSCENE_SYSTEM.refs, NULL, NULL);
|
||||||
CUTSCENE_SYSTEM.entityInteracted = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
||||||
CUTSCENE_SYSTEM.onComplete = NULL;
|
CUTSCENE_SYSTEM.onComplete = NULL;
|
||||||
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
|
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
|
||||||
@@ -44,25 +47,14 @@ void cutsceneSystemPrepare(
|
|||||||
|
|
||||||
CUTSCENE_SYSTEM.scene = cutscene;
|
CUTSCENE_SYSTEM.scene = cutscene;
|
||||||
CUTSCENE_SYSTEM.pause = cutscene->pause;
|
CUTSCENE_SYSTEM.pause = cutscene->pause;
|
||||||
CUTSCENE_SYSTEM.entityInteract = interact;
|
cutsceneRefReset(&CUTSCENE_SYSTEM.refs, interact, interacted);
|
||||||
CUTSCENE_SYSTEM.entityInteracted = interacted;
|
|
||||||
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
||||||
CUTSCENE_SYSTEM.currentItem = 0xFF;// Set to 0xFF so Next wraps to 0.
|
|
||||||
CUTSCENE_SYSTEM.onComplete = NULL;
|
CUTSCENE_SYSTEM.onComplete = NULL;
|
||||||
|
|
||||||
// Only invalidate the known source file when switching away from
|
// cutsceneNext will cause overflow to index 0 (intentional).
|
||||||
// loadedScene entirely. Starting loadedScene itself means
|
CUTSCENE_SYSTEM.currentItem = CUTSCENE_CURRENT_ITEM_NONE;
|
||||||
// cutsceneSystemLoad/cutsceneCutsceneResolve just populated it - for
|
|
||||||
// cutsceneCutsceneResolve (see cutsceneCutsceneStart), that already
|
// Clear loaded file if cutscene not running from file.
|
||||||
// happened before this call, so clearing loadedFile here would
|
|
||||||
// immediately undo it. cutsceneGoTo needs loadedFile intact to reload
|
|
||||||
// a marker behind the current position; cutsceneSystemLoad re-stamps
|
|
||||||
// it itself right after this call anyway, so it's unaffected either
|
|
||||||
// way.
|
|
||||||
if(cutscene != &CUTSCENE_SYSTEM.loadedScene) {
|
if(cutscene != &CUTSCENE_SYSTEM.loadedScene) {
|
||||||
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
|
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
|
||||||
}
|
}
|
||||||
@@ -83,7 +75,9 @@ void cutsceneSystemStartCutsceneWith(
|
|||||||
"Cutscene itemCount exceeds itemsMax"
|
"Cutscene itemCount exceeds itemsMax"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Prep cutscene, save it to the save slot, and advance, aka overflow to 0.
|
||||||
cutsceneSystemPrepare(cutscene, interact, interacted);
|
cutsceneSystemPrepare(cutscene, interact, interacted);
|
||||||
|
saveSlotSetCurrentCutscene(CUTSCENE_SYSTEM.loadedFile);
|
||||||
cutsceneSystemNext();
|
cutsceneSystemNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +87,9 @@ void cutsceneSystemStartCutsceneAndGoToMarker(
|
|||||||
) {
|
) {
|
||||||
assertNotNull(marker, "Marker cannot be NULL");
|
assertNotNull(marker, "Marker cannot be NULL");
|
||||||
|
|
||||||
|
// Restarts the cutscene
|
||||||
cutsceneSystemPrepare(cutscene, NULL, NULL);
|
cutsceneSystemPrepare(cutscene, NULL, NULL);
|
||||||
cutsceneGoTo(marker);
|
cutsceneSystemGoTo(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneSystemInsertItemsNext(
|
void cutsceneSystemInsertItemsNext(
|
||||||
@@ -106,7 +101,6 @@ void cutsceneSystemInsertItemsNext(
|
|||||||
CUTSCENE_SYSTEM.scene,
|
CUTSCENE_SYSTEM.scene,
|
||||||
"cutsceneSystemInsertItemsNext called with no cutscene running"
|
"cutsceneSystemInsertItemsNext called with no cutscene running"
|
||||||
);
|
);
|
||||||
|
|
||||||
cutsceneAppendNext(
|
cutsceneAppendNext(
|
||||||
CUTSCENE_SYSTEM.scene, CUTSCENE_SYSTEM.currentItem, items, itemCount
|
CUTSCENE_SYSTEM.scene, CUTSCENE_SYSTEM.currentItem, items, itemCount
|
||||||
);
|
);
|
||||||
@@ -125,11 +119,29 @@ void cutsceneSystemInsertCutscene(const cutscene_t *cutscene) {
|
|||||||
cutsceneSystemInsertItems(cutscene->items, cutscene->itemCount);
|
cutsceneSystemInsertItems(cutscene->items, cutscene->itemCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cutsceneSystemClearAfter(const uint8_t index) {
|
||||||
|
assertNotNull(
|
||||||
|
CUTSCENE_SYSTEM.scene,
|
||||||
|
"cutsceneSystemClearAfter called with no cutscene running"
|
||||||
|
);
|
||||||
|
assertTrue(
|
||||||
|
index < CUTSCENE_SYSTEM.scene->itemCount,
|
||||||
|
"cutsceneSystemClearAfter index out of range"
|
||||||
|
);
|
||||||
|
|
||||||
|
CUTSCENE_SYSTEM.scene->itemCount = index + 1;
|
||||||
|
}
|
||||||
|
|
||||||
void cutsceneSystemLoad(const char_t *file) {
|
void cutsceneSystemLoad(const char_t *file) {
|
||||||
assertNotNull(file, "File cannot be NULL");
|
assertNotNull(file, "File cannot be NULL");
|
||||||
|
|
||||||
|
// Take a copy of file, as it may be a part of the cutscene itself.
|
||||||
|
char_t fileCopy[ASSET_FILE_NAME_MAX];
|
||||||
|
stringCopy(fileCopy, file, ASSET_FILE_NAME_MAX - 1);
|
||||||
|
|
||||||
|
// Load the cutscene asset, parse it, and start it.
|
||||||
errorret_t result = cutsceneLoadParse(
|
errorret_t result = cutsceneLoadParse(
|
||||||
file, &CUTSCENE_SYSTEM.loadedScene, CUTSCENE_SYSTEM.loadedItems,
|
fileCopy, &CUTSCENE_SYSTEM.loadedScene, CUTSCENE_SYSTEM.loadedItems,
|
||||||
CUTSCENE_LOADED_ITEMS_MAX
|
CUTSCENE_LOADED_ITEMS_MAX
|
||||||
);
|
);
|
||||||
if(errorIsNotOk(result)) {
|
if(errorIsNotOk(result)) {
|
||||||
@@ -138,32 +150,36 @@ void cutsceneSystemLoad(const char_t *file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the loaded file so we can restart if needed.
|
||||||
|
stringCopy(CUTSCENE_SYSTEM.loadedFile, fileCopy, ASSET_FILE_NAME_MAX - 1);
|
||||||
cutsceneSystemStartCutscene(&CUTSCENE_SYSTEM.loadedScene);
|
cutsceneSystemStartCutscene(&CUTSCENE_SYSTEM.loadedScene);
|
||||||
stringCopy(CUTSCENE_SYSTEM.loadedFile, file, ASSET_FILE_NAME_MAX - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneRestart(void) {
|
void cutsceneRestart(void) {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.scene, "cutsceneRestart called with no cutscene running"
|
CUTSCENE_SYSTEM.scene, "cutsceneRestart called with no cutscene running"
|
||||||
);
|
);
|
||||||
|
assertTrue(
|
||||||
|
CUTSCENE_SYSTEM.scene == &CUTSCENE_SYSTEM.loadedScene,
|
||||||
|
"cutsceneRestart called with a cutscene not loaded from file"
|
||||||
|
);
|
||||||
|
assertTrue(
|
||||||
|
CUTSCENE_SYSTEM.loadedFile[0] != '\0',
|
||||||
|
"cutsceneRestart called with no loaded file"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copy the refs and callbacks
|
||||||
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
|
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
|
||||||
entity_t *entityInteract = CUTSCENE_SYSTEM.entityInteract;
|
cutsceneref_t refs = CUTSCENE_SYSTEM.refs;
|
||||||
entity_t *entityInteracted = CUTSCENE_SYSTEM.entityInteracted;
|
|
||||||
|
|
||||||
if(CUTSCENE_SYSTEM.loadedFile[0] != '\0') {
|
// Reload the file.
|
||||||
char_t file[ASSET_FILE_NAME_MAX];
|
char_t file[ASSET_FILE_NAME_MAX];
|
||||||
stringCopy(file, CUTSCENE_SYSTEM.loadedFile, ASSET_FILE_NAME_MAX - 1);
|
stringCopy(file, CUTSCENE_SYSTEM.loadedFile, ASSET_FILE_NAME_MAX - 1);
|
||||||
cutsceneSystemLoad(file);
|
cutsceneSystemLoad(file);
|
||||||
} else {
|
|
||||||
cutsceneSystemStartCutsceneWith(
|
|
||||||
CUTSCENE_SYSTEM.scene, entityInteract, entityInteracted
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Restore the refs and callbacks.
|
||||||
CUTSCENE_SYSTEM.onComplete = onComplete;
|
CUTSCENE_SYSTEM.onComplete = onComplete;
|
||||||
CUTSCENE_SYSTEM.entityInteract = entityInteract;
|
CUTSCENE_SYSTEM.refs = refs;
|
||||||
CUTSCENE_SYSTEM.entityInteracted = entityInteracted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneSystemSetOnComplete(cutscenecallback_t onComplete) {
|
void cutsceneSystemSetOnComplete(cutscenecallback_t onComplete) {
|
||||||
@@ -179,28 +195,28 @@ entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex) {
|
|||||||
|
|
||||||
if(entityIndex == CUTSCENE_ENTITY_INTERACT) {
|
if(entityIndex == CUTSCENE_ENTITY_INTERACT) {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.entityInteract,
|
CUTSCENE_SYSTEM.refs.entityInteract,
|
||||||
"CUTSCENE_ENTITY_INTERACT used but no interact entity is set"
|
"CUTSCENE_ENTITY_INTERACT used but no interact entity is set"
|
||||||
);
|
);
|
||||||
entity = CUTSCENE_SYSTEM.entityInteract;
|
entity = CUTSCENE_SYSTEM.refs.entityInteract;
|
||||||
} else if(entityIndex == CUTSCENE_ENTITY_INTERACTED) {
|
} else if(entityIndex == CUTSCENE_ENTITY_INTERACTED) {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.entityInteracted,
|
CUTSCENE_SYSTEM.refs.entityInteracted,
|
||||||
"CUTSCENE_ENTITY_INTERACTED used but no interacted entity is set"
|
"CUTSCENE_ENTITY_INTERACTED used but no interacted entity is set"
|
||||||
);
|
);
|
||||||
entity = CUTSCENE_SYSTEM.entityInteracted;
|
entity = CUTSCENE_SYSTEM.refs.entityInteracted;
|
||||||
} else if(entityIndex == CUTSCENE_ENTITY_LAST_CREATED) {
|
} else if(entityIndex == CUTSCENE_ENTITY_LAST_CREATED) {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.entityLastCreated,
|
CUTSCENE_SYSTEM.refs.entityLastCreated,
|
||||||
"CUTSCENE_ENTITY_LAST_CREATED used but no entity has been created"
|
"CUTSCENE_ENTITY_LAST_CREATED used but no entity has been created"
|
||||||
);
|
);
|
||||||
entity = CUTSCENE_SYSTEM.entityLastCreated;
|
entity = CUTSCENE_SYSTEM.refs.entityLastCreated;
|
||||||
} else if(entityIndex == CUTSCENE_ENTITY_LAST_REF) {
|
} else if(entityIndex == CUTSCENE_ENTITY_LAST_REF) {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.entityLastRef,
|
CUTSCENE_SYSTEM.refs.entityLastRef,
|
||||||
"CUTSCENE_ENTITY_LAST_REF used but no entity has been referenced"
|
"CUTSCENE_ENTITY_LAST_REF used but no entity has been referenced"
|
||||||
);
|
);
|
||||||
entity = CUTSCENE_SYSTEM.entityLastRef;
|
entity = CUTSCENE_SYSTEM.refs.entityLastRef;
|
||||||
} else {
|
} else {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
entityIndex < ENTITY_COUNT,
|
entityIndex < ENTITY_COUNT,
|
||||||
@@ -209,29 +225,30 @@ entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex) {
|
|||||||
entity = &ENTITIES[entityIndex];
|
entity = &ENTITIES[entityIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.entityLastRef = entity;
|
CUTSCENE_SYSTEM.refs.entityLastRef = entity;
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId) {
|
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId) {
|
||||||
if(areaId == CUTSCENE_AREA_LAST_CREATED) {
|
if(areaId == CUTSCENE_REF_AREA_LAST_CREATED) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
CUTSCENE_SYSTEM.areaLastCreated != CUTSCENE_AREA_LAST_CREATED,
|
CUTSCENE_SYSTEM.refs.areaLastCreated != CUTSCENE_REF_AREA_LAST_CREATED,
|
||||||
"CUTSCENE_AREA_LAST_CREATED used but no map area has been created"
|
"CUTSCENE_REF_AREA_LAST_CREATED used but no map area has been created"
|
||||||
);
|
);
|
||||||
return CUTSCENE_SYSTEM.areaLastCreated;
|
return CUTSCENE_SYSTEM.refs.areaLastCreated;
|
||||||
}
|
}
|
||||||
return areaId;
|
return areaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cutsceneSystemGetTextMiniId(const uint8_t index) {
|
uint8_t cutsceneSystemGetTextMiniId(const uint8_t index) {
|
||||||
if(index == CUTSCENE_TEXT_MINI_LAST_CREATED) {
|
if(index == CUTSCENE_REF_TEXT_MINI_LAST_CREATED) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated != CUTSCENE_TEXT_MINI_LAST_CREATED,
|
CUTSCENE_SYSTEM.refs.textMiniLastCreated !=
|
||||||
"CUTSCENE_TEXT_MINI_LAST_CREATED used but no mini textbox has been "
|
CUTSCENE_REF_TEXT_MINI_LAST_CREATED,
|
||||||
|
"CUTSCENE_REF_TEXT_MINI_LAST_CREATED used but no mini textbox has been "
|
||||||
"shown"
|
"shown"
|
||||||
);
|
);
|
||||||
return CUTSCENE_SYSTEM.textMiniLastCreated;
|
return CUTSCENE_SYSTEM.refs.textMiniLastCreated;
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -251,68 +268,49 @@ void cutsceneSystemSetTextCache(const char_t *text) {
|
|||||||
void cutsceneSystemNext() {
|
void cutsceneSystemNext() {
|
||||||
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
||||||
|
|
||||||
// Pop the just-finished item off the front rather than advancing an
|
// Pop the just-finished item off the front.
|
||||||
// index further into the array - see CUTSCENE_SYSTEM.currentItem's doc
|
if(CUTSCENE_SYSTEM.currentItem == CUTSCENE_CURRENT_ITEM_NONE) {
|
||||||
// comment. The very first call (currentItem still 0xFF) has nothing to
|
|
||||||
// pop yet; it just marks the cutscene as started.
|
|
||||||
if(CUTSCENE_SYSTEM.currentItem == 0xFF) {
|
|
||||||
CUTSCENE_SYSTEM.currentItem = 0;
|
CUTSCENE_SYSTEM.currentItem = 0;
|
||||||
} else {
|
} else {
|
||||||
cutsceneRemoveFront(CUTSCENE_SYSTEM.scene, 1);
|
cutscene_t *scene = CUTSCENE_SYSTEM.scene;
|
||||||
|
const size_t tailCount = (size_t)scene->itemCount - 1;
|
||||||
|
if(tailCount > 0) {
|
||||||
|
memoryMove(
|
||||||
|
&scene->items[0], &scene->items[1], tailCount * sizeof(cutsceneitem_t)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
scene->itemCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of the cutscene? Note that a CUTSCENE_ITEM_TYPE_INSERT item's
|
// End of the cutscene?
|
||||||
// spliced-in items are physically part of this same array (see
|
|
||||||
// cutsceneSystemInsertCutscene), so there's no separate "parent scene"
|
|
||||||
// to fall back into here - itemCount already accounts for them.
|
|
||||||
if(CUTSCENE_SYSTEM.scene->itemCount == 0) {
|
if(CUTSCENE_SYSTEM.scene->itemCount == 0) {
|
||||||
// Saved and cleared before firing so a callback that immediately
|
|
||||||
// starts another cutscene (or sets its own onComplete) isn't clobbered
|
|
||||||
// by this function's own cleanup running after it - same reentrancy
|
|
||||||
// hazard as uiFocusPop, see src/dusk/ui/focus/uifocus.c.
|
|
||||||
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
|
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.scene = NULL;
|
CUTSCENE_SYSTEM.scene = NULL;
|
||||||
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
|
||||||
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
||||||
CUTSCENE_SYSTEM.entityInteract = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityInteracted = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
||||||
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
||||||
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
|
||||||
CUTSCENE_SYSTEM.onComplete = NULL;
|
|
||||||
|
|
||||||
if(onComplete != NULL) onComplete(NULL);
|
if(onComplete != NULL) onComplete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start item.
|
// Start next (now current) item
|
||||||
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
||||||
memset(&CUTSCENE_SYSTEM.data, 0, sizeof(CUTSCENE_SYSTEM.data));
|
memset(&CUTSCENE_SYSTEM.data, 0, sizeof(CUTSCENE_SYSTEM.data));
|
||||||
cutsceneItemStart(item, &CUTSCENE_SYSTEM.data);
|
cutsceneItemStart(item, &CUTSCENE_SYSTEM.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneGoTo(const char_t *name) {
|
void cutsceneSystemGoTo(const char_t *name) {
|
||||||
assertNotNull(name, "Name cannot be NULL");
|
assertNotNull(name, "Name cannot be NULL");
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
CUTSCENE_SYSTEM.scene, "cutsceneGoTo called with no cutscene running"
|
CUTSCENE_SYSTEM.scene, "cutsceneSystemGoTo called with no cutscene running"
|
||||||
|
);
|
||||||
|
assertTrue(
|
||||||
|
CUTSCENE_SYSTEM.scene == &CUTSCENE_SYSTEM.loadedScene,
|
||||||
|
"cutsceneSystemGoTo requires the running cutscene file reference (1)"
|
||||||
);
|
);
|
||||||
// A marker behind the current position can't be found in the live
|
|
||||||
// queue - already-run items are evicted from its front as the
|
|
||||||
// cutscene advances (see cutsceneSystemNext/cutsceneRemoveFront), so
|
|
||||||
// the untouched original has to be re-parsed from source instead. Only
|
|
||||||
// supported when the running cutscene is the one cutsceneSystemLoad/
|
|
||||||
// cutsceneCutsceneResolve populated - a C-authored cutscene_t, or
|
|
||||||
// content spliced in via INSERT/battleStateExecutingInit, has no
|
|
||||||
// source to reload from, so a backward jump into those isn't supported
|
|
||||||
// yet.
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
CUTSCENE_SYSTEM.scene == &CUTSCENE_SYSTEM.loadedScene &&
|
|
||||||
CUTSCENE_SYSTEM.loadedFile[0] != '\0',
|
CUTSCENE_SYSTEM.loadedFile[0] != '\0',
|
||||||
"cutsceneGoTo requires the running cutscene to have come from "
|
"cutsceneSystemGoTo requires the running cutscene file reference (2)"
|
||||||
"cutsceneSystemLoad/cutsceneCutsceneResolve"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
cutscene_t freshScene = { .items = CUTSCENE_SYSTEM.gotoScratchItems };
|
cutscene_t freshScene = { .items = CUTSCENE_SYSTEM.gotoScratchItems };
|
||||||
@@ -326,6 +324,7 @@ void cutsceneGoTo(const char_t *name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search for the marker with the given name...
|
||||||
for(uint8_t i = 0; i < freshScene.itemCount; i++) {
|
for(uint8_t i = 0; i < freshScene.itemCount; i++) {
|
||||||
const cutsceneitem_t *item = &freshScene.items[i];
|
const cutsceneitem_t *item = &freshScene.items[i];
|
||||||
if(
|
if(
|
||||||
@@ -333,10 +332,8 @@ void cutsceneGoTo(const char_t *name) {
|
|||||||
!stringEquals(item->marker.name, name)
|
!stringEquals(item->marker.name, name)
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
// Commit: replace the live queue outright with marker-onward from
|
// Found, so splice the cutscene at that point and start it, the remaining
|
||||||
// the fresh parse. Nothing before the marker (including whatever was
|
// items being the rest of the cutscene after the marker.
|
||||||
// running) gets Started - only the marker item itself does, same as
|
|
||||||
// the old in-place jump's semantics.
|
|
||||||
const uint8_t remaining = freshScene.itemCount - i;
|
const uint8_t remaining = freshScene.itemCount - i;
|
||||||
memoryCopy(
|
memoryCopy(
|
||||||
CUTSCENE_SYSTEM.loadedItems, &freshScene.items[i],
|
CUTSCENE_SYSTEM.loadedItems, &freshScene.items[i],
|
||||||
@@ -352,19 +349,10 @@ void cutsceneGoTo(const char_t *name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(false, "cutsceneGoTo: no marker found with that name");
|
assertTrue(false, "cutsceneSystemGoTo: no marker found with that name");
|
||||||
}
|
|
||||||
|
|
||||||
void cutsceneSystemUpdate() {
|
|
||||||
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
|
||||||
|
|
||||||
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
|
||||||
if(cutsceneItemUpdate(item, &CUTSCENE_SYSTEM.data)) cutsceneSystemNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
|
const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
|
||||||
if(CUTSCENE_SYSTEM.scene == NULL) return NULL;
|
if(CUTSCENE_SYSTEM.scene == NULL) return NULL;
|
||||||
|
|
||||||
// Always index 0 - see CUTSCENE_SYSTEM.currentItem's doc comment.
|
|
||||||
return &CUTSCENE_SYSTEM.scene->items[0];
|
return &CUTSCENE_SYSTEM.scene->items[0];
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "cutscene.h"
|
#include "cutscene.h"
|
||||||
|
#include "cutsceneref.h"
|
||||||
typedef struct entity_s entity_t;
|
|
||||||
|
|
||||||
#define CUTSCENE_ENTITY_INTERACT ((uint8_t)0xFE)
|
#define CUTSCENE_ENTITY_INTERACT ((uint8_t)0xFE)
|
||||||
#define CUTSCENE_ENTITY_INTERACTED ((uint8_t)0xFD)
|
#define CUTSCENE_ENTITY_INTERACTED ((uint8_t)0xFD)
|
||||||
#define CUTSCENE_ENTITY_LAST_CREATED ((uint8_t)0xFC)
|
#define CUTSCENE_ENTITY_LAST_CREATED ((uint8_t)0xFC)
|
||||||
#define CUTSCENE_ENTITY_LAST_REF ((uint8_t)0xFB)
|
#define CUTSCENE_ENTITY_LAST_REF ((uint8_t)0xFB)
|
||||||
#define CUTSCENE_AREA_LAST_CREATED ((uint8_t)0xFF)
|
#define CUTSCENE_CURRENT_ITEM_NONE ((uint8_t)0xFF)
|
||||||
#define CUTSCENE_TEXT_MINI_LAST_CREATED ((uint8_t)0xFA)
|
|
||||||
|
|
||||||
#define CUTSCENE_TEXT_CACHE_MAX 64
|
#define CUTSCENE_TEXT_CACHE_MAX 64
|
||||||
#define CUTSCENE_LOADED_ITEMS_MAX 128
|
#define CUTSCENE_LOADED_ITEMS_MAX 128
|
||||||
@@ -23,21 +21,10 @@ typedef struct entity_s entity_t;
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
cutscene_t *scene;
|
cutscene_t *scene;
|
||||||
|
|
||||||
// 0xFF if nothing has started running yet, otherwise always 0 - the
|
|
||||||
// currently-running item is always scene->items[0]; cutsceneSystemNext
|
|
||||||
// removes it from the front (see cutsceneRemoveFront) rather than
|
|
||||||
// advancing an index further into the array, so an item's slot is
|
|
||||||
// reclaimed the moment it finishes instead of sitting there as dead
|
|
||||||
// weight for the rest of the cutscene's run.
|
|
||||||
uint8_t currentItem;
|
uint8_t currentItem;
|
||||||
cutscenepause_t pause;
|
cutscenepause_t pause;
|
||||||
entity_t *entityInteract;
|
|
||||||
entity_t *entityInteracted;
|
cutsceneref_t refs;
|
||||||
entity_t *entityLastCreated;
|
|
||||||
entity_t *entityLastRef;
|
|
||||||
uint8_t areaLastCreated;
|
|
||||||
uint8_t textMiniLastCreated;
|
|
||||||
|
|
||||||
// Free-form text cache for the running cutscene - see
|
// Free-form text cache for the running cutscene - see
|
||||||
// cutsceneSystemGetTextCache/cutsceneSystemSetTextCache.
|
// cutsceneSystemGetTextCache/cutsceneSystemSetTextCache.
|
||||||
@@ -49,17 +36,12 @@ typedef struct {
|
|||||||
// See cutsceneSystemSetOnComplete.
|
// See cutsceneSystemSetOnComplete.
|
||||||
cutscenecallback_t onComplete;
|
cutscenecallback_t onComplete;
|
||||||
|
|
||||||
|
// Cache and storage used for the dynamically loaded cutscenes.
|
||||||
cutsceneitem_t loadedItems[CUTSCENE_LOADED_ITEMS_MAX];
|
cutsceneitem_t loadedItems[CUTSCENE_LOADED_ITEMS_MAX];
|
||||||
cutscene_t loadedScene;
|
cutscene_t loadedScene;
|
||||||
|
|
||||||
// Filename last passed to cutsceneSystemLoad - see cutsceneRestart.
|
|
||||||
char_t loadedFile[ASSET_FILE_NAME_MAX];
|
char_t loadedFile[ASSET_FILE_NAME_MAX];
|
||||||
|
|
||||||
// Scratch space for cutsceneGoTo's re-parse of loadedFile - a fixed,
|
// Cutscene items scratch, mostly used for CUTSCENE_INSERT items.
|
||||||
// persistent buffer rather than a local one since cutsceneitem_t is
|
|
||||||
// large (e.g. cutscenemodal_t alone carries a 256-byte message buffer),
|
|
||||||
// making a CUTSCENE_LOADED_ITEMS_MAX-sized array too big to put on the
|
|
||||||
// stack on constrained platforms (PSP/GameCube/Wii).
|
|
||||||
cutsceneitem_t gotoScratchItems[CUTSCENE_LOADED_ITEMS_MAX];
|
cutsceneitem_t gotoScratchItems[CUTSCENE_LOADED_ITEMS_MAX];
|
||||||
} cutscenesystem_t;
|
} cutscenesystem_t;
|
||||||
|
|
||||||
@@ -156,6 +138,21 @@ void cutsceneSystemInsertItems(
|
|||||||
*/
|
*/
|
||||||
void cutsceneSystemInsertCutscene(const cutscene_t *cutscene);
|
void cutsceneSystemInsertCutscene(const cutscene_t *cutscene);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discards every item queued after index (e.g. index 0 keeps only the
|
||||||
|
* currently-running item and drops everything spliced in behind it),
|
||||||
|
* without disturbing index's own progress - e.g. so a callback that
|
||||||
|
* decides the rest of a batch-spliced sequence is now moot (a battle
|
||||||
|
* ending mid-round, with other fighters' still-queued move cutscenes and
|
||||||
|
* the round's trailing state transition left behind) can drop it before
|
||||||
|
* splicing in its own follow-up items, instead of leaving it to run
|
||||||
|
* afterward against torn-down state.
|
||||||
|
*
|
||||||
|
* @param index Index to keep - everything after it is discarded. Must be
|
||||||
|
* < the running cutscene's current item count.
|
||||||
|
*/
|
||||||
|
void cutsceneSystemClearAfter(const uint8_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and immediately starts a cutscene asset by file name.
|
* Loads and immediately starts a cutscene asset by file name.
|
||||||
*
|
*
|
||||||
@@ -186,7 +183,7 @@ void cutsceneSystemSetOnComplete(cutscenecallback_t onComplete);
|
|||||||
entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex);
|
entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a raw map area ID (or CUTSCENE_AREA_LAST_CREATED sentinel) to
|
* Resolves a raw map area ID (or CUTSCENE_REF_AREA_LAST_CREATED sentinel) to
|
||||||
* a concrete map area ID.
|
* a concrete map area ID.
|
||||||
*
|
*
|
||||||
* @param areaId Raw map area ID or sentinel value.
|
* @param areaId Raw map area ID or sentinel value.
|
||||||
@@ -195,7 +192,7 @@ entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex);
|
|||||||
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId);
|
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a raw mini textbox slot index (or CUTSCENE_TEXT_MINI_LAST_CREATED
|
* Resolves a raw mini textbox slot index (or CUTSCENE_REF_TEXT_MINI_LAST_CREATED
|
||||||
* sentinel) to a concrete UI_TEXTBOX_MINI_LIST slot index.
|
* sentinel) to a concrete UI_TEXTBOX_MINI_LIST slot index.
|
||||||
*
|
*
|
||||||
* @param index Raw slot index or sentinel value.
|
* @param index Raw slot index or sentinel value.
|
||||||
@@ -224,25 +221,12 @@ void cutsceneSystemSetTextCache(const char_t *text);
|
|||||||
void cutsceneSystemNext();
|
void cutsceneSystemNext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jumps the running cutscene directly to the marker with the given name
|
* Jumps to a cutscene marker directly. If the cutscene is a loaded cutscene,
|
||||||
* and starts it immediately. Re-parses the cutscene fresh from its
|
* this will result in it being reloaded (due to unshift nature of cutscenes).
|
||||||
* source file (see cutsceneLoadParse) and replaces the live queue with
|
|
||||||
* marker-onward from that fresh parse - items already run may have been
|
|
||||||
* evicted from the front of the live queue (see
|
|
||||||
* cutsceneSystemNext/cutsceneRemoveFront), so a marker behind the
|
|
||||||
* current position can only be found in the untouched original. Nothing
|
|
||||||
* before the marker gets Started, only the marker item itself.
|
|
||||||
*
|
|
||||||
* Requires the running cutscene to be the one cutsceneSystemLoad/
|
|
||||||
* cutsceneCutsceneResolve populated (i.e. CUTSCENE_SYSTEM.scene ==
|
|
||||||
* &CUTSCENE_SYSTEM.loadedScene) - asserts otherwise. A C-authored
|
|
||||||
* cutscene_t, or content spliced in via INSERT/battleStateExecutingInit,
|
|
||||||
* has no source file to reload from, so backward jumps into those
|
|
||||||
* aren't supported yet.
|
|
||||||
*
|
*
|
||||||
* @param name Marker name to search for.
|
* @param name Marker name to search for.
|
||||||
*/
|
*/
|
||||||
void cutsceneGoTo(const char_t *name);
|
void cutsceneSystemGoTo(const char_t *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the cutscene system for one frame.
|
* Update the cutscene system for one frame.
|
||||||
|
|||||||
@@ -21,3 +21,4 @@ add_subdirectory(save)
|
|||||||
add_subdirectory(audio)
|
add_subdirectory(audio)
|
||||||
add_subdirectory(json)
|
add_subdirectory(json)
|
||||||
add_subdirectory(story)
|
add_subdirectory(story)
|
||||||
|
add_subdirectory(party)
|
||||||
@@ -35,6 +35,12 @@ void cutsceneBattlePostMoveStart(
|
|||||||
|
|
||||||
BATTLE.result = allyAlive ? BATTLE_RESULT_WIN : BATTLE_RESULT_LOSS;
|
BATTLE.result = allyAlive ? BATTLE_RESULT_WIN : BATTLE_RESULT_LOSS;
|
||||||
|
|
||||||
|
// Drop the rest of this round's already-spliced items (other fighters'
|
||||||
|
// still-pending move cutscenes, the trailing BATTLE_SET_STATE(PRE_ROUND) -
|
||||||
|
// see battleStateExecutingInit) - the battle is over, so none of that
|
||||||
|
// should run against the WON/LOST/ENDING transition about to replace it.
|
||||||
|
cutsceneSystemClearAfter(CUTSCENE_SYSTEM.currentItem);
|
||||||
|
|
||||||
const cutsceneitem_t items[] = {
|
const cutsceneitem_t items[] = {
|
||||||
{
|
{
|
||||||
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
|
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
|
||||||
|
|||||||
@@ -34,17 +34,8 @@ void cutsceneBattleStartStart(
|
|||||||
sizeof(CUTSCENE_BATTLE_START_ENEMY_POOL)
|
sizeof(CUTSCENE_BATTLE_START_ENEMY_POOL)
|
||||||
);
|
);
|
||||||
for(uint8_t i = 0; i < config->enemyCount; i++) {
|
for(uint8_t i = 0; i < config->enemyCount; i++) {
|
||||||
const cutscenebattlestartenemy_t *enemyConfig = &config->enemies[i];
|
|
||||||
battlefighter_t *enemy = &CUTSCENE_BATTLE_START_ENEMY_POOL[i];
|
battlefighter_t *enemy = &CUTSCENE_BATTLE_START_ENEMY_POOL[i];
|
||||||
|
*enemy = config->enemies[i].fighter;
|
||||||
battleFighterInit(
|
|
||||||
enemy, BATTLE_FIGHTER_TEAM_ENEMY, BATTLE_FIGHTER_CONTROLLER_AI,
|
|
||||||
enemyConfig->stats
|
|
||||||
);
|
|
||||||
for(uint8_t a = 0; a < enemyConfig->abilityCount; a++) {
|
|
||||||
battleFighterAbilityAdd(enemy, enemyConfig->abilities[a]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fighters[i] = enemy;
|
fighters[i] = enemy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,54 +79,14 @@ errorret_t cutsceneBattleStartLoad(
|
|||||||
while((enemyVal = yyjson_arr_iter_next(&iter)) != NULL) {
|
while((enemyVal = yyjson_arr_iter_next(&iter)) != NULL) {
|
||||||
cutscenebattlestartenemy_t *enemy = &item->battleStart.enemies[e];
|
cutscenebattlestartenemy_t *enemy = &item->battleStart.enemies[e];
|
||||||
|
|
||||||
yyjson_val *stats = yyjson_obj_get(enemyVal, "stats");
|
errorret_t parseResult = battleFighterParse(&enemy->fighter, enemyVal);
|
||||||
if(!yyjson_is_obj(stats)) {
|
if(errorIsNotOk(parseResult)) errorChain(parseResult);
|
||||||
errorThrow(
|
|
||||||
"Cutscene item (BATTLE_START): enemies[%u] is missing 'stats'",
|
|
||||||
(uint32_t)e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
enemy->stats.attack = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "attack"));
|
|
||||||
enemy->stats.defense = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "defense"));
|
|
||||||
enemy->stats.magic = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "magic"));
|
|
||||||
enemy->stats.speed = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "speed"));
|
|
||||||
enemy->stats.luck = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "luck"));
|
|
||||||
enemy->stats.healthMax = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "healthMax"));
|
|
||||||
enemy->stats.mpMax = (uint16_t)yyjson_get_int(yyjson_obj_get(stats, "mpMax"));
|
|
||||||
|
|
||||||
yyjson_val *abilities = yyjson_obj_get(enemyVal, "abilities");
|
// Enemy JSON never specifies team/controller (battleFighterParse just
|
||||||
if(abilities != NULL) {
|
// defaulted them to ALLY/PLAYER) - BATTLE_START enemies are always
|
||||||
size_t abilityCount = yyjson_arr_size(abilities);
|
// ENEMY/AI.
|
||||||
if(
|
enemy->fighter.team = BATTLE_FIGHTER_TEAM_ENEMY;
|
||||||
!yyjson_is_arr(abilities) ||
|
enemy->fighter.controller = BATTLE_FIGHTER_CONTROLLER_AI;
|
||||||
abilityCount > BATTLE_FIGHTER_ABILITY_COUNT_MAX
|
|
||||||
) {
|
|
||||||
errorThrow(
|
|
||||||
"Cutscene item (BATTLE_START): enemies[%u].abilities must have "
|
|
||||||
"0-%u entries",
|
|
||||||
(uint32_t)e, (uint32_t)BATTLE_FIGHTER_ABILITY_COUNT_MAX
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
yyjson_arr_iter abilityIter = yyjson_arr_iter_with(abilities);
|
|
||||||
yyjson_val *abilityVal;
|
|
||||||
size_t a = 0;
|
|
||||||
while((abilityVal = yyjson_arr_iter_next(&abilityIter)) != NULL) {
|
|
||||||
const char_t *name = yyjson_get_str(abilityVal);
|
|
||||||
battlemoveid_t ability = name == NULL
|
|
||||||
? BATTLE_MOVE_ID_NULL : battleMoveGetIdByName(name);
|
|
||||||
if(ability == BATTLE_MOVE_ID_NULL) {
|
|
||||||
errorThrow(
|
|
||||||
"Cutscene item (BATTLE_START): enemies[%u].abilities[%u] is "
|
|
||||||
"invalid",
|
|
||||||
(uint32_t)e, (uint32_t)a
|
|
||||||
);
|
|
||||||
}
|
|
||||||
enemy->abilities[a] = ability;
|
|
||||||
a++;
|
|
||||||
}
|
|
||||||
enemy->abilityCount = (uint8_t)abilityCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
e++;
|
e++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,11 @@
|
|||||||
#define CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX 4
|
#define CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX 4
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
battlefighterstats_t stats;
|
// Fully parsed at Load time via battleFighterParse (team/controller
|
||||||
battlemoveid_t abilities[BATTLE_FIGHTER_ABILITY_COUNT_MAX];
|
// forced to ENEMY/AI right after, since enemy JSON only ever supplies
|
||||||
uint8_t abilityCount;
|
// stats/abilities) - Start splices this directly into
|
||||||
|
// CUTSCENE_BATTLE_START_ENEMY_POOL, no further init needed.
|
||||||
|
battlefighter_t fighter;
|
||||||
} cutscenebattlestartenemy_t;
|
} cutscenebattlestartenemy_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
/**
|
/**
|
||||||
* Updates an idle item. Never completes on its own - the cutscene blocks
|
* Updates an idle item. Never completes on its own - the cutscene blocks
|
||||||
* here indefinitely until something external (e.g. a UI callback) calls
|
* here indefinitely until something external (e.g. a UI callback) calls
|
||||||
* cutsceneGoTo to jump elsewhere.
|
* cutsceneSystemGoTo to jump elsewhere.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ typedef struct {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a marker item. A marker does nothing on its own - it exists
|
* Starts a marker item. A marker does nothing on its own - it exists
|
||||||
* purely as a named position for cutsceneGoTo to jump to.
|
* purely as a named position for cutsceneSystemGoTo to jump to.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -371,6 +371,35 @@ cutsceneitemcallbacks_t CUTSCENE_ITEM_CALLBACKS[CUTSCENE_ITEM_TYPE_COUNT] = {
|
|||||||
.update = cutsceneStoryWaitFlagUpdate,
|
.update = cutsceneStoryWaitFlagUpdate,
|
||||||
.jsonName = "STORY_WAIT_FLAG",
|
.jsonName = "STORY_WAIT_FLAG",
|
||||||
.load = cutsceneStoryWaitFlagLoad
|
.load = cutsceneStoryWaitFlagLoad
|
||||||
|
},
|
||||||
|
|
||||||
|
// Party
|
||||||
|
[CUTSCENE_ITEM_TYPE_PARTY_ADD_MEMBER] = {
|
||||||
|
.init = cutscenePartyAddMemberStart,
|
||||||
|
.update = cutscenePartyAddMemberUpdate,
|
||||||
|
.jsonName = "PARTY_ADD_MEMBER",
|
||||||
|
.load = cutscenePartyAddMemberLoad
|
||||||
|
},
|
||||||
|
|
||||||
|
[CUTSCENE_ITEM_TYPE_PARTY_REMOVE_MEMBER] = {
|
||||||
|
.init = cutscenePartyRemoveMemberStart,
|
||||||
|
.update = cutscenePartyRemoveMemberUpdate,
|
||||||
|
.jsonName = "PARTY_REMOVE_MEMBER",
|
||||||
|
.load = cutscenePartyRemoveMemberLoad
|
||||||
|
},
|
||||||
|
|
||||||
|
[CUTSCENE_ITEM_TYPE_PARTY_HEAL_MEMBER] = {
|
||||||
|
.init = cutscenePartyHealMemberStart,
|
||||||
|
.update = cutscenePartyHealMemberUpdate,
|
||||||
|
.jsonName = "PARTY_HEAL_MEMBER",
|
||||||
|
.load = cutscenePartyHealMemberLoad
|
||||||
|
},
|
||||||
|
|
||||||
|
[CUTSCENE_ITEM_TYPE_PARTY_HEAL_ALL] = {
|
||||||
|
.init = cutscenePartyHealAllStart,
|
||||||
|
.update = cutscenePartyHealAllUpdate,
|
||||||
|
.jsonName = "PARTY_HEAL_ALL",
|
||||||
|
.load = cutsceneItemLoadNoop
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -430,8 +459,19 @@ bool_t cutsceneCutsceneUpdate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cutscene_t * cutsceneCutsceneResolve(const char_t *name) {
|
cutscene_t * cutsceneCutsceneResolve(const char_t *name) {
|
||||||
|
// Copy name out before it can be invalidated: this is commonly called
|
||||||
|
// with a pointer into CUTSCENE_SYSTEM.loadedItems itself (a running
|
||||||
|
// CUTSCENE/INSERT item's own cutsceneRef.name/insert.name field, when
|
||||||
|
// the running cutscene IS loadedScene, e.g. initial.jsonc's closing
|
||||||
|
// CUTSCENE item into main_menu.jsonc) - cutsceneLoadParse below parses
|
||||||
|
// straight into that same shared loadedItems buffer, overwriting the
|
||||||
|
// very memory name points into with the target cutscene's own first
|
||||||
|
// item before this function is done reading name.
|
||||||
|
char_t nameCopy[ASSET_FILE_NAME_MAX];
|
||||||
|
stringCopy(nameCopy, name, ASSET_FILE_NAME_MAX - 1);
|
||||||
|
|
||||||
errorret_t result = cutsceneLoadParse(
|
errorret_t result = cutsceneLoadParse(
|
||||||
name, &CUTSCENE_SYSTEM.loadedScene, CUTSCENE_SYSTEM.loadedItems,
|
nameCopy, &CUTSCENE_SYSTEM.loadedScene, CUTSCENE_SYSTEM.loadedItems,
|
||||||
CUTSCENE_LOADED_ITEMS_MAX
|
CUTSCENE_LOADED_ITEMS_MAX
|
||||||
);
|
);
|
||||||
if(errorIsNotOk(result)) {
|
if(errorIsNotOk(result)) {
|
||||||
@@ -441,10 +481,10 @@ cutscene_t * cutsceneCutsceneResolve(const char_t *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shares loadedScene/loadedItems with cutsceneSystemLoad, so track the
|
// Shares loadedScene/loadedItems with cutsceneSystemLoad, so track the
|
||||||
// source the same way it does - cutsceneGoTo needs this to reload the
|
// source the same way it does - cutsceneSystemGoTo needs this to reload the
|
||||||
// untouched original when jumping to a marker behind the current
|
// untouched original when jumping to a marker behind the current
|
||||||
// position (see cutsceneGoTo's doc comment).
|
// position (see cutsceneSystemGoTo's doc comment).
|
||||||
stringCopy(CUTSCENE_SYSTEM.loadedFile, name, ASSET_FILE_NAME_MAX - 1);
|
stringCopy(CUTSCENE_SYSTEM.loadedFile, nameCopy, ASSET_FILE_NAME_MAX - 1);
|
||||||
|
|
||||||
return &CUTSCENE_SYSTEM.loadedScene;
|
return &CUTSCENE_SYSTEM.loadedScene;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,10 @@
|
|||||||
#include "audio/cutsceneaudioset.h"
|
#include "audio/cutsceneaudioset.h"
|
||||||
#include "story/cutscenestorysetflag.h"
|
#include "story/cutscenestorysetflag.h"
|
||||||
#include "story/cutscenestorywaitflag.h"
|
#include "story/cutscenestorywaitflag.h"
|
||||||
|
#include "party/cutscenepartyaddmember.h"
|
||||||
|
#include "party/cutscenepartyremovemember.h"
|
||||||
|
#include "party/cutscenepartyhealmember.h"
|
||||||
|
#include "party/cutscenepartyhealall.h"
|
||||||
|
|
||||||
typedef struct cutscene_s cutscene_t;
|
typedef struct cutscene_s cutscene_t;
|
||||||
|
|
||||||
@@ -144,6 +148,9 @@ struct cutsceneitem_s {
|
|||||||
cutsceneuishow_t uiShow;
|
cutsceneuishow_t uiShow;
|
||||||
cutscenestorysetflag_t storySetFlag;
|
cutscenestorysetflag_t storySetFlag;
|
||||||
cutscenestorywaitflag_t storyWaitFlag;
|
cutscenestorywaitflag_t storyWaitFlag;
|
||||||
|
cutscenepartyaddmember_t partyAddMember;
|
||||||
|
cutscenepartyremovemember_t partyRemoveMember;
|
||||||
|
cutscenepartyhealmember_t partyHealMember;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,12 @@ typedef enum {
|
|||||||
CUTSCENE_ITEM_TYPE_STORY_SET_FLAG,
|
CUTSCENE_ITEM_TYPE_STORY_SET_FLAG,
|
||||||
CUTSCENE_ITEM_TYPE_STORY_WAIT_FLAG,
|
CUTSCENE_ITEM_TYPE_STORY_WAIT_FLAG,
|
||||||
|
|
||||||
|
// Party
|
||||||
|
CUTSCENE_ITEM_TYPE_PARTY_ADD_MEMBER,
|
||||||
|
CUTSCENE_ITEM_TYPE_PARTY_REMOVE_MEMBER,
|
||||||
|
CUTSCENE_ITEM_TYPE_PARTY_HEAL_MEMBER,
|
||||||
|
CUTSCENE_ITEM_TYPE_PARTY_HEAL_ALL,
|
||||||
|
|
||||||
CUTSCENE_ITEM_TYPE_COUNT
|
CUTSCENE_ITEM_TYPE_COUNT
|
||||||
} cutsceneitemtype_t;
|
} cutsceneitemtype_t;
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ void cutsceneEntityAddStart(
|
|||||||
entityInit(entity, item->entityAdd.entityType);
|
entityInit(entity, item->entityAdd.entityType);
|
||||||
entityPositionSet(entity, item->entityAdd.position);// Also assigns chunk.
|
entityPositionSet(entity, item->entityAdd.position);// Also assigns chunk.
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.entityLastCreated = entity;
|
CUTSCENE_SYSTEM.refs.entityLastCreated = entity;
|
||||||
CUTSCENE_SYSTEM.entityLastRef = entity;
|
CUTSCENE_SYSTEM.refs.entityLastRef = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t cutsceneEntityAddUpdate(
|
bool_t cutsceneEntityAddUpdate(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "yyjson.h"
|
#include "yyjson.h"
|
||||||
|
|
||||||
// Sentinel accepted in place of a literal area id - see cutscenesystem.h's
|
// Sentinel accepted in place of a literal area id - see cutscenesystem.h's
|
||||||
// CUTSCENE_AREA_LAST_CREATED. Kept local since it's a JSON-authoring
|
// CUTSCENE_REF_AREA_LAST_CREATED. Kept local since it's a JSON-authoring
|
||||||
// convenience, not part of the item struct definitions themselves.
|
// convenience, not part of the item struct definitions themselves.
|
||||||
#define CUTSCENE_JSON_AREA_SENTINEL_LAST_CREATED ((uint8_t)0xFF)
|
#define CUTSCENE_JSON_AREA_SENTINEL_LAST_CREATED ((uint8_t)0xFF)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ void cutsceneMapAreaAddStart(
|
|||||||
const cutsceneitem_t *item,
|
const cutsceneitem_t *item,
|
||||||
cutsceneitemdata_t *data
|
cutsceneitemdata_t *data
|
||||||
) {
|
) {
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = mapAreaAdd(
|
CUTSCENE_SYSTEM.refs.areaLastCreated = mapAreaAdd(
|
||||||
item->mapAreaAdd.min,
|
item->mapAreaAdd.min,
|
||||||
item->mapAreaAdd.max,
|
item->mapAreaAdd.max,
|
||||||
item->mapAreaAdd.callback,
|
item->mapAreaAdd.callback,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ typedef struct {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a map area add step (adds the area immediately, storing its ID
|
* Starts a map area add step (adds the area immediately, storing its ID
|
||||||
* in CUTSCENE_SYSTEM.areaLastCreated).
|
* in CUTSCENE_SYSTEM.refs.areaLastCreated).
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ typedef struct {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a map area remove step (removes the area immediately). Accepts
|
* Starts a map area remove step (removes the area immediately). Accepts
|
||||||
* CUTSCENE_AREA_LAST_CREATED in place of a literal area ID.
|
* CUTSCENE_REF_AREA_LAST_CREATED in place of a literal area ID.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
cutscenepartyaddmember.c
|
||||||
|
cutscenepartyremovemember.c
|
||||||
|
cutscenepartyhealmember.c
|
||||||
|
cutscenepartyhealall.c
|
||||||
|
)
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
|
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
|
||||||
|
|
||||||
|
void cutscenePartyAddMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
partyAddMember(item->partyAddMember.memberIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t cutscenePartyAddMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t cutscenePartyAddMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
) {
|
||||||
|
char_t key[PARTY_KEY_LENGTH_MAX];
|
||||||
|
if(!cutsceneJsonCopyString(itemObj, "key", NULL, key, PARTY_KEY_LENGTH_MAX)) {
|
||||||
|
errorThrow("Cutscene item (PARTY_ADD_MEMBER): missing/invalid 'key'");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t memberIndex = partyGetMemberIndexByKey(key);
|
||||||
|
if(memberIndex == PARTY_MEMBER_NOT_FOUND) {
|
||||||
|
errorThrow("Cutscene item (PARTY_ADD_MEMBER): no member with key '%s'", key);
|
||||||
|
}
|
||||||
|
item->partyAddMember.memberIndex = memberIndex;
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// Resolved from the JSON 'key' field at load time (see
|
||||||
|
// partyGetMemberIndexByKey) - not a raw JSON field itself.
|
||||||
|
uint8_t memberIndex;
|
||||||
|
} cutscenepartyaddmember_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a PARTY_ADD_MEMBER item, activating the configured existing
|
||||||
|
* roster member into the current save slot's active party order (see
|
||||||
|
* partyAddMember). No-op if already active or there's no free order slot.
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
*/
|
||||||
|
void cutscenePartyAddMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a PARTY_ADD_MEMBER item (always completes immediately).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
* @returns true always.
|
||||||
|
*/
|
||||||
|
bool_t cutscenePartyAddMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a PARTY_ADD_MEMBER cutscene item's JSON fields into item:
|
||||||
|
* 'key', a required string matching a party.jsonc member key, resolved to
|
||||||
|
* its roster index via partyGetMemberIndexByKey.
|
||||||
|
*
|
||||||
|
* @param itemObj The item's JSON object.
|
||||||
|
* @param item Destination item, already zeroed by the caller.
|
||||||
|
* @return Error code indicating success or failure of the parse.
|
||||||
|
*/
|
||||||
|
errorret_t cutscenePartyAddMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
);
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
|
|
||||||
|
void cutscenePartyHealAllStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
partyHealAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t cutscenePartyHealAllUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a PARTY_HEAL_ALL item, fully restoring every occupied slot in
|
||||||
|
* the current save slot's party roster (see partyHealAll).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
*/
|
||||||
|
void cutscenePartyHealAllStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a PARTY_HEAL_ALL item (always completes immediately).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
* @returns true always.
|
||||||
|
*/
|
||||||
|
bool_t cutscenePartyHealAllUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
|
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
|
||||||
|
|
||||||
|
void cutscenePartyHealMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
partyHealMember(item->partyHealMember.memberIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t cutscenePartyHealMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t cutscenePartyHealMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
) {
|
||||||
|
char_t key[PARTY_KEY_LENGTH_MAX];
|
||||||
|
if(!cutsceneJsonCopyString(itemObj, "key", NULL, key, PARTY_KEY_LENGTH_MAX)) {
|
||||||
|
errorThrow("Cutscene item (PARTY_HEAL_MEMBER): missing/invalid 'key'");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t memberIndex = partyGetMemberIndexByKey(key);
|
||||||
|
if(memberIndex == PARTY_MEMBER_NOT_FOUND) {
|
||||||
|
errorThrow("Cutscene item (PARTY_HEAL_MEMBER): no member with key '%s'", key);
|
||||||
|
}
|
||||||
|
item->partyHealMember.memberIndex = memberIndex;
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// Resolved from the JSON 'key' field at load time (see
|
||||||
|
// partyGetMemberIndexByKey) - not a raw JSON field itself.
|
||||||
|
uint8_t memberIndex;
|
||||||
|
} cutscenepartyhealmember_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a PARTY_HEAL_MEMBER item, fully restoring the configured member's
|
||||||
|
* health/mp and reviving it if dead (see partyHealMember).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
*/
|
||||||
|
void cutscenePartyHealMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a PARTY_HEAL_MEMBER item (always completes immediately).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
* @returns true always.
|
||||||
|
*/
|
||||||
|
bool_t cutscenePartyHealMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a PARTY_HEAL_MEMBER cutscene item's JSON fields into item:
|
||||||
|
* 'key', a required string matching a party.jsonc member key, resolved to
|
||||||
|
* its roster index via partyGetMemberIndexByKey.
|
||||||
|
*
|
||||||
|
* @param itemObj The item's JSON object.
|
||||||
|
* @param item Destination item, already zeroed by the caller.
|
||||||
|
* @return Error code indicating success or failure of the parse.
|
||||||
|
*/
|
||||||
|
errorret_t cutscenePartyHealMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
);
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
|
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
|
||||||
|
|
||||||
|
void cutscenePartyRemoveMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
partyRemoveMember(item->partyRemoveMember.memberIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t cutscenePartyRemoveMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t cutscenePartyRemoveMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
) {
|
||||||
|
char_t key[PARTY_KEY_LENGTH_MAX];
|
||||||
|
if(!cutsceneJsonCopyString(itemObj, "key", NULL, key, PARTY_KEY_LENGTH_MAX)) {
|
||||||
|
errorThrow("Cutscene item (PARTY_REMOVE_MEMBER): missing/invalid 'key'");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t memberIndex = partyGetMemberIndexByKey(key);
|
||||||
|
if(memberIndex == PARTY_MEMBER_NOT_FOUND) {
|
||||||
|
errorThrow(
|
||||||
|
"Cutscene item (PARTY_REMOVE_MEMBER): no member with key '%s'", key
|
||||||
|
);
|
||||||
|
}
|
||||||
|
item->partyRemoveMember.memberIndex = memberIndex;
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// Resolved from the JSON 'key' field at load time (see
|
||||||
|
// partyGetMemberIndexByKey) - not a raw JSON field itself.
|
||||||
|
uint8_t memberIndex;
|
||||||
|
} cutscenepartyremovemember_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a PARTY_REMOVE_MEMBER item, deactivating the configured member
|
||||||
|
* from the current save slot's active party order (see partyRemoveMember)
|
||||||
|
* - the roster member itself still exists, just no longer active.
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
*/
|
||||||
|
void cutscenePartyRemoveMemberStart(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a PARTY_REMOVE_MEMBER item (always completes immediately).
|
||||||
|
*
|
||||||
|
* @param item The cutscene item.
|
||||||
|
* @param data Runtime data storage.
|
||||||
|
* @returns true always.
|
||||||
|
*/
|
||||||
|
bool_t cutscenePartyRemoveMemberUpdate(
|
||||||
|
const cutsceneitem_t *item,
|
||||||
|
cutsceneitemdata_t *data
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a PARTY_REMOVE_MEMBER cutscene item's JSON fields into item:
|
||||||
|
* 'key', a required string matching a party.jsonc member key, resolved to
|
||||||
|
* its roster index via partyGetMemberIndexByKey.
|
||||||
|
*
|
||||||
|
* @param itemObj The item's JSON object.
|
||||||
|
* @param item Destination item, already zeroed by the caller.
|
||||||
|
* @return Error code indicating success or failure of the parse.
|
||||||
|
*/
|
||||||
|
errorret_t cutscenePartyRemoveMemberLoad(
|
||||||
|
yyjson_val *itemObj,
|
||||||
|
cutsceneitem_t *item
|
||||||
|
);
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
void cutsceneSaveDeviceCheckCallback(savedevice_t *device, void *user) {
|
void cutsceneSaveDeviceCheckCallback(savedevice_t *device, void *user) {
|
||||||
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
||||||
cutsceneGoTo(
|
cutsceneSystemGoTo(
|
||||||
device != NULL ?
|
device != NULL ?
|
||||||
item->saveDeviceCheck.successMarker :
|
item->saveDeviceCheck.successMarker :
|
||||||
item->saveDeviceCheck.failureMarker
|
item->saveDeviceCheck.failureMarker
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ void cutsceneSaveDeviceCheckStart(
|
|||||||
* Updates a save-device-check item. Like a CUTSCENE_MODAL_OPTIONS item,
|
* Updates a save-device-check item. Like a CUTSCENE_MODAL_OPTIONS item,
|
||||||
* this never completes on its own - once saveFindAvailableDevice's
|
* this never completes on its own - once saveFindAvailableDevice's
|
||||||
* callback fires, it jumps straight to the item's successMarker or
|
* callback fires, it jumps straight to the item's successMarker or
|
||||||
* failureMarker via cutsceneGoTo.
|
* failureMarker via cutsceneSystemGoTo.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ void cutsceneSaveLoadAllSlotsStart(
|
|||||||
errorret_t result = saveLoadAllSlots();
|
errorret_t result = saveLoadAllSlots();
|
||||||
if(errorIsNotOk(result)) {
|
if(errorIsNotOk(result)) {
|
||||||
errorCatch(errorPrint(result));
|
errorCatch(errorPrint(result));
|
||||||
cutsceneGoTo(item->saveLoadAllSlots.failureMarker);
|
cutsceneSystemGoTo(item->saveLoadAllSlots.failureMarker);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cutsceneGoTo(item->saveLoadAllSlots.successMarker);
|
cutsceneSystemGoTo(item->saveLoadAllSlots.successMarker);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t cutsceneSaveLoadAllSlotsUpdate(
|
bool_t cutsceneSaveLoadAllSlotsUpdate(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Starts a save-load-all-slots item: calls saveLoadAllSlots() and jumps
|
* Starts a save-load-all-slots item: calls saveLoadAllSlots() and jumps
|
||||||
* straight to the item's successMarker or failureMarker via
|
* straight to the item's successMarker or failureMarker via
|
||||||
* cutsceneGoTo, depending on the result.
|
* cutsceneSystemGoTo, depending on the result.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void cutsceneModalStart(
|
|||||||
* CUTSCENE_MODAL_OPTIONS) always blocks regardless of the blocking
|
* CUTSCENE_MODAL_OPTIONS) always blocks regardless of the blocking
|
||||||
* field - it's dismissed by the player picking one of them, and the
|
* field - it's dismissed by the player picking one of them, and the
|
||||||
* option callback is responsible for moving the cutscene on from there
|
* option callback is responsible for moving the cutscene on from there
|
||||||
* (typically via cutsceneGoTo or cutsceneRestart).
|
* (typically via cutsceneSystemGoTo or cutsceneRestart).
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void cutsceneModalOptionsMarkersCallback(
|
|||||||
// the modal directly (uiModalClose) before an option is picked.
|
// the modal directly (uiModalClose) before an option is picked.
|
||||||
const uint8_t index =
|
const uint8_t index =
|
||||||
optionIndex < options->optionCount ? optionIndex : options->optionCount - 1;
|
optionIndex < options->optionCount ? optionIndex : options->optionCount - 1;
|
||||||
cutsceneGoTo(options->markers[index]);
|
cutsceneSystemGoTo(options->markers[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cutsceneModalOptionsMarkersStart(
|
void cutsceneModalOptionsMarkersStart(
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ typedef struct {
|
|||||||
char_t message[CUTSCENE_MODAL_MESSAGE_MAX_CHARS];
|
char_t message[CUTSCENE_MODAL_MESSAGE_MAX_CHARS];
|
||||||
|
|
||||||
// Each option's display text/locale message ID, and the marker to
|
// Each option's display text/locale message ID, and the marker to
|
||||||
// cutsceneGoTo when that option is selected. Copied by value at parse
|
// cutsceneSystemGoTo when that option is selected. Copied by value at parse
|
||||||
// time (see cutsceneModalOptionsMarkersLoad), so they stay valid
|
// time (see cutsceneModalOptionsMarkersLoad), so they stay valid
|
||||||
// regardless of the backing JSON doc's lifetime.
|
// regardless of the backing JSON doc's lifetime.
|
||||||
char_t options[CUTSCENE_MODAL_OPTIONS_MARKERS_MAX][UI_MODAL_OPTION_TEXT_MAX];
|
char_t options[CUTSCENE_MODAL_OPTIONS_MARKERS_MAX][UI_MODAL_OPTION_TEXT_MAX];
|
||||||
@@ -47,7 +47,7 @@ void cutsceneModalOptionsMarkersStart(
|
|||||||
* the cutscene blocks here indefinitely. Back/cancel input is disabled
|
* the cutscene blocks here indefinitely. Back/cancel input is disabled
|
||||||
* while it's open (see uiMenuSetDisableBack), so it must be dismissed
|
* while it's open (see uiMenuSetDisableBack), so it must be dismissed
|
||||||
* by picking an option, which jumps straight to that option's marker
|
* by picking an option, which jumps straight to that option's marker
|
||||||
* via cutsceneGoTo.
|
* via cutsceneSystemGoTo.
|
||||||
*
|
*
|
||||||
* @param item The cutscene item.
|
* @param item The cutscene item.
|
||||||
* @param data Runtime data storage.
|
* @param data Runtime data storage.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void cutsceneTextMiniStart(
|
|||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = index;
|
CUTSCENE_SYSTEM.refs.textMiniLastCreated = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t cutsceneTextMiniUpdate(
|
bool_t cutsceneTextMiniUpdate(
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ errorret_t rpgInit(void) {
|
|||||||
errorChain(itemInit());
|
errorChain(itemInit());
|
||||||
errorChain(battleMoveInit());
|
errorChain(battleMoveInit());
|
||||||
backpackInit();
|
backpackInit();
|
||||||
partyInit();
|
|
||||||
cutsceneSystemInit();
|
cutsceneSystemInit();
|
||||||
errorChain(mapInit());
|
errorChain(mapInit());
|
||||||
rpgCameraInit();
|
rpgCameraInit();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ errorret_t saveInit() {
|
|||||||
|
|
||||||
// Initialize the slots and settings
|
// Initialize the slots and settings
|
||||||
saveSettingsInit(&SAVE.settings);
|
saveSettingsInit(&SAVE.settings);
|
||||||
saveSlotInit();
|
errorChain(saveSlotInit(&SAVE.slot));
|
||||||
|
|
||||||
// Update caches to match default data.
|
// Update caches to match default data.
|
||||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||||
@@ -226,7 +226,7 @@ errorret_t saveLoadSlot() {
|
|||||||
|
|
||||||
if(SAVE.deviceCurrent == 0xFF) {
|
if(SAVE.deviceCurrent == 0xFF) {
|
||||||
// No save device available, so we assume an empty slot.
|
// No save device available, so we assume an empty slot.
|
||||||
saveSlotInit();
|
errorChain(saveSlotInit(&SAVE.slot));
|
||||||
SAVE.caches[SAVE.slotCurrent] = SAVE.slot.cachedData;
|
SAVE.caches[SAVE.slotCurrent] = SAVE.slot.cachedData;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ errorret_t saveLoadSlot() {
|
|||||||
"Save slot %u could not be loaded, treating as empty.\n",
|
"Save slot %u could not be loaded, treating as empty.\n",
|
||||||
(uint32_t)SAVE.slotCurrent
|
(uint32_t)SAVE.slotCurrent
|
||||||
);
|
);
|
||||||
saveSlotInit();
|
errorChain(saveSlotInit(&SAVE.slot));
|
||||||
SAVE.slot.cachedData.corrupt = true;
|
SAVE.slot.cachedData.corrupt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ errorret_t saveLoadSlot() {
|
|||||||
errorret_t saveLoadAllSlots() {
|
errorret_t saveLoadAllSlots() {
|
||||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||||
SAVE.slotCurrent = i;
|
SAVE.slotCurrent = i;
|
||||||
saveSlotInit();
|
errorChain(saveSlotInit(&SAVE.slot));
|
||||||
errorChain(saveLoadSlot());// Load slot updates the cache.
|
errorChain(saveLoadSlot());// Load slot updates the cache.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,33 +12,48 @@
|
|||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
void saveSlotInit(void) {
|
errorret_t saveSlotInit(saveslot_t *slot) {
|
||||||
memorySet(&SAVE.slot, 0, sizeof(saveslot_t));
|
assertNotNull(slot, "Slot cannot be null");
|
||||||
|
|
||||||
SAVE.slot.version = 1;
|
// Zero the save slot.
|
||||||
|
memoryZero(slot, sizeof(saveslot_t));
|
||||||
|
slot->version = 1;
|
||||||
|
|
||||||
|
// Set the default story flags.
|
||||||
for(storyflag_t flag = 0; flag < STORY_FLAG_COUNT; flag++) {
|
for(storyflag_t flag = 0; flag < STORY_FLAG_COUNT; flag++) {
|
||||||
SAVE.slot.storyFlags[flag] = STORY_FLAG_MAP[flag].initial;
|
slot->storyFlags[flag] = STORY_FLAG_MAP[flag].initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
partyInit();
|
// Set the default party.
|
||||||
|
errorChain(partyInit(&slot->party));
|
||||||
|
|
||||||
|
// Set the default current cutscene.
|
||||||
|
stringCopy(
|
||||||
|
slot->currentCutscene, SAVE_SLOT_CUTSCENE_DEFAULT,
|
||||||
|
sizeof(slot->currentCutscene) - 1
|
||||||
|
);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSlotNewGame(void) {
|
errorret_t saveSlotNewGame(void) {
|
||||||
saveSlotInit();
|
errorChain(saveSlotInit(&SAVE.slot));
|
||||||
|
|
||||||
stringCopy(
|
stringCopy(
|
||||||
SAVE.slot.cachedData.mapName, SAVE_SLOT_MAP_NAME_DEFAULT,
|
SAVE.slot.cachedData.mapName, SAVE_SLOT_MAP_NAME_DEFAULT,
|
||||||
sizeof(SAVE.slot.cachedData.mapName)
|
sizeof(SAVE.slot.cachedData.mapName)
|
||||||
);
|
);
|
||||||
|
|
||||||
// TEMPORARY: placeholder starting party stats - replace once there's a
|
errorOk();
|
||||||
// real starting-party/character-creation flow.
|
}
|
||||||
const battlefighterstats_t startingStats = {
|
|
||||||
.attack = 10, .defense = 5, .magic = 0, .speed = 10, .luck = 0,
|
void saveSlotSetCurrentCutscene(const char_t *file) {
|
||||||
.healthMax = 30, .mpMax = 10
|
assertNotNull(file, "File cannot be null");
|
||||||
};
|
|
||||||
partyAddMember(startingStats);
|
stringCopy(
|
||||||
|
SAVE.slot.currentCutscene, file, sizeof(SAVE.slot.currentCutscene) - 1
|
||||||
|
);
|
||||||
|
SAVE.slotDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t saveSlotInUse(saveslotcache_t *slot) {
|
bool_t saveSlotInUse(saveslotcache_t *slot) {
|
||||||
@@ -64,14 +79,13 @@ errorret_t saveSlotReadJSON(saveslot_t *slot, yyjson_val *object) {
|
|||||||
assertNotNull(slot, "Slot cannot be null");
|
assertNotNull(slot, "Slot cannot be null");
|
||||||
assertNotNull(object, "Object cannot be null");
|
assertNotNull(object, "Object cannot be null");
|
||||||
|
|
||||||
// A plain reset, not saveSlotInit() - this may be reading into a slot
|
// saveSlotInit() now takes slot directly, so this can reset through it
|
||||||
// other than SAVE.slot (e.g. a save-device round trip in a test), and
|
// rather than duplicating the memSet/version stub - saveSlotCurrent
|
||||||
// saveSlotInit() only ever operates on SAVE.slot now. saveSlotCurrent
|
// ReadJSON() fully overwrites every field it sets anyway (including
|
||||||
// ReadJSON() fully overwrites every field below anyway (including
|
// party.members/order), so seeding a fresh party.jsonc roster here only
|
||||||
// party.members/order), so this only needs to reset the bookkeeping
|
// to replace it is wasted work, but keeps this in one reset path rather
|
||||||
// fields (version/dataType) that aren't part of the JSON wire format.
|
// than two subtly different ones.
|
||||||
memorySet(slot, 0, sizeof(saveslot_t));
|
errorChain(saveSlotInit(slot));
|
||||||
slot->version = 1;
|
|
||||||
|
|
||||||
errorChain(saveSlotCurrentReadJSON(slot, object));
|
errorChain(saveSlotCurrentReadJSON(slot, object));
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "rpg/battle/party.h"
|
#include "rpg/battle/party.h"
|
||||||
#include "rpg/story/story.h"
|
#include "rpg/story/story.h"
|
||||||
#include "time/timeepoch.h"
|
#include "time/timeepoch.h"
|
||||||
|
#include "asset/assetfile.h"
|
||||||
#include "yyjson.h"
|
#include "yyjson.h"
|
||||||
|
|
||||||
#define SAVE_SLOT_NAME_LENGTH 8
|
#define SAVE_SLOT_NAME_LENGTH 8
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SAVE_SLOT_MAP_NAME_DEFAULT "overworld"
|
#define SAVE_SLOT_MAP_NAME_DEFAULT "overworld"
|
||||||
|
#define SAVE_SLOT_CUTSCENE_NAME_MAX ASSET_FILE_NAME_MAX
|
||||||
|
#define SAVE_SLOT_CUTSCENE_DEFAULT "cutscenes/new_game.jsonc"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char_t name[SAVE_SLOT_NAME_LENGTH + 1];// 8 characters + null terminator
|
char_t name[SAVE_SLOT_NAME_LENGTH + 1];// 8 characters + null terminator
|
||||||
@@ -34,25 +37,44 @@ typedef struct saveslot_s {
|
|||||||
saveslotcache_t cachedData;
|
saveslotcache_t cachedData;
|
||||||
party_t party;
|
party_t party;
|
||||||
storyflagval_t storyFlags[STORY_FLAG_COUNT_MAX];
|
storyflagval_t storyFlags[STORY_FLAG_COUNT_MAX];
|
||||||
|
// Asset path of the cutscene currently in progress for this slot (e.g.
|
||||||
|
// resumed on load) - defaults to SAVE_SLOT_CUTSCENE_DEFAULT on a fresh
|
||||||
|
// slot (see saveSlotInit).
|
||||||
|
char_t currentCutscene[SAVE_SLOT_CUTSCENE_NAME_MAX];
|
||||||
} saveslot_t;
|
} saveslot_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits the current save slot (SAVE.slot) with the default state, this is
|
* Inits slot with the default state, this is functionally "new game" but
|
||||||
* functionally "new game" but will not set the player name, as that is
|
* will not set the player name, as that is what we use to determine if a
|
||||||
* what we use to determine if a save slot is "in use" or not.
|
* save slot is "in use" or not. Seeds the party roster from party.jsonc
|
||||||
|
* (see partyInit).
|
||||||
|
*
|
||||||
|
* @param slot The save slot to initialize.
|
||||||
|
* @return Error if the starting party roster (party.jsonc) fails to
|
||||||
|
* load/parse.
|
||||||
*/
|
*/
|
||||||
void saveSlotInit(void);
|
errorret_t saveSlotInit(saveslot_t *slot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the current save slot (SAVE.slot) for a brand new game: calls
|
* Sets up the current save slot (SAVE.slot) for a brand new game: calls
|
||||||
* saveSlotInit, then seeds it with a starting party. Use this (not
|
* saveSlotInit (which seeds the starting party roster) and sets the
|
||||||
* saveSlotInit) whenever a new save is actually being created for a
|
* default starting map. Use this (not saveSlotInit directly) whenever a
|
||||||
* player - saveSlotInit alone leaves the party empty, which every other
|
* new save is actually being created for a player. Callers creating a
|
||||||
* caller (resetting the slot before a load attempt, wiping a deleted
|
* new save at a specific index should set SAVE.slotCurrent first.
|
||||||
* slot) wants. Callers creating a new save at a specific index should set
|
*
|
||||||
* SAVE.slotCurrent first.
|
* @return Error if saveSlotInit fails.
|
||||||
*/
|
*/
|
||||||
void saveSlotNewGame(void);
|
errorret_t saveSlotNewGame(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current save slot's (SAVE.slot) in-progress cutscene and
|
||||||
|
* dirties the save (SAVE.slotDirty), same as storySetFlagValue - so the
|
||||||
|
* next save write persists it. Use this (not writing SAVE.slot.
|
||||||
|
* currentCutscene directly) anywhere gameplay needs to change it.
|
||||||
|
*
|
||||||
|
* @param file Asset path of the cutscene now in progress, or "" for none.
|
||||||
|
*/
|
||||||
|
void saveSlotSetCurrentCutscene(const char_t *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the save slot is in use, this is determined by checking if the
|
* Checks if the save slot is in use, this is determined by checking if the
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ errorret_t saveSlotCurrentWriteJSON(
|
|||||||
|
|
||||||
memoryCopy(ver1.storyFlags, slot->storyFlags, sizeof(ver1.storyFlags));
|
memoryCopy(ver1.storyFlags, slot->storyFlags, sizeof(ver1.storyFlags));
|
||||||
|
|
||||||
|
stringCopy(
|
||||||
|
ver1.currentCutscene, slot->currentCutscene, sizeof(ver1.currentCutscene)
|
||||||
|
);
|
||||||
|
|
||||||
errorChain(saveSlotVer1WriteJSON(&ver1, doc, object));
|
errorChain(saveSlotVer1WriteJSON(&ver1, doc, object));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -66,5 +70,10 @@ errorret_t saveSlotCurrentReadJSON(saveslot_t *slot, yyjson_val *object) {
|
|||||||
|
|
||||||
memoryCopy(slot->storyFlags, ver1.storyFlags, sizeof(slot->storyFlags));
|
memoryCopy(slot->storyFlags, ver1.storyFlags, sizeof(slot->storyFlags));
|
||||||
|
|
||||||
|
stringCopy(
|
||||||
|
slot->currentCutscene, ver1.currentCutscene,
|
||||||
|
sizeof(slot->currentCutscene)
|
||||||
|
);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -26,21 +26,9 @@ errorret_t saveSlotVer1WriteJSON(
|
|||||||
|
|
||||||
yyjson_mut_val *partyMembersArr = yyjson_mut_arr(doc);
|
yyjson_mut_val *partyMembersArr = yyjson_mut_arr(doc);
|
||||||
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
||||||
battlefighter_t *member = &slot->partyMembers[i];
|
yyjson_mut_val *memberObj =
|
||||||
writeArrayObject(partyMembersArr);
|
battleFighterSerialize(&slot->partyMembers[i], doc);
|
||||||
writeUInt32("id", member->id);
|
yyjson_mut_arr_add_val(partyMembersArr, memberObj);
|
||||||
writeUInt32("status", member->status);
|
|
||||||
writeUInt32("team", member->team);
|
|
||||||
writeUInt32("controller", member->controller);
|
|
||||||
writeUInt32("health", member->stats.health);
|
|
||||||
writeUInt32("healthMax", member->stats.healthMax);
|
|
||||||
writeUInt32("mp", member->stats.mp);
|
|
||||||
writeUInt32("mpMax", member->stats.mpMax);
|
|
||||||
writeUInt32("statAttack", member->stats.attack);
|
|
||||||
writeUInt32("statDefense", member->stats.defense);
|
|
||||||
writeUInt32("statMagic", member->stats.magic);
|
|
||||||
writeUInt32("statSpeed", member->stats.speed);
|
|
||||||
writeUInt32("statLuck", member->stats.luck);
|
|
||||||
}
|
}
|
||||||
writeValue("partyMembers", partyMembersArr);
|
writeValue("partyMembers", partyMembersArr);
|
||||||
|
|
||||||
@@ -53,6 +41,8 @@ errorret_t saveSlotVer1WriteJSON(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeString("currentCutscene", slot->currentCutscene);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,24 +74,8 @@ errorret_t saveSlotVer1ReadJSON(saveslotver1_t *slot, yyjson_val *object) {
|
|||||||
partyMembersArr, memberIdx, memberLen, memberObj
|
partyMembersArr, memberIdx, memberLen, memberObj
|
||||||
) {
|
) {
|
||||||
battlefighter_t *member = &slot->partyMembers[memberIdx];
|
battlefighter_t *member = &slot->partyMembers[memberIdx];
|
||||||
// Shadows the outer `object` so readUInt32() below (which hardcodes
|
member->id = (uint8_t)memberIdx;
|
||||||
// that name) reads from this member's object instead.
|
errorChain(battleFighterParse(member, memberObj));
|
||||||
yyjson_val *object = memberObj;
|
|
||||||
readUInt32("id", member->id, 0);
|
|
||||||
readUInt32("status", member->status, BATTLE_FIGHTER_STATUS_NULL);
|
|
||||||
readUInt32("team", member->team, BATTLE_FIGHTER_TEAM_ALLY);
|
|
||||||
readUInt32(
|
|
||||||
"controller", member->controller, BATTLE_FIGHTER_CONTROLLER_PLAYER
|
|
||||||
);
|
|
||||||
readUInt32("health", member->stats.health, 0);
|
|
||||||
readUInt32("healthMax", member->stats.healthMax, 0);
|
|
||||||
readUInt32("mp", member->stats.mp, 0);
|
|
||||||
readUInt32("mpMax", member->stats.mpMax, 0);
|
|
||||||
readUInt32("statAttack", member->stats.attack, 0);
|
|
||||||
readUInt32("statDefense", member->stats.defense, 0);
|
|
||||||
readUInt32("statMagic", member->stats.magic, 0);
|
|
||||||
readUInt32("statSpeed", member->stats.speed, 0);
|
|
||||||
readUInt32("statLuck", member->stats.luck, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readUInt8Array(
|
readUInt8Array(
|
||||||
@@ -122,5 +96,10 @@ errorret_t saveSlotVer1ReadJSON(saveslotver1_t *slot, yyjson_val *object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readString(
|
||||||
|
"currentCutscene", slot->currentCutscene, SAVE_SLOT_VER1_CUTSCENE_DEFAULT,
|
||||||
|
SAVE_SLOT_VER1_CUTSCENE_NAME_MAX - 1
|
||||||
|
);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -24,8 +24,22 @@
|
|||||||
// keyed by flag name (not position), so its on-disk shape is decoupled from
|
// keyed by flag name (not position), so its on-disk shape is decoupled from
|
||||||
// STORY_FLAG_COUNT_MAX entirely; a save simply loses whatever flags no
|
// STORY_FLAG_COUNT_MAX entirely; a save simply loses whatever flags no
|
||||||
// longer resolve by name (see storyGetFlagByName) if that cap ever shrinks.
|
// longer resolve by name (see storyGetFlagByName) if that cap ever shrinks.
|
||||||
|
//
|
||||||
|
// partyMembers is a THIRD exception, deliberately broken pre-release: its
|
||||||
|
// per-member shape now comes from battleFighterSerialize/battleFighterParse
|
||||||
|
// (rpg/battle/fighter/battlefighter.h) - the shared fighter JSON format
|
||||||
|
// used everywhere else (party.jsonc, BATTLE_START enemies) - instead of its
|
||||||
|
// own hand-rolled field set. This is a real on-disk break (different key
|
||||||
|
// names, no more "statAttack" etc.) with no migration - an old v1 save
|
||||||
|
// simply reads back as corrupt. Acceptable only because nothing has
|
||||||
|
// shipped yet; don't repeat this once real saves exist without a version
|
||||||
|
// bump instead.
|
||||||
#define SAVE_SLOT_VER1_NAME_LENGTH 8
|
#define SAVE_SLOT_VER1_NAME_LENGTH 8
|
||||||
#define SAVE_SLOT_VER1_MAP_NAME_MAX 10
|
#define SAVE_SLOT_VER1_MAP_NAME_MAX 10
|
||||||
|
#define SAVE_SLOT_VER1_CUTSCENE_NAME_MAX 128
|
||||||
|
// Own frozen copy of save/slot/saveslot.h's SAVE_SLOT_CUTSCENE_DEFAULT, for
|
||||||
|
// the same reason as the sizes above - never reference the live constant.
|
||||||
|
#define SAVE_SLOT_VER1_CUTSCENE_DEFAULT "cutscenes/new_game.jsonc"
|
||||||
|
|
||||||
// Independent from saveslotcache_t (save/slot/saveslot.h) by design - this
|
// Independent from saveslotcache_t (save/slot/saveslot.h) by design - this
|
||||||
// is what version 1 actually put on disk, frozen forever. saveSlotCurrent
|
// is what version 1 actually put on disk, frozen forever. saveSlotCurrent
|
||||||
@@ -42,6 +56,8 @@ typedef struct saveslotver1_s {
|
|||||||
uint8_t partyOrder[PARTY_ACTIVE_SIZE_MAX];
|
uint8_t partyOrder[PARTY_ACTIVE_SIZE_MAX];
|
||||||
|
|
||||||
storyflagval_t storyFlags[STORY_FLAG_COUNT_MAX];
|
storyflagval_t storyFlags[STORY_FLAG_COUNT_MAX];
|
||||||
|
|
||||||
|
char_t currentCutscene[SAVE_SLOT_VER1_CUTSCENE_NAME_MAX];
|
||||||
} saveslotver1_t;
|
} saveslotver1_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -107,7 +107,12 @@ void uiSelectSaveDeleteConfirmed(const bool_t result, void *user) {
|
|||||||
// uimainmenu.c), so it's safe to reuse SAVE.slot as scratch for whichever
|
// uimainmenu.c), so it's safe to reuse SAVE.slot as scratch for whichever
|
||||||
// index is being written here - nothing else is relying on it.
|
// index is being written here - nothing else is relying on it.
|
||||||
SAVE.slotCurrent = index;
|
SAVE.slotCurrent = index;
|
||||||
saveSlotInit();
|
errorret_t initResult = saveSlotInit(&SAVE.slot);
|
||||||
|
if(errorIsNotOk(initResult)) {
|
||||||
|
errorCatch(errorPrint(initResult));
|
||||||
|
uiFatalErrorOpen(initResult.state->message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
errorret_t writeResult = saveDeviceSlotWrite(
|
errorret_t writeResult = saveDeviceSlotWrite(
|
||||||
&SAVE.devices[SAVE.deviceCurrent], &SAVE.slot, index
|
&SAVE.devices[SAVE.deviceCurrent], &SAVE.slot, index
|
||||||
@@ -144,7 +149,12 @@ void uiSelectSaveNameEntered(
|
|||||||
// uimainmenu.c), so it's safe to reuse SAVE.slot as scratch for whichever
|
// uimainmenu.c), so it's safe to reuse SAVE.slot as scratch for whichever
|
||||||
// index is being written here - nothing else is relying on it.
|
// index is being written here - nothing else is relying on it.
|
||||||
SAVE.slotCurrent = index;
|
SAVE.slotCurrent = index;
|
||||||
saveSlotNewGame();
|
errorret_t newGameResult = saveSlotNewGame();
|
||||||
|
if(errorIsNotOk(newGameResult)) {
|
||||||
|
errorCatch(errorPrint(newGameResult));
|
||||||
|
uiFatalErrorOpen(newGameResult.state->message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
stringCopy(SAVE.slot.cachedData.name, text, SAVE_SLOT_NAME_LENGTH);
|
stringCopy(SAVE.slot.cachedData.name, text, SAVE_SLOT_NAME_LENGTH);
|
||||||
|
|
||||||
// No save device available - proceed with an in-memory-only slot rather
|
// No save device available - proceed with an in-memory-only slot rather
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "uibattlehud.h"
|
#include "uibattlehud.h"
|
||||||
#include "rpg/battle/battle.h"
|
#include "rpg/battle/battle.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
#include "scene/battle/scenebattle.h"
|
#include "scene/battle/scenebattle.h"
|
||||||
#include "scene/scene.h"
|
#include "scene/scene.h"
|
||||||
#include "display/text/text.h"
|
#include "display/text/text.h"
|
||||||
@@ -58,22 +59,28 @@ errorret_t uiBattleHudDraw(void) {
|
|||||||
vec2 screenPos;
|
vec2 screenPos;
|
||||||
sceneBattleWorldToScreen(battle, position, screenPos);
|
sceneBattleWorldToScreen(battle, position, screenPos);
|
||||||
|
|
||||||
|
float_t lineY = screenPos[1];
|
||||||
|
if(fighter->team == BATTLE_FIGHTER_TEAM_ALLY) {
|
||||||
|
errorChain(textDraw(
|
||||||
|
screenPos[0], lineY, partyGetMemberKey(fighter->id), COLOR_WHITE, NULL
|
||||||
|
));
|
||||||
|
lineY += UI_BATTLE_HUD_LINE_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
char_t hpText[UI_BATTLE_HUD_TEXT_MAX];
|
char_t hpText[UI_BATTLE_HUD_TEXT_MAX];
|
||||||
stringFormat(
|
stringFormat(
|
||||||
hpText, UI_BATTLE_HUD_TEXT_MAX - 1, UI_BATTLE_HUD.hpFormat,
|
hpText, UI_BATTLE_HUD_TEXT_MAX - 1, UI_BATTLE_HUD.hpFormat,
|
||||||
fighter->stats.health, fighter->stats.healthMax
|
fighter->stats.health, fighter->stats.healthMax
|
||||||
);
|
);
|
||||||
errorChain(textDraw(screenPos[0], screenPos[1], hpText, COLOR_WHITE, NULL));
|
errorChain(textDraw(screenPos[0], lineY, hpText, COLOR_WHITE, NULL));
|
||||||
|
lineY += UI_BATTLE_HUD_LINE_HEIGHT;
|
||||||
|
|
||||||
char_t mpText[UI_BATTLE_HUD_TEXT_MAX];
|
char_t mpText[UI_BATTLE_HUD_TEXT_MAX];
|
||||||
stringFormat(
|
stringFormat(
|
||||||
mpText, UI_BATTLE_HUD_TEXT_MAX - 1, UI_BATTLE_HUD.mpFormat,
|
mpText, UI_BATTLE_HUD_TEXT_MAX - 1, UI_BATTLE_HUD.mpFormat,
|
||||||
fighter->stats.mp, fighter->stats.mpMax
|
fighter->stats.mp, fighter->stats.mpMax
|
||||||
);
|
);
|
||||||
errorChain(textDraw(
|
errorChain(textDraw(screenPos[0], lineY, mpText, COLOR_CYAN, NULL));
|
||||||
screenPos[0], screenPos[1] + UI_BATTLE_HUD_LINE_HEIGHT,
|
|
||||||
mpText, COLOR_CYAN, NULL
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorChain(spriteBatchFlush());
|
errorChain(spriteBatchFlush());
|
||||||
|
|||||||
@@ -12,8 +12,11 @@
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
#include "display/screen/screen.h"
|
#include "display/screen/screen.h"
|
||||||
|
#include "display/text/text.h"
|
||||||
|
#include "display/color.h"
|
||||||
#include "locale/localemanager.h"
|
#include "locale/localemanager.h"
|
||||||
#include "asset/loader/locale/assetlocaleloader.h"
|
#include "asset/loader/locale/assetlocaleloader.h"
|
||||||
|
#include "rpg/battle/party.h"
|
||||||
|
|
||||||
uibattlemenu_t UI_BATTLE_MENU;
|
uibattlemenu_t UI_BATTLE_MENU;
|
||||||
|
|
||||||
@@ -62,6 +65,11 @@ void uiBattleMenuOpenTargets(void) {
|
|||||||
uiMenuOpen(&UI_BATTLE_MENU.targetMenu);
|
uiMenuOpen(&UI_BATTLE_MENU.targetMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool_t uiBattleMenuActionCancel(const uimenu_t *menu) {
|
||||||
|
battleStateSelectionGoBack();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void uiBattleMenuActionSelected(
|
void uiBattleMenuActionSelected(
|
||||||
const uimenu_t *menu,
|
const uimenu_t *menu,
|
||||||
const uint8_t index,
|
const uint8_t index,
|
||||||
@@ -112,6 +120,8 @@ errorret_t uiBattleMenuInit(void) {
|
|||||||
MENU_BUTTON(UI_BATTLE_MENU.fleeLabel);
|
MENU_BUTTON(UI_BATTLE_MENU.fleeLabel);
|
||||||
MENU_END(UI_BATTLE_MENU.actionItems, 1);
|
MENU_END(UI_BATTLE_MENU.actionItems, 1);
|
||||||
|
|
||||||
|
uiMenuSetCancelCallback(&UI_BATTLE_MENU.actionMenu, uiBattleMenuActionCancel);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +144,14 @@ errorret_t uiBattleMenuDraw(void) {
|
|||||||
const float_t x = (float_t)(SCREEN.scanX + SCREEN.scanWidth) - width;
|
const float_t x = (float_t)(SCREEN.scanX + SCREEN.scanWidth) - width;
|
||||||
const float_t y = (float_t)(SCREEN.scanY + SCREEN.scanHeight) - height;
|
const float_t y = (float_t)(SCREEN.scanY + SCREEN.scanHeight) - height;
|
||||||
|
|
||||||
|
battlefighter_t *current = battleStateSelectionGetCurrentFighter();
|
||||||
|
if(current != NULL) {
|
||||||
|
errorChain(textDraw(
|
||||||
|
x, y - UI_BATTLE_MENU_NAME_LINE_HEIGHT,
|
||||||
|
partyGetMemberKey(current->id), COLOR_WHITE, NULL
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
errorChain(uiFrameDraw(x, y, width, height));
|
errorChain(uiFrameDraw(x, y, width, height));
|
||||||
errorChain(uiMenuDraw(
|
errorChain(uiMenuDraw(
|
||||||
&UI_BATTLE_MENU.actionMenu,
|
&UI_BATTLE_MENU.actionMenu,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#define UI_BATTLE_MENU_WIDTH 160.0f
|
#define UI_BATTLE_MENU_WIDTH 160.0f
|
||||||
#define UI_BATTLE_MENU_HEIGHT 96.0f
|
#define UI_BATTLE_MENU_HEIGHT 96.0f
|
||||||
|
#define UI_BATTLE_MENU_NAME_LINE_HEIGHT 12.0f
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uimenu_t actionMenu;
|
uimenu_t actionMenu;
|
||||||
|
|||||||
@@ -38,7 +38,13 @@ void uiMainMenuSelectSaveResult(const uint8_t slotIndex, void *user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SAVE.slotCurrent = slotIndex;
|
SAVE.slotCurrent = slotIndex;
|
||||||
saveSlotInit();
|
errorret_t initResult = saveSlotInit(&SAVE.slot);
|
||||||
|
if(errorIsNotOk(initResult)) {
|
||||||
|
errorCatch(errorPrint(initResult));
|
||||||
|
uiFatalErrorOpen(initResult.state->message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
errorret_t result = saveLoadSlot();
|
errorret_t result = saveLoadSlot();
|
||||||
if(errorIsNotOk(result)) {
|
if(errorIsNotOk(result)) {
|
||||||
errorCatch(errorPrint(result));
|
errorCatch(errorPrint(result));
|
||||||
@@ -57,6 +63,10 @@ void uiMainMenuSelectSaveResult(const uint8_t slotIndex, void *user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sceneSet(SCENE_TYPE_OVERWORLD);
|
sceneSet(SCENE_TYPE_OVERWORLD);
|
||||||
|
|
||||||
|
if(SAVE.slot.currentCutscene[0] != '\0') {
|
||||||
|
cutsceneSystemLoad(SAVE.slot.currentCutscene);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiMainMenuOpenSelectSave(void *userData) {
|
void uiMainMenuOpenSelectSave(void *userData) {
|
||||||
@@ -71,7 +81,7 @@ void uiMainMenuStartGame(void) {
|
|||||||
if(cutscene == NULL) return;
|
if(cutscene == NULL) return;
|
||||||
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "NEW_GAME");
|
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "NEW_GAME");
|
||||||
} else {
|
} else {
|
||||||
cutsceneGoTo("NEW_GAME");
|
cutsceneSystemGoTo("NEW_GAME");
|
||||||
}
|
}
|
||||||
|
|
||||||
cutsceneSystemSetOnComplete(uiMainMenuOpenSelectSave);
|
cutsceneSystemSetOnComplete(uiMainMenuOpenSelectSave);
|
||||||
@@ -83,7 +93,7 @@ void uiMainMenuOptions(void) {
|
|||||||
if(cutscene == NULL) return;
|
if(cutscene == NULL) return;
|
||||||
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "OPTIONS");
|
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "OPTIONS");
|
||||||
} else {
|
} else {
|
||||||
cutsceneGoTo("OPTIONS");
|
cutsceneSystemGoTo("OPTIONS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +103,7 @@ void uiMainMenuQuit(void) {
|
|||||||
if(cutscene == NULL) return;
|
if(cutscene == NULL) return;
|
||||||
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "QUIT");
|
cutsceneSystemStartCutsceneAndGoToMarker(cutscene, "QUIT");
|
||||||
} else {
|
} else {
|
||||||
cutsceneGoTo("QUIT");
|
cutsceneSystemGoTo("QUIT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ static void test_cutsceneMapAreaRemoveResolvesLastCreatedSentinel(
|
|||||||
|
|
||||||
cutsceneitem_t removeItem = {
|
cutsceneitem_t removeItem = {
|
||||||
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
|
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
|
||||||
.mapAreaRemove = { .areaId = CUTSCENE_AREA_LAST_CREATED }
|
.mapAreaRemove = { .areaId = CUTSCENE_REF_AREA_LAST_CREATED }
|
||||||
};
|
};
|
||||||
cutsceneMapAreaRemoveStart(&removeItem, &data);
|
cutsceneMapAreaRemoveStart(&removeItem, &data);
|
||||||
assert_null(MAP_AREAS[id].callback);
|
assert_null(MAP_AREAS[id].callback);
|
||||||
@@ -150,7 +150,7 @@ static void test_cutsceneMapAreaWaitResolvesLastCreatedSentinel(
|
|||||||
|
|
||||||
cutsceneitem_t waitItem = {
|
cutsceneitem_t waitItem = {
|
||||||
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
|
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
|
||||||
.mapAreaWait = { .areaIds = { CUTSCENE_AREA_LAST_CREATED }, .count = 1 }
|
.mapAreaWait = { .areaIds = { CUTSCENE_REF_AREA_LAST_CREATED }, .count = 1 }
|
||||||
};
|
};
|
||||||
cutsceneMapAreaWaitStart(&waitItem, &data);
|
cutsceneMapAreaWaitStart(&waitItem, &data);
|
||||||
assert_false(cutsceneMapAreaWaitUpdate(&waitItem, &data));
|
assert_false(cutsceneMapAreaWaitUpdate(&waitItem, &data));
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ static void test_cutsceneSystemStartWithSetsInteractEntities(void **state) {
|
|||||||
&CUTSCENE_TEST_SINGLE_WAIT, &ENTITIES[0], &ENTITIES[1]
|
&CUTSCENE_TEST_SINGLE_WAIT, &ENTITIES[0], &ENTITIES[1]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ptr_equal(CUTSCENE_SYSTEM.entityInteract, &ENTITIES[0]);
|
assert_ptr_equal(CUTSCENE_SYSTEM.refs.entityInteract, &ENTITIES[0]);
|
||||||
assert_ptr_equal(CUTSCENE_SYSTEM.entityInteracted, &ENTITIES[1]);
|
assert_ptr_equal(CUTSCENE_SYSTEM.refs.entityInteracted, &ENTITIES[1]);
|
||||||
assert_ptr_equal(
|
assert_ptr_equal(
|
||||||
cutsceneSystemGetEntity(CUTSCENE_ENTITY_INTERACT), &ENTITIES[0]
|
cutsceneSystemGetEntity(CUTSCENE_ENTITY_INTERACT), &ENTITIES[0]
|
||||||
);
|
);
|
||||||
@@ -122,8 +122,8 @@ static void test_cutsceneSystemStartWithSetsInteractEntities(void **state) {
|
|||||||
|
|
||||||
TIME.delta = 2.0f;
|
TIME.delta = 2.0f;
|
||||||
cutsceneSystemUpdate();// ends the cutscene
|
cutsceneSystemUpdate();// ends the cutscene
|
||||||
assert_null(CUTSCENE_SYSTEM.entityInteract);// reset on end
|
assert_null(CUTSCENE_SYSTEM.refs.entityInteract);// reset on end
|
||||||
assert_null(CUTSCENE_SYSTEM.entityInteracted);
|
assert_null(CUTSCENE_SYSTEM.refs.entityInteracted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_cutsceneSystemGetEntitySentinelsRequireBeingSet(
|
static void test_cutsceneSystemGetEntitySentinelsRequireBeingSet(
|
||||||
@@ -158,28 +158,28 @@ static void test_cutsceneSystemGetAreaId(void **state) {
|
|||||||
cutsceneSystemInit();
|
cutsceneSystemInit();
|
||||||
// cutsceneSystemInit() zero-inits the field -- only actually starting a
|
// cutsceneSystemInit() zero-inits the field -- only actually starting a
|
||||||
// cutscene sets it to the "nothing created yet" sentinel.
|
// cutscene sets it to the "nothing created yet" sentinel.
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
CUTSCENE_SYSTEM.refs.areaLastCreated = CUTSCENE_REF_AREA_LAST_CREATED;
|
||||||
|
|
||||||
expect_assert_failure(cutsceneSystemGetAreaId(CUTSCENE_AREA_LAST_CREATED));
|
expect_assert_failure(cutsceneSystemGetAreaId(CUTSCENE_REF_AREA_LAST_CREATED));
|
||||||
assert_int_equal(cutsceneSystemGetAreaId(5), 5);// direct IDs pass through
|
assert_int_equal(cutsceneSystemGetAreaId(5), 5);// direct IDs pass through
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.areaLastCreated = 3;
|
CUTSCENE_SYSTEM.refs.areaLastCreated = 3;
|
||||||
assert_int_equal(cutsceneSystemGetAreaId(CUTSCENE_AREA_LAST_CREATED), 3);
|
assert_int_equal(cutsceneSystemGetAreaId(CUTSCENE_REF_AREA_LAST_CREATED), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_cutsceneSystemGetTextMiniId(void **state) {
|
static void test_cutsceneSystemGetTextMiniId(void **state) {
|
||||||
|
|
||||||
cutsceneSystemInit();
|
cutsceneSystemInit();
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
CUTSCENE_SYSTEM.refs.textMiniLastCreated = CUTSCENE_REF_TEXT_MINI_LAST_CREATED;
|
||||||
|
|
||||||
expect_assert_failure(
|
expect_assert_failure(
|
||||||
cutsceneSystemGetTextMiniId(CUTSCENE_TEXT_MINI_LAST_CREATED)
|
cutsceneSystemGetTextMiniId(CUTSCENE_REF_TEXT_MINI_LAST_CREATED)
|
||||||
);
|
);
|
||||||
assert_int_equal(cutsceneSystemGetTextMiniId(4), 4);
|
assert_int_equal(cutsceneSystemGetTextMiniId(4), 4);
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.textMiniLastCreated = 1;
|
CUTSCENE_SYSTEM.refs.textMiniLastCreated = 1;
|
||||||
assert_int_equal(
|
assert_int_equal(
|
||||||
cutsceneSystemGetTextMiniId(CUTSCENE_TEXT_MINI_LAST_CREATED), 1
|
cutsceneSystemGetTextMiniId(CUTSCENE_REF_TEXT_MINI_LAST_CREATED), 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,15 +195,15 @@ static void test_cutsceneSystemDisposeResetsState(void **state) {
|
|||||||
assert_null(CUTSCENE_SYSTEM.scene);
|
assert_null(CUTSCENE_SYSTEM.scene);
|
||||||
assert_int_equal(CUTSCENE_SYSTEM.currentItem, 0xFF);
|
assert_int_equal(CUTSCENE_SYSTEM.currentItem, 0xFF);
|
||||||
assert_int_equal(CUTSCENE_SYSTEM.pause, CUTSCENE_PAUSE_NONE);
|
assert_int_equal(CUTSCENE_SYSTEM.pause, CUTSCENE_PAUSE_NONE);
|
||||||
assert_null(CUTSCENE_SYSTEM.entityInteract);
|
assert_null(CUTSCENE_SYSTEM.refs.entityInteract);
|
||||||
assert_null(CUTSCENE_SYSTEM.entityInteracted);
|
assert_null(CUTSCENE_SYSTEM.refs.entityInteracted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- loadedFile survival across cutsceneSystemPrepare -------------------
|
// --- loadedFile survival across cutsceneSystemPrepare -------------------
|
||||||
//
|
//
|
||||||
// cutsceneCutsceneResolve (and cutsceneSystemLoad) stamp
|
// cutsceneCutsceneResolve (and cutsceneSystemLoad) stamp
|
||||||
// CUTSCENE_SYSTEM.loadedFile with what they just parsed loadedScene from
|
// CUTSCENE_SYSTEM.loadedFile with what they just parsed loadedScene from
|
||||||
// - cutsceneGoTo needs that to survive so it can reload the same source
|
// - cutsceneSystemGoTo needs that to survive so it can reload the same source
|
||||||
// later. cutsceneCutsceneResolve's caller stamps it BEFORE calling
|
// later. cutsceneCutsceneResolve's caller stamps it BEFORE calling
|
||||||
// cutsceneSystemStartCutscene(&CUTSCENE_SYSTEM.loadedScene), so
|
// cutsceneSystemStartCutscene(&CUTSCENE_SYSTEM.loadedScene), so
|
||||||
// cutsceneSystemPrepare must not blindly clear loadedFile on every
|
// cutsceneSystemPrepare must not blindly clear loadedFile on every
|
||||||
@@ -212,7 +212,7 @@ static void test_cutsceneSystemDisposeResetsState(void **state) {
|
|||||||
// regression-tests the exact bug hit via initial.jsonc's CUTSCENE item
|
// regression-tests the exact bug hit via initial.jsonc's CUTSCENE item
|
||||||
// into main_menu.jsonc: cutsceneCutsceneResolve stamped loadedFile, then
|
// into main_menu.jsonc: cutsceneCutsceneResolve stamped loadedFile, then
|
||||||
// the immediately following cutsceneSystemStartCutscene call wiped it
|
// the immediately following cutsceneSystemStartCutscene call wiped it
|
||||||
// straight back out, so a later cutsceneGoTo on the still-running
|
// straight back out, so a later cutsceneSystemGoTo on the still-running
|
||||||
// cutscene had nothing to reload from.
|
// cutscene had nothing to reload from.
|
||||||
static void test_cutsceneSystemPrepareKeepsLoadedFileWhenReenteringLoadedScene(
|
static void test_cutsceneSystemPrepareKeepsLoadedFileWhenReenteringLoadedScene(
|
||||||
void **state
|
void **state
|
||||||
@@ -551,8 +551,8 @@ static void test_cutsceneInsertDoesNotResetPauseOrInteractEntities(
|
|||||||
// been popped off the front, only the snippet's one item is left.
|
// been popped off the front, only the snippet's one item is left.
|
||||||
assert_ptr_equal(CUTSCENE_SYSTEM.scene, &CUTSCENE_TEST_INSERT_PERSIST_OUTER);
|
assert_ptr_equal(CUTSCENE_SYSTEM.scene, &CUTSCENE_TEST_INSERT_PERSIST_OUTER);
|
||||||
assert_int_equal(CUTSCENE_SYSTEM.scene->itemCount, 1);
|
assert_int_equal(CUTSCENE_SYSTEM.scene->itemCount, 1);
|
||||||
assert_ptr_equal(CUTSCENE_SYSTEM.entityInteract, &ENTITIES[3]);
|
assert_ptr_equal(CUTSCENE_SYSTEM.refs.entityInteract, &ENTITIES[3]);
|
||||||
assert_ptr_equal(CUTSCENE_SYSTEM.entityInteracted, &ENTITIES[4]);
|
assert_ptr_equal(CUTSCENE_SYSTEM.refs.entityInteracted, &ENTITIES[4]);
|
||||||
// The snippet declares ALL, but INSERT doesn't apply it -- the outer
|
// The snippet declares ALL, but INSERT doesn't apply it -- the outer
|
||||||
// cutscene's NPC pause, already in effect, stands.
|
// cutscene's NPC pause, already in effect, stands.
|
||||||
assert_int_equal(CUTSCENE_SYSTEM.pause, CUTSCENE_PAUSE_NPC);
|
assert_int_equal(CUTSCENE_SYSTEM.pause, CUTSCENE_PAUSE_NPC);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ include(dusktest)
|
|||||||
# Tests
|
# Tests
|
||||||
dusktest(test_savesettings.c)
|
dusktest(test_savesettings.c)
|
||||||
dusktest(test_saveslot.c)
|
dusktest(test_saveslot.c)
|
||||||
|
target_sources(test_saveslot PRIVATE savetestfixture.c)
|
||||||
|
|
||||||
dusktest(test_savedevicelinux.c)
|
dusktest(test_savedevicelinux.c)
|
||||||
target_sources(test_savedevicelinux PRIVATE savetestfixture.c)
|
target_sources(test_savedevicelinux PRIVATE savetestfixture.c)
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "savetestfixture.h"
|
#include "savetestfixture.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
#include "asset/asset.h"
|
||||||
|
#include "asset/loader/assetloader.h"
|
||||||
|
#include "asset/loader/assetentry.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
@@ -22,6 +25,51 @@ static char_t SAVE_TEST_FIXTURE_HOME[PATH_MAX];
|
|||||||
static char_t SAVE_TEST_FIXTURE_REAL_HOME[PATH_MAX];
|
static char_t SAVE_TEST_FIXTURE_REAL_HOME[PATH_MAX];
|
||||||
static bool_t SAVE_TEST_FIXTURE_HAD_REAL_HOME;
|
static bool_t SAVE_TEST_FIXTURE_HAD_REAL_HOME;
|
||||||
|
|
||||||
|
static const char_t *SAVE_TEST_FIXTURE_PARTY_JSON =
|
||||||
|
"{\"members\":{\"hero\":{"
|
||||||
|
"\"attack\":10,\"defense\":5,\"magic\":0,\"speed\":10,\"luck\":0,"
|
||||||
|
"\"healthMax\":30,\"mpMax\":10"
|
||||||
|
"}}}";
|
||||||
|
|
||||||
|
static yyjson_doc *SAVE_TEST_FIXTURE_PARTY_DOC = NULL;
|
||||||
|
|
||||||
|
errorret_t saveTestFixturePartyJsonLoadSyncStub(assetloading_t *loading) {
|
||||||
|
loading->entry->data.json = SAVE_TEST_FIXTURE_PARTY_DOC;
|
||||||
|
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t saveTestFixturePartyJsonDisposeStub(assetentry_t *entry) {
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveTestFixtureStubPartyAsset(void) {
|
||||||
|
memoryZero(&ASSET, sizeof(ASSET));
|
||||||
|
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
||||||
|
threadMutexInit(&ASSET.loading[i].mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SAVE_TEST_FIXTURE_PARTY_DOC == NULL) {
|
||||||
|
SAVE_TEST_FIXTURE_PARTY_DOC = yyjson_read(
|
||||||
|
SAVE_TEST_FIXTURE_PARTY_JSON, strlen(SAVE_TEST_FIXTURE_PARTY_JSON), 0
|
||||||
|
);
|
||||||
|
assertNotNull(
|
||||||
|
SAVE_TEST_FIXTURE_PARTY_DOC, "Failed to parse party JSON fixture"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_JSON].loadSync =
|
||||||
|
saveTestFixturePartyJsonLoadSyncStub;
|
||||||
|
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_JSON].dispose =
|
||||||
|
saveTestFixturePartyJsonDisposeStub;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveTestFixtureUnstubPartyAsset(void) {
|
||||||
|
if(SAVE_TEST_FIXTURE_PARTY_DOC == NULL) return;
|
||||||
|
yyjson_doc_free(SAVE_TEST_FIXTURE_PARTY_DOC);
|
||||||
|
SAVE_TEST_FIXTURE_PARTY_DOC = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int_t saveTestFixtureRemoveEntry(
|
static int_t saveTestFixtureRemoveEntry(
|
||||||
const char *path,
|
const char *path,
|
||||||
const struct stat *statBuffer,
|
const struct stat *statBuffer,
|
||||||
@@ -49,6 +97,8 @@ int saveTestFixtureSetup(void **state) {
|
|||||||
|
|
||||||
assertTrue(setenv("HOME", SAVE_TEST_FIXTURE_HOME, 1) == 0, "setenv failed");
|
assertTrue(setenv("HOME", SAVE_TEST_FIXTURE_HOME, 1) == 0, "setenv failed");
|
||||||
|
|
||||||
|
saveTestFixtureStubPartyAsset();
|
||||||
|
|
||||||
errorret_t ret = saveInit();
|
errorret_t ret = saveInit();
|
||||||
assertTrue(errorIsOk(ret), "saveInit failed in test fixture");
|
assertTrue(errorIsOk(ret), "saveInit failed in test fixture");
|
||||||
|
|
||||||
@@ -56,6 +106,8 @@ int saveTestFixtureSetup(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int saveTestFixtureTeardown(void **state) {
|
int saveTestFixtureTeardown(void **state) {
|
||||||
|
saveTestFixtureUnstubPartyAsset();
|
||||||
|
|
||||||
nftw(
|
nftw(
|
||||||
SAVE_TEST_FIXTURE_HOME, saveTestFixtureRemoveEntry, 16,
|
SAVE_TEST_FIXTURE_HOME, saveTestFixtureRemoveEntry, 16,
|
||||||
FTW_DEPTH | FTW_PHYS
|
FTW_DEPTH | FTW_PHYS
|
||||||
|
|||||||
@@ -35,3 +35,21 @@ int saveTestFixtureTeardown(void **state);
|
|||||||
* filesystem permission tricks. Must be called after saveTestFixtureSetup.
|
* filesystem permission tricks. Must be called after saveTestFixtureSetup.
|
||||||
*/
|
*/
|
||||||
void saveTestFixtureBlockSaveDirectory(void);
|
void saveTestFixtureBlockSaveDirectory(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stubs the JSON asset loader's sync callback to hand back a small
|
||||||
|
* in-memory party.jsonc-shaped doc instead of doing a real file/zip read -
|
||||||
|
* saveInit()/saveSlotInit() seed the party roster via partyInit(), which
|
||||||
|
* loads party.jsonc through the real asset system, and there's no real
|
||||||
|
* asset bundle available under the test harness. No thread, no real I/O.
|
||||||
|
* Resets ASSET to a fresh, otherwise-empty state each call, so it's safe
|
||||||
|
* to call once per test. Called automatically by saveTestFixtureSetup.
|
||||||
|
*/
|
||||||
|
void saveTestFixtureStubPartyAsset(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the in-memory doc created by saveTestFixtureStubPartyAsset. Safe
|
||||||
|
* to call even if that function was never called. Called automatically
|
||||||
|
* by saveTestFixtureTeardown.
|
||||||
|
*/
|
||||||
|
void saveTestFixtureUnstubPartyAsset(void);
|
||||||
@@ -298,7 +298,7 @@ static void test_saveSaveSlot_invalidSlotIndexAsserts(void **state) {
|
|||||||
static void test_saveSaveSlot_success(void **state) {
|
static void test_saveSaveSlot_success(void **state) {
|
||||||
makeDeviceAvailable();
|
makeDeviceAvailable();
|
||||||
SAVE.slotCurrent = 1;
|
SAVE.slotCurrent = 1;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
stringCopy(
|
stringCopy(
|
||||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||||
);
|
);
|
||||||
@@ -336,7 +336,7 @@ static void test_saveLoadSlot_success(void **state) {
|
|||||||
// ever operates on SAVE.slot now), then reset it again below - the
|
// ever operates on SAVE.slot now), then reset it again below - the
|
||||||
// write and the load-under-test don't overlap in time.
|
// write and the load-under-test don't overlap in time.
|
||||||
SAVE.slotCurrent = 2;
|
SAVE.slotCurrent = 2;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
stringCopy(
|
stringCopy(
|
||||||
SAVE.slot.cachedData.name, "Zelda", sizeof(SAVE.slot.cachedData.name)
|
SAVE.slot.cachedData.name, "Zelda", sizeof(SAVE.slot.cachedData.name)
|
||||||
);
|
);
|
||||||
@@ -345,7 +345,7 @@ static void test_saveLoadSlot_success(void **state) {
|
|||||||
assert_true(errorIsOk(writeRet));
|
assert_true(errorIsOk(writeRet));
|
||||||
|
|
||||||
SAVE.slotCurrent = 2;
|
SAVE.slotCurrent = 2;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.slotDirty = true;
|
SAVE.slotDirty = true;
|
||||||
|
|
||||||
errorret_t ret = saveLoadSlot();
|
errorret_t ret = saveLoadSlot();
|
||||||
@@ -371,7 +371,7 @@ static void test_saveLoadSlot_deviceReadFails_cacheStaysStale(void **state) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
SAVE.slotCurrent = 0;
|
SAVE.slotCurrent = 0;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.caches[0].playerLevel = 77;// sentinel
|
SAVE.caches[0].playerLevel = 77;// sentinel
|
||||||
|
|
||||||
errorret_t ret = saveLoadSlot();
|
errorret_t ret = saveLoadSlot();
|
||||||
@@ -391,7 +391,7 @@ static void test_saveLoadAllSlots_loadsAllAndEndsAtLastIndex(void **state) {
|
|||||||
|
|
||||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||||
SAVE.slotCurrent = i;
|
SAVE.slotCurrent = i;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.slot.cachedData.playerLevel = (int32_t)(i + 1);
|
SAVE.slot.cachedData.playerLevel = (int32_t)(i + 1);
|
||||||
errorret_t saveRet = saveSaveSlot();
|
errorret_t saveRet = saveSaveSlot();
|
||||||
assert_true(errorIsOk(saveRet));
|
assert_true(errorIsOk(saveRet));
|
||||||
@@ -410,7 +410,7 @@ static void test_saveLoadAllSlots_missingFileLeavesInitDefaults(void **state) {
|
|||||||
makeDeviceAvailable();
|
makeDeviceAvailable();
|
||||||
|
|
||||||
SAVE.slotCurrent = 0;
|
SAVE.slotCurrent = 0;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.slot.cachedData.playerLevel = 5;
|
SAVE.slot.cachedData.playerLevel = 5;
|
||||||
errorret_t saveRet = saveSaveSlot();
|
errorret_t saveRet = saveSaveSlot();
|
||||||
assert_true(errorIsOk(saveRet));
|
assert_true(errorIsOk(saveRet));
|
||||||
@@ -433,7 +433,7 @@ static void test_saveLoadAllSlots_middleSlotCorrupt_stopsAtFailingIndex(
|
|||||||
makeDeviceAvailable();
|
makeDeviceAvailable();
|
||||||
|
|
||||||
SAVE.slotCurrent = 0;
|
SAVE.slotCurrent = 0;
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
errorret_t saveRet = saveSaveSlot();
|
errorret_t saveRet = saveSaveSlot();
|
||||||
assert_true(errorIsOk(saveRet));
|
assert_true(errorIsOk(saveRet));
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ static void test_saveDeviceSlot_dispatchesToPlatform(void **state) {
|
|||||||
|
|
||||||
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
||||||
// write source here.
|
// write source here.
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.slot.cachedData.playerLevel = 21;
|
SAVE.slot.cachedData.playerLevel = 21;
|
||||||
|
|
||||||
errorret_t writeRet = saveDeviceSlotWrite(&device, &SAVE.slot, 0);
|
errorret_t writeRet = saveDeviceSlotWrite(&device, &SAVE.slot, 0);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ static void test_slotWriteRead_roundTrip(void **state) {
|
|||||||
|
|
||||||
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
||||||
// write source here.
|
// write source here.
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
stringCopy(
|
stringCopy(
|
||||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,11 +9,25 @@
|
|||||||
#include "save/slot/saveslot.h"
|
#include "save/slot/saveslot.h"
|
||||||
#include "save/save.h"
|
#include "save/save.h"
|
||||||
#include "save/savejson.h"
|
#include "save/savejson.h"
|
||||||
|
#include "savetestfixture.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// saveSlotInit() seeds the party roster via partyInit(), which loads
|
||||||
|
// party.jsonc through the real asset system - stub it out (see
|
||||||
|
// savetestfixture.h) rather than needing a real asset bundle here.
|
||||||
|
static int assetGroupSetup(void **state) {
|
||||||
|
saveTestFixtureStubPartyAsset();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int assetGroupTeardown(void **state) {
|
||||||
|
saveTestFixtureUnstubPartyAsset();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Helpers - wrap the writeInit/readInit macros (which can only be used
|
// Helpers - wrap the writeInit/readInit macros (which can only be used
|
||||||
// inside a function returning errorret_t) so tests can call them plainly.
|
// inside a function returning errorret_t) so tests can call them plainly.
|
||||||
@@ -52,7 +66,7 @@ static errorret_t slotFromJSON(saveslot_t *slot, const char_t *json) {
|
|||||||
static void test_saveSlotInit_defaults(void **state) {
|
static void test_saveSlotInit_defaults(void **state) {
|
||||||
memorySet(&SAVE.slot, 0xFF, sizeof(SAVE.slot));
|
memorySet(&SAVE.slot, 0xFF, sizeof(SAVE.slot));
|
||||||
|
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
|
|
||||||
assert_int_equal(SAVE.slot.version, 1);
|
assert_int_equal(SAVE.slot.version, 1);
|
||||||
assert_int_equal(SAVE.slot.dataType, 0);
|
assert_int_equal(SAVE.slot.dataType, 0);
|
||||||
@@ -66,7 +80,7 @@ static void test_saveSlotInit_defaults(void **state) {
|
|||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
static void test_saveSlotInUse(void **state) {
|
static void test_saveSlotInUse(void **state) {
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
|
|
||||||
assert_false(saveSlotInUse(&SAVE.slot.cachedData));
|
assert_false(saveSlotInUse(&SAVE.slot.cachedData));
|
||||||
|
|
||||||
@@ -81,7 +95,7 @@ static void test_saveSlotInUse_nullAsserts(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_saveSlotHasSaved(void **state) {
|
static void test_saveSlotHasSaved(void **state) {
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
|
|
||||||
assert_false(saveSlotHasSaved(&SAVE.slot.cachedData));
|
assert_false(saveSlotHasSaved(&SAVE.slot.cachedData));
|
||||||
|
|
||||||
@@ -136,7 +150,7 @@ static void test_saveSlotReadJSON_nullAsserts(void **state) {
|
|||||||
static void test_saveSlotReadJSON_roundTrip(void **state) {
|
static void test_saveSlotReadJSON_roundTrip(void **state) {
|
||||||
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
||||||
// write source here.
|
// write source here.
|
||||||
saveSlotInit();
|
saveSlotInit(&SAVE.slot);
|
||||||
SAVE.slot.version = 7;// deliberately non-default, not part of the JSON schema
|
SAVE.slot.version = 7;// deliberately non-default, not part of the JSON schema
|
||||||
stringCopy(
|
stringCopy(
|
||||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||||
@@ -296,5 +310,5 @@ int main(void) {
|
|||||||
cmocka_unit_test(test_saveSlotReadJSON_versionMismatch_errors),
|
cmocka_unit_test(test_saveSlotReadJSON_versionMismatch_errors),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
return cmocka_run_group_tests(tests, assetGroupSetup, assetGroupTeardown);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user