-
Notifications
You must be signed in to change notification settings - Fork 192
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
String Variables #3051
Conversation
Jenkins: test this please <3 Thanks for this huge contribution! You received an invite for the "Player Team". This whitelists you for the pull request builder (will auto-build your stuff). Also add yourself and all other authors that contributed to this to the Authors.md if you havn't done already. |
Not going to review this right now as is a bit too long xD. But one remark already: I don't like the commit text. Could you prefix all of them with something like The easiest way to do this should be:
Then change all the After save and quit git will open a text editor for every single commit (so 23 times). Here prefix all the commits with something like Then push: Is a bit tedious but shouldn't take more than a few minutes. |
Uploaded the string var test project to the web player: https://easyrpg.org/play/pr3051/?game=string-var (note that txt file loading won't work as the code for "async asset fetching" is not implemented currently) |
Looks like String vars in a string pic isn't fully supported -- while you can display a stringvar through message codes (e.g. |
except for StringPics (where this appears to be used alot(?)) I would prefer to have support for string-vars in the other commands as another PR. Adding support to all other commands is alot of additional complexity and lots of more testing that nothing breaks. So not required for the MVP. ;) |
I agree -- don't want to explode the scope of this. Isolating to supporting string pics sounds reasonable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only quickly looked through the code and these are the largest issues I'm currently seeing.
Sorry but text processing and encodings is tricky so we must think here of all the edge-cases as we are multi-platform, multi-language and Unicode aware, so a "lol, works in Japan for me" is not good enough.
All in all for your first PR (which solves a complex problem) this is already pretty good work :).
int len = static_cast<std::string>(Get(params.string_id)).length(); | ||
Main_Data::game_variables->Set(var_id, len); | ||
return len; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be checked (same for index
returned by InStr
):
What kind of encoding is Maniac Patch using here?
Is this the length in bytes or in codepoints? When it is the length in bytes is it in local encoding or in UTF-8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the PR as it is, the player does not behave the same way.
With files read as utf8, we are saying its length is 17
With files read as ansi, we are saying its length is 17
And when assigned directly to a string, we are saying its length is 15... I believe this is because tpc
doesn't allow the ứ
character (either due to my computer's locale or tpc itself, no idea).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like BingShan recently released an update to tpc
on his private discord that does not encode the text-editor as shift-jis, so I may be able to test this a little more comprehensively... I'll check this out.
src/game_strings.cpp
Outdated
if (params.hex) | ||
num = std::stoi(str, 0, 16); | ||
else | ||
num = std::stoi(str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::stoi
is problematic because it throws an exception when conversion fails and we have exceptions disabled = crash
If you need no error checking (error is 0, if this matches Maniac Patch???) use atoi
and if you need error checking and different bases use std::strtoimax
https://en.cppreference.com/w/cpp/string/byte/strtoimax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know this about std::stoi
, good note! I will look into the alternatives suggested.
Ghabry asked to list the issues pointed at rm2k3 channel:
@loop 20 {
v[1] += 1
t[2] .asg v[1]
t[1] .asg .cat t[2], "
", t[1]
}
@pic[1].strpic {
"\t[1]"
.pos 160, 120 .center
.size 0, 0 .chromakey 1
.scale 100
.trans 0
.rgbs 100, 100, 100, 100
.font "", 12
.spacing 0, 4
.skin "" .stretch
.mapLayer 7
.eraseWhenTransfer
.affectedByFlash
.affectedByShake
} this last one may have been fixed already. |
a09f033
to
7e6e982
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, I think we are 98% there :)
I rebased the PR but I cannot push to the branch (because it is master I guess?). Will likely close this PR later and create my own to resolve the last pending issues. Oh and thanks again for figuring this all out. This looked like a huge afford, the stuff I have to fix is simple compared to it ^^ |
-Simple assign and concatenation operations already work -Added the escape \t[x] for messages -Complete documentation of the inner workings of the command made by BingShan
i had deleted some code from the insert subcommand previously somehow
Have resolved most issues, still a couple hanging threads to resolve. An issue has cropped up with displaying string pictures, though. Seems to be related to some code changes I had to accommodate on rebase in the Player also appears to incorrectly(?) color text when maniacs does not, but I don't know how concerned I am about that particular thing. For the newline stripping piece, I will try to find time to dig into the PendingMessage class in more depth to deduce why this is happening. |
some related code changed during the rebase and this no longer appears to be necessary
I have a hard time going through the tests because I'm already stuck for a long time at the first one: Bottom left. Just this bottom left test took me already 90 minutes to check what is going in... First discovery: Maniac changed how unknown command codes are parsed. E.g. a message with Top Maniac, Bottom Player: I wouldn't say that we are wrong here. This is just how it worked in original RPG_RT. Also is an edge-case nobody will usually encounter. Notice the missing Imo test passed ✔️ Looks like what we need for Test failed ➖ Upon more testing there seems to be in general a difference in how the message box resolves codes: When you call Hero 1 |
The 2nd test at the bottom row is also completely different. Left is Maniac, Right is Player. Am I using the wrong version of Maniac patch? I use the RPG_RT.exe provided in the ZIP archive of the test game. Sorry I cannot continue this review under these circumstances. My time is limited and something is completely broken. |
About the remaining issues according to the screenshots:
The last two cannot be fully implemented because we use shared code for both messages and string pics compared to Maniacs which seems to use 2 implementations...... |
@enewey I figured out solutions for most of the remaining problems. Just need to clean it up a bit. Will send you a patch on Sunday or Monday that will resolve them. |
one thing we forgot to take a look is loading text files with webplayer |
Fix crash when older string var commands are used.
In Messages commands in \t[] are evaluated once. In StringPics and Extract they are not.
@enewey Creating commits was easier than explaining but I cannot push to your master branch (permission denied). Please grab my commits manually:
Now you have my commits and you can push. |
@jetrotal In case you already want to retest here is an emscripten instance with my changes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is already complex enough and it is a very solid implementation of String Vars. Thanks again for this huge contribution.
There is only nitpicky stuff left (e.g. lack of unit tests, lots of copying instead of string view, code formatting in some parts) but this can be all addressed later.
implements all major maniacs string variable operations and modifiers, with the exception of the
.sjis
and.utf8
encoding modifiers for file reading/writing..asg & .cat
t[..]
v[..]
s[..]
.actor [a] .name
.skill [a] .name
.item [a] .name
.enemy [a] .name
.troop [a] .name
.terrain [a] .name
.element [a] .name
.state [a] .name
.anim [a] .name
.tileset [a] .name
.s [a] .name
.v [a] .name
.t [a] .name
.cev [a] .name
.class [a] .name
.anim2 [a] .name
.map [a] .name
.mev [a] .name
.member [a] .name
.actor [a] .desc
.skill [a] .desc
.item [a] .desc
.member [a] .desc
.cat
.ins
.rem
.rep
.exrep
.subs
.join
.file
.toNum
.getLen
.inStr
.exInStr
.exMatch
.split
.toFile
.popLine
also adds support for string comparators in conditional statements
.eq
.neq
.contains
.notContains
2k3 test project used for developing these features:
https://rpgmaker.net/users/narcodis/locker/easyrpg_testing.zip
proper unit testing could be added 😓
Web Player test: https://easyrpg.org/play/pr3051/?game=string-var