Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Variables #3051

Merged
merged 47 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
86d6407
StringVar: Basic implementation
JorgeMaker8000 Apr 26, 2023
409a4ed
StringVar: :Game_Strings: minor update
JorgeMaker8000 Apr 26, 2023
87ae111
StringVar: add min and range support for string asg and cat
enewey Jun 27, 2023
f95ee78
StringVar: add num asg & cat
enewey Jun 27, 2023
e1613c3
StringVar: add some string name assigns
enewey Jun 28, 2023
63f850d
StringVar: add concat subcommand to string assignment
enewey Jun 28, 2023
5d0150f
StringVar: refactors, add insert and replace subcommands
enewey Jun 28, 2023
1174d54
StringVar: add substring support
enewey Jun 28, 2023
12d14d1
StringVar: add join, rem, exrep subcommands, fix insert
enewey Jun 28, 2023
164e909
StringVar: convert casts to static_cast
enewey Jun 28, 2023
0279892
StringVar: add toNum function
enewey Jun 29, 2023
6de91d4
StringVar: add getLen and inStr functions
enewey Jun 29, 2023
17dab18
StringVar: more refactors and add split function
enewey Jun 29, 2023
fb1af42
StringVar: add popline function
enewey Jun 29, 2023
c8fcc85
StringVar: add regex find and replace functions
enewey Jun 29, 2023
77e304a
StringVar: first pass at extract functionality
enewey Jun 29, 2023
8902752
StringVar: support entity description assignment/concat
enewey Jun 30, 2023
c214739
StringVar: add read file to string
enewey Jun 30, 2023
fac88ca
StringVar: first pass at file writing support
enewey Jul 3, 2023
82ee999
StringVar: add support for string conditionals
enewey Jul 3, 2023
ad3ebdc
StringVar: add support for hex conversion in extract operators
enewey Jul 4, 2023
88c8934
StringVar: more hex support in string functions
enewey Jul 5, 2023
7c3e2ef
StringVar: properly use fallback for opening files
enewey Jul 5, 2023
a0d976f
StringVar: add find generic fallback function for FindText
enewey Jul 5, 2023
6aa50b3
StringVar: support more text types
enewey Jul 5, 2023
e1c6312
StringVars: parse string pic delimiters to support direct and indirec…
enewey Jul 6, 2023
ab783c8
StringVar: fix split function
enewey Jul 7, 2023
6ef09ab
StringVar: fix join function
enewey Jul 7, 2023
1c5b6f6
StringVar: crack at fixing line breaks in show string pic
enewey Jul 7, 2023
329a280
StringVar: add safety to parsing string pic delimiters
enewey Jul 12, 2023
0ec5f0c
StringVar: refactor from DBString to std string
enewey Jul 12, 2023
95a90eb
refactor maniac helpers into maniac_patch module
enewey Jul 13, 2023
f540e2c
StringVar: add switch to string conversion
enewey Jul 13, 2023
48c87d5
StringVar: fix game_message string param parse result
enewey Oct 12, 2023
c6349be
StringVar: change string comparison strategy, remove regex
enewey Oct 12, 2023
5a9ef06
StringVar: use Utils ReadLine instead of std getline
enewey Oct 12, 2023
8d32f7a
StringVar: use ValueOrVariable and remove redundant helper function
enewey Oct 13, 2023
c4f1ac3
updated to read files from Save first before game files
enewey Oct 13, 2023
9e5aa88
StringVar: remove string extract logic from game_windows
enewey Oct 13, 2023
2bbf64d
StringVar: Support files with Ansi encoding
Ghabry Oct 22, 2023
ed00633
String Pic: Interpret Linebreaks (\n)
Ghabry Oct 22, 2023
069828e
String Var: Move Maniac Command Inserters to Game_Strings
Ghabry Oct 22, 2023
6886f03
String Var: Use lambdas in GetLcfName and GetLcfDesc to make the code…
Ghabry Oct 22, 2023
e20c316
String Var: Use correct extraction logic for \t[]
Ghabry Oct 22, 2023
26ff6b8
Add eneway aka narcodis as Author
Ghabry Oct 22, 2023
6480213
String Var: Fetch the text file for emscripten
Ghabry Oct 22, 2023
7221769
StringVars: remove debug statements
enewey Oct 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ add_library(${PROJECT_NAME} OBJECT
src/game_quit.h
src/game_screen.cpp
src/game_screen.h
src/game_strings.cpp
src/game_strings.h
src/game_switches.cpp
src/game_switches.h
src/game_system.cpp
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ libeasyrpg_player_a_SOURCES = \
src/game_player.h \
src/game_screen.cpp \
src/game_screen.h \
src/game_strings.cpp \
src/game_strings.h \
src/game_switches.cpp \
src/game_switches.h \
src/game_system.cpp \
Expand Down
1 change: 1 addition & 0 deletions docs/AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ EasyRPG Player authors
* Carsten Teibes (carstene1ns)
* Christian Breitwieser (ChrisBreiti)
* Diego Pedraza (zegeri)
* Erich Newey (enewey)
* Dmytro Kushnariov (rohkea)
* Francisco de la Peña (fdelapena)
* Gabriel Kind (Ghabry)
Expand Down
10 changes: 10 additions & 0 deletions src/async_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ bool AsyncHandler::IsFilePending(bool important, bool graphic) {
return false;
}

void AsyncHandler::SaveFilesystem() {
#ifdef EMSCRIPTEN
// Save changed file system
EM_ASM({
FS.syncfs(function(err) {
});
});
#endif
}

bool AsyncHandler::IsImportantFilePending() {
return IsFilePending(true, false);
}
Expand Down
6 changes: 6 additions & 0 deletions src/async_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ namespace AsyncHandler {
* @return If any file with params is pending.
*/
bool IsFilePending(bool important, bool graphic);

/**
* Saves the state of the Save filesystem.
* Only works on emscripten, noop on other platforms.
*/
void SaveFilesystem();
}

using FileRequestBinding = std::shared_ptr<int>;
Expand Down
12 changes: 6 additions & 6 deletions src/dynrpg_textplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class DynRpgText : public Drawable {
}

static DynRpgText* GetTextHandle(const std::string& id, bool silent = false) {
PendingMessage pm;
pm.PushLine(id, DynRpgText::CommandCodeInserter);
PendingMessage pm(CommandCodeInserter);
pm.PushLine(id);
std::string new_id = pm.GetLines().front();

auto it = graphics.find(new_id);
Expand Down Expand Up @@ -230,8 +230,8 @@ class DynRpgText : public Drawable {
const FontRef& font = Font::Default();

for (auto& t : texts) {
PendingMessage pm;
pm.PushLine(t, CommandCodeInserter);
PendingMessage pm(CommandCodeInserter);
pm.PushLine(t);
t = pm.GetLines().front();

Rect r = Text::GetSize(*font, t);
Expand Down Expand Up @@ -269,8 +269,8 @@ static bool WriteText(dyn_arg_list args) {
if (!okay)
return true;

PendingMessage pm;
pm.PushLine(id, DynRpgText::CommandCodeInserter);
PendingMessage pm(DynRpgText::CommandCodeInserter);
pm.PushLine(id);
std::string new_id = pm.GetLines().front();
graphics[new_id] = std::make_unique<DynRpgText>(1, x, y, text);

Expand Down
30 changes: 30 additions & 0 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace {
constexpr const auto SOUND_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mp3", ".wma");
constexpr const auto FONTS_TYPES = Utils::MakeSvArray(".fon", ".fnt", ".bdf", ".ttf", ".ttc", ".otf", ".woff2", ".woff");
constexpr const auto TEXT_TYPES = Utils::MakeSvArray(".txt", ".csv", ".svg", ".xml", ".json", ".yml", ".yaml");
}

FilesystemView FileFinder::Game() {
Expand Down Expand Up @@ -337,6 +338,15 @@ std::string find_generic(const DirectoryTree::Args& args) {
return FileFinder::Game().FindFile(args);
}

std::string find_generic_with_fallback(DirectoryTree::Args& args) {
std::string found = FileFinder::Save().FindFile(args);
if (found.empty()) {
return find_generic(args);
}
enewey marked this conversation as resolved.
Show resolved Hide resolved

return found;
}

std::string FileFinder::FindImage(StringView dir, StringView name) {
DirectoryTree::Args args = { MakePath(dir, name), IMG_TYPES, 1, false };
return find_generic(args);
Expand All @@ -358,6 +368,11 @@ std::string FileFinder::FindFont(StringView name) {
return find_generic(args);
}

std::string FileFinder::FindText(StringView name) {
DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, true };
return find_generic_with_fallback(args);
}

Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, DirectoryTree::Args& args) {
if (!Tr::GetCurrentTranslationId().empty()) {
auto tr_fs = Tr::GetCurrentTranslationFilesystem();
Expand All @@ -377,6 +392,16 @@ Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, Dir
return is;
}

Filesystem_Stream::InputStream open_generic_with_fallback(StringView dir, StringView name, DirectoryTree::Args& args) {
auto is = FileFinder::Save().OpenFile(args);
if (!is) { is = open_generic(dir, name, args); }
if (!is) {
Output::Debug("Unable to open in either Game or Save: {}/{}", dir, name);
}
enewey marked this conversation as resolved.
Show resolved Hide resolved

return is;
}

Filesystem_Stream::InputStream FileFinder::OpenImage(StringView dir, StringView name) {
DirectoryTree::Args args = { MakePath(dir, name), IMG_TYPES, 1, false };
return open_generic(dir, name, args);
Expand All @@ -397,6 +422,11 @@ Filesystem_Stream::InputStream FileFinder::OpenFont(StringView name) {
return open_generic("Font", name, args);
}

Filesystem_Stream::InputStream FileFinder::OpenText(StringView name) {
DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, false };
return open_generic_with_fallback("Text", name, args);
}

bool FileFinder::IsMajorUpdatedTree() {
auto fs = Game();
assert(fs);
Expand Down
38 changes: 33 additions & 5 deletions src/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ namespace FileFinder {
*/
std::string FindSound(StringView name);

/**
* Finds a font file.
* Searches through the current RPG Maker game and the RTP directories.
*
* @param name the font name.
* @return path to file.
*/
std::string FindFont(StringView name);

/**
* Finds a text file in the current RPG Maker game.
*
* @param name the text path and name.
* @return path to file.
*/
std::string FindText(StringView name);

/**
* Finds an image file and opens a file handle to it.
* Searches through the current RPG Maker game and the RTP directories.
Expand Down Expand Up @@ -137,13 +154,24 @@ namespace FileFinder {
Filesystem_Stream::InputStream OpenFont(StringView name);

/**
* Finds a font file.
* Searches through the current RPG Maker game and the RTP directories.
* Finds a text file and opens a file handle to it.
* Searches through the Text folder of the current RPG Maker game.
* Will also search through the directory save files are written to as a fallback,
* as it needs to account for files written by the game as well.
*
* @param name the font name.
* @return path to file.
* @param name the text path and name.
* @return read handle on success or invalid handle if not found
*/
std::string FindFont(StringView name);
Filesystem_Stream::InputStream OpenText(StringView name);

/**
* Writes data to a txt file.
* If the file exists, it will be overwritten.
*
* @param name the text file path and name
* @param data the content of the text file to be written
*/
void WriteText(StringView name, StringView data);

/**
* Appends name to directory.
Expand Down
Loading