Skip to content

Commit d1e3602

Browse files
authored
Merge pull request #2280 from fmatthew5876/string
Use liblcf string and array types
2 parents 3e58779 + 2ef5483 commit d1e3602

66 files changed

Lines changed: 247 additions & 299 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/battle_animation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BattleAnimation::BattleAnimation(const lcf::rpg::Animation& anim, bool only_soun
4242

4343
SetZ(Priority_BattleAnimation);
4444

45-
const std::string& name = animation.animation_name;
45+
StringView name = animation.animation_name;
4646
BitmapRef graphic;
4747

4848
if (name.empty()) return;

src/game_actor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ std::string Game_Actor::GetLearningMessage(const lcf::rpg::Skill& skill) const {
747747
);
748748
}
749749

750-
return skill.name + (Player::IsRPG2k3E() ? " " : "") + lcf::Data::terms.skill_learned;
750+
return ToString(skill.name) + (Player::IsRPG2k3E() ? " " : "") + ToString(lcf::Data::terms.skill_learned);
751751
}
752752

753753
void Game_Actor::ChangeLevel(int new_level, PendingMessage* pm) {
@@ -823,9 +823,9 @@ Point Game_Actor::GetOriginalPosition() const {
823823
return { actor.battle_x, actor.battle_y };
824824
}
825825

826-
const std::string& Game_Actor::GetSkillName() const {
826+
StringView Game_Actor::GetSkillName() const {
827827
auto& a = GetActor();
828-
return a.rename_skill ? a.skill_name : lcf::Data::terms.command_skill;
828+
return a.rename_skill ? StringView(a.skill_name) : StringView(lcf::Data::terms.command_skill);
829829
}
830830

831831
void Game_Actor::SetSprite(const std::string &file, int index, bool transparent) {
@@ -1041,9 +1041,9 @@ void Game_Actor::ChangeClass(int new_class_id,
10411041
}
10421042
}
10431043

1044-
std::string Game_Actor::GetClassName() const {
1044+
StringView Game_Actor::GetClassName() const {
10451045
if (!GetClass()) {
1046-
return "";
1046+
return {};
10471047
}
10481048
return GetClass()->name;
10491049
}

src/game_actor.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@
2222
#include <string>
2323
#include <vector>
2424
#include <cstdint>
25+
#include <lcf/rpg/fwd.h>
2526
#include <lcf/rpg/saveactor.h>
2627
#include <lcf/rpg/learning.h>
2728
#include "game_battler.h"
28-
29-
namespace lcf {
30-
namespace rpg {
31-
class Actor;
32-
class Skill;
33-
class BattleCommand;
34-
class Item;
35-
class Class;
36-
} // namespace rpg
37-
} // namespace lcf
29+
#include "string_view.h"
3830

3931
class PendingMessage;
4032

@@ -245,14 +237,14 @@ class Game_Actor final : public Game_Battler {
245237
*
246238
* @return name.
247239
*/
248-
const std::string& GetName() const override;
240+
StringView GetName() const override;
249241

250242
/**
251243
* Gets actor character sprite filename.
252244
*
253245
* @return character sprite filename.
254246
*/
255-
const std::string& GetSpriteName() const override;
247+
StringView GetSpriteName() const override;
256248

257249
/**
258250
* Gets actor character sprite index.
@@ -271,7 +263,7 @@ class Game_Actor final : public Game_Battler {
271263
*
272264
* @return face graphic filename.
273265
*/
274-
const std::string& GetFaceName() const;
266+
StringView GetFaceName() const;
275267

276268
/**
277269
* Gets actor face graphic index.
@@ -681,7 +673,7 @@ class Game_Actor final : public Game_Battler {
681673
*
682674
* @return name of skill menu item
683675
*/
684-
const std::string& GetSkillName() const;
676+
StringView GetSkillName() const;
685677

686678
/**
687679
* Sets new actor name.
@@ -764,7 +756,7 @@ class Game_Actor final : public Game_Battler {
764756
*
765757
* @return Rpg2k3 hero class name
766758
*/
767-
std::string GetClassName() const;
759+
StringView GetClassName() const;
768760

769761
/**
770762
* Gets battle commands.
@@ -889,7 +881,7 @@ inline void Game_Actor::SetName(const std::string &new_name) {
889881
}
890882

891883

892-
inline const std::string& Game_Actor::GetName() const {
884+
inline StringView Game_Actor::GetName() const {
893885
return GetData().name;
894886
}
895887

@@ -901,7 +893,7 @@ inline const std::string& Game_Actor::GetTitle() const {
901893
return GetData().title;
902894
}
903895

904-
inline const std::string& Game_Actor::GetSpriteName() const {
896+
inline StringView Game_Actor::GetSpriteName() const {
905897
return GetData().sprite_name;
906898
}
907899

@@ -913,7 +905,7 @@ inline int Game_Actor::GetSpriteTransparency() const {
913905
return GetData().transparency;
914906
}
915907

916-
inline const std::string& Game_Actor::GetFaceName() const {
908+
inline StringView Game_Actor::GetFaceName() const {
917909
return GetData().face_name;
918910
}
919911

src/game_battle.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define EP_GAME_BATTLE_H
2020

2121
#include <functional>
22+
#include <lcf/rpg/fwd.h>
2223
#include <lcf/rpg/system.h>
2324
#include <lcf/rpg/troop.h>
2425
#include "teleport_target.h"
@@ -31,12 +32,6 @@ class Game_Actor;
3132
class Game_Interpreter;
3233
class Spriteset_Battle;
3334

34-
namespace lcf {
35-
namespace rpg {
36-
class EventPage;
37-
} // namespace rpg
38-
} // namespace lcf
39-
4035
enum class BattleResult {
4136
Victory,
4237
Escape,

src/game_battlealgorithm.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDeathMessage() const {
358358

359359
bool is_ally = GetTarget()->GetType() == Game_Battler::Type_Ally;
360360
const lcf::rpg::State* state = lcf::ReaderUtil::GetElement(lcf::Data::states, 1);
361-
const std::string& message = is_ally ? state->message_actor
361+
StringView message = is_ally ? state->message_actor
362362
: state->message_enemy;
363363

364364
if (Player::IsRPG2kE()) {
@@ -369,15 +369,15 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDeathMessage() const {
369369
);
370370
}
371371
else {
372-
return GetTarget()->GetName() + message;
372+
return ToString(GetTarget()->GetName()) + ToString(message);
373373
}
374374
}
375375

376376
lcf::rpg::State::Restriction Game_BattleAlgorithm::AlgorithmBase::GetSourceRestrictionWhenStarted() const {
377377
return source_restriction;
378378
}
379379

380-
std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(const std::string& message) const {
380+
std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(StringView message) const {
381381
if (Player::IsRPG2kE()) {
382382
return Utils::ReplacePlaceholders(
383383
message,
@@ -386,11 +386,11 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(const s
386386
);
387387
}
388388
else {
389-
return GetTarget()->GetName() + message;
389+
return ToString(GetTarget()->GetName()) + ToString(message);
390390
}
391391
}
392392

393-
std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int value, const std::string& points) const {
393+
std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int value, StringView points) const {
394394
if (Player::IsRPG2kE()) {
395395
return Utils::ReplacePlaceholders(
396396
lcf::Data::terms.hp_recovery,
@@ -420,7 +420,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int val
420420
std::string Game_BattleAlgorithm::AlgorithmBase::GetUndamagedMessage() const {
421421
bool target_is_ally = (GetTarget()->GetType() ==
422422
Game_Battler::Type_Ally);
423-
const std::string& message = target_is_ally ?
423+
StringView message = target_is_ally ?
424424
lcf::Data::terms.actor_undamaged :
425425
lcf::Data::terms.enemy_undamaged;
426426

@@ -432,14 +432,14 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetUndamagedMessage() const {
432432
);
433433
}
434434
else {
435-
return GetTarget()->GetName() + message;
435+
return ToString(GetTarget()->GetName()) + ToString(message);
436436
}
437437
}
438438

439439
std::string Game_BattleAlgorithm::AlgorithmBase::GetCriticalHitMessage() const {
440440
bool target_is_ally = (GetTarget()->GetType() ==
441441
Game_Battler::Type_Ally);
442-
const std::string& message = target_is_ally ?
442+
StringView message = target_is_ally ?
443443
lcf::Data::terms.actor_critical :
444444
lcf::Data::terms.enemy_critical;
445445

@@ -451,14 +451,14 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetCriticalHitMessage() const {
451451
);
452452
}
453453
else {
454-
return message;
454+
return ToString(message);
455455
}
456456
}
457457

458-
std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int value, const std::string& points) const {
458+
std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int value, StringView points) const {
459459
bool target_is_ally = (GetTarget()->GetType() ==
460460
Game_Battler::Type_Ally);
461-
const std::string& message = target_is_ally ?
461+
StringView message = target_is_ally ?
462462
lcf::Data::terms.actor_hp_absorbed :
463463
lcf::Data::terms.enemy_hp_absorbed;
464464

@@ -492,7 +492,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int valu
492492
std::string Game_BattleAlgorithm::AlgorithmBase::GetDamagedMessage() const {
493493
bool target_is_ally = (GetTarget()->GetType() ==
494494
Game_Battler::Type_Ally);
495-
const std::string& message = target_is_ally ?
495+
StringView message = target_is_ally ?
496496
lcf::Data::terms.actor_damaged :
497497
lcf::Data::terms.enemy_damaged;
498498
int value = GetAffectedHp();
@@ -520,8 +520,8 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDamagedMessage() const {
520520
}
521521
}
522522

523-
std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool is_positive, int value, const std::string& points) const {
524-
const std::string& message = is_positive ?
523+
std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool is_positive, int value, StringView points) const {
524+
StringView message = is_positive ?
525525
lcf::Data::terms.parameter_increase :
526526
lcf::Data::terms.parameter_decrease;
527527

@@ -552,7 +552,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool
552552
}
553553
}
554554

555-
std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(const std::string& message) const {
555+
std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(StringView message) const {
556556
if (Player::IsRPG2kE()) {
557557
return Utils::ReplacePlaceholders(
558558
message,
@@ -561,12 +561,12 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(const std::stri
561561
);
562562
}
563563
else {
564-
return GetTarget()->GetName() + message;
564+
return ToString(GetTarget()->GetName()) + ToString(message);
565565
}
566566
}
567567

568-
std::string Game_BattleAlgorithm::AlgorithmBase::GetAttributeShiftMessage( const std::string& attribute) const {
569-
const std::string& message = IsPositive() ?
568+
std::string Game_BattleAlgorithm::AlgorithmBase::GetAttributeShiftMessage(StringView attribute) const {
569+
StringView message = IsPositive() ?
570570
lcf::Data::terms.resistance_increase :
571571
lcf::Data::terms.resistance_decrease;
572572
std::stringstream ss;
@@ -1110,7 +1110,7 @@ std::string Game_BattleAlgorithm::Normal::GetStartMessage() const {
11101110
);
11111111
}
11121112
else {
1113-
return source->GetName() + lcf::Data::terms.attacking;
1113+
return ToString(source->GetName()) + ToString(lcf::Data::terms.attacking);
11141114
}
11151115
}
11161116
else {
@@ -1418,11 +1418,11 @@ std::string Game_BattleAlgorithm::Skill::GetStartMessage() const {
14181418
);
14191419
}
14201420
else {
1421-
return source->GetName() + skill.using_message1;
1421+
return ToString(source->GetName()) + ToString(skill.using_message1);
14221422
}
14231423
}
14241424
else {
1425-
return skill.name;
1425+
return ToString(skill.name);
14261426
}
14271427
}
14281428

@@ -1444,7 +1444,7 @@ std::string Game_BattleAlgorithm::Skill::GetSecondStartMessage() const {
14441444
);
14451445
}
14461446
else {
1447-
return skill.using_message2;
1447+
return ToString(skill.using_message2);
14481448
}
14491449
}
14501450
else {
@@ -1678,10 +1678,10 @@ std::string Game_BattleAlgorithm::Item::GetStartMessage() const {
16781678
particle = "";
16791679
else
16801680
particle = " ";
1681-
return source->GetName() + particle + item.name + lcf::Data::terms.use_item;
1681+
return ToString(source->GetName()) + particle + ToString(item.name) + ToString(lcf::Data::terms.use_item);
16821682
}
16831683
else {
1684-
return item.name;
1684+
return ToString(item.name);
16851685
}
16861686
}
16871687

@@ -1716,7 +1716,7 @@ std::string Game_BattleAlgorithm::Defend::GetStartMessage() const {
17161716
);
17171717
}
17181718
else if (Player::IsRPG2k()) {
1719-
return source->GetName() + lcf::Data::terms.defending;
1719+
return ToString(source->GetName()) + ToString(lcf::Data::terms.defending);
17201720
}
17211721
else {
17221722
return "";
@@ -1750,7 +1750,7 @@ std::string Game_BattleAlgorithm::Observe::GetStartMessage() const {
17501750
);
17511751
}
17521752
else if (Player::IsRPG2k()) {
1753-
return source->GetName() + lcf::Data::terms.observing;
1753+
return ToString(source->GetName()) + ToString(lcf::Data::terms.observing);
17541754
}
17551755
else {
17561756
return "";
@@ -1777,7 +1777,7 @@ std::string Game_BattleAlgorithm::Charge::GetStartMessage() const {
17771777
);
17781778
}
17791779
else if (Player::IsRPG2k()) {
1780-
return source->GetName() + lcf::Data::terms.focus;
1780+
return ToString(source->GetName()) + ToString(lcf::Data::terms.focus);
17811781
}
17821782
else {
17831783
return "";
@@ -1808,7 +1808,7 @@ std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage() const {
18081808
);
18091809
}
18101810
else if (Player::IsRPG2k()) {
1811-
return source->GetName() + lcf::Data::terms.autodestruction;
1811+
return ToString(source->GetName()) + ToString(lcf::Data::terms.autodestruction);
18121812
}
18131813
else {
18141814
return "";
@@ -1888,7 +1888,7 @@ std::string Game_BattleAlgorithm::Escape::GetStartMessage() const {
18881888
}
18891889
else if (Player::IsRPG2k()) {
18901890
if (source->GetType() == Game_Battler::Type_Enemy) {
1891-
return source->GetName() + lcf::Data::terms.enemy_escape;
1891+
return ToString(source->GetName()) + ToString(lcf::Data::terms.enemy_escape);
18921892
}
18931893
}
18941894

@@ -1940,7 +1940,7 @@ std::string Game_BattleAlgorithm::Transform::GetStartMessage() const {
19401940
);
19411941
}
19421942
else if (Player::IsRPG2k()) {
1943-
return source->GetName() + lcf::Data::terms.enemy_transform;
1943+
return ToString(source->GetName()) + ToString(lcf::Data::terms.enemy_transform);
19441944
}
19451945
else {
19461946
return "";

0 commit comments

Comments
 (0)