Repository navigation
Conversation
This is curently a standalone python file, and needs integration into pylivemaker build environment.
The export/import file format is similar/compatible to the menu translation format.
|
Changes are failing lint @Stefan311 can you run (once the pre-commit hook is installed, it'll run automatically whenever you try to commit changes in the future) |
|
I'll have to think about this one a bit, I'm hesitant to merge changes that can potentially lead to abusing undocumented API endpoints. I know the Maybe some separated behavior would be better, where pylm can read/write to csv's, and then the user can then translate the csv however they want. But we would not actually do the machine translate step in a pylm CLI tool. |
''stefan@stefan-P55A-UD4:~/pylivemaker$ pre-commit install |
|
you might need to do |
Sure. You are free to take or to drop this. That's why this is a separate command, and separate commit. |
Works, fixed the hard errors, but does a terrible re-formatting. Is this really necessary? |
| sys.exit('Could not generate new LSB file: {}'.format(e)) | ||
|
|
||
|
|
||
| def scan_texts(lsb, csv_data, file_name, extract=False, patch=False): |
There was a problem hiding this comment.
This function is way too big and should be broken up into smaller chunks. Stuff can go into it's own function even if that function is only called once. Basically you should not have python functions where you need 10+ levels of indentation, because it becomes really hard to read even after just a few levels of indentation.
the main reason the reformatter makes this code look particularly bad is because of the excessive levels of indentation
There was a problem hiding this comment.
Way too big? Really? This function perfectly fits my old small 1280x1024 screen.
Split this function into more small functions just to avoid intention levels would make the readability way more worse.
- you have to permanently jump with your eyes between the main function and the sub functions to understand what the whole construction is doing.
- you have to transport all variables between the functions, who are very many in this case!
- i do not know many about the internal python operations, but i guess placing subroutine calls into the inner loops will have a big negative performance impact.
I will not split this function. Take it as it is, rewrite it by yourself or drop the whole pull request.
There was a problem hiding this comment.
Fair enough. I certainly do appreciate the PR, and don't mind cleaning it up myself.
but mainly my issue was just that python projects generally have a standard coding style (pep8), and nested indentations this deep are for the most part considered bad practice . calling it "too big" was probably not the best way to put it.
There was a problem hiding this comment.
I agree, too many intentions are bad style. But things are need to be done. Adding stuff just to avoid intentions levels will make the whole thing more complicated. Keep things as simple as possible.
|
Been thinking about this some more, I think it would be beneficial to move the logic for being able to access individual lines into the core pylivemaker API. Having programmatic API access to lines would obviously be pretty beneficial for pylm. Basically, the Then, people can do whatever they want w/those lines via the actual API. So, your CSV CLI command could be simplified to something like # open csv file, prepare for reading/writing csv
for scenario in lsb.text_scenarios():
lines = ScenarioLines(scenario)
for line in ScenarioLines(scenario):
if extract:
csv.append(line)
if patch:
line.replace(csv_line)
scenario.body = lines.make_body()
# save lsbThis would also open up a bunch of other possibilities, like being able to call some machine translation API directly from a python script and not even need the intermediate CSV file. You'd just do the same kind of thing as the above example, except def translate(line):
# do machine translate translate things, whether its google trans or whatever other api you want
for line in ScenarioLines(scenario):
translated = translate(line)
line.replace(translated)
# save lsbalthough given that machine translations need to be cleaned up this may not be a super realistic example? more likely you would still want to output your translated scenario, whether it's dumping to CSV, or dumping the translated scenario as a full LNS script, etc. It would also make |
|
I guess for now you can just leave this PR alone, and I'll start cherry-picking stuff to move the necessary logic into the API this weekend. then once that is done we can either update the CLI things in this PR to use the new API, or just do a new PR entirely. |
Fixes "Stuck Game" bug. I still wonder, how this bug passed the function test.
Seems pmrowla thinks about turning this pull request all over. So it makes little sense to do long bug fixing. |
|
The reason tests didn't catch it is that there are pretty much no tests. The only commands that are actually tested right now are In this case, we'd need to add tests that run |
| new_ch = TWdChar( | ||
| ch = ch, | ||
| decorator = last_ch.decorator, | ||
| text_speed = last_ch.text_speed, | ||
| link_name = last_ch.link_name, | ||
| link = last_ch.link, | ||
| condition = last_ch.condition, | ||
| ) |
There was a problem hiding this comment.
This command probably needs some documented warning that we ill break cases where a game uses styling tags (decorators) or links/conditions. (but links/conditions aren't as important here since I think they are really only used in history/scrollback).
Ex:
Say you have a text line that looks like
<STYLE ID=1>おはよう</STYLE><STYLE ID=2>ございます</STYLE>
where style 1 is the default, and style 2 is text colored red.
the string is extracted as
おはようございます
but when we translate and re-insert it, it would end up looking like
<STYLE ID=2>Good morning</STYLE>
where the entire line is now red, since the decorator condition is coming from the last character in the line.
It's not a huge deal, but basically any one using this command/API needs to aware that if their game uses tags for more advanced formatting, they will still need to clean things up themselves using the full script format.
and in the event a game is actually using links/conditions for embedding icons/images into regular message boxes, it may break their game (until they fix the translated script).
There was a problem hiding this comment.
I am not sure about this. The script does a line break on everything else than TWdChar.
As long links/conds/icons/images are not embedded into TWdChar they remain an the right places.
If they are embedded you are right.
There was a problem hiding this comment.
Yeah the issue is that links/conditionals/decorators are flags tied to a TWdChar. when a decorator (font styling) changes between characters, the only difference is that the next TWdChar will have a new .decorator value (corresponding to some font style ID). So there's no non-TWdChar object between the different characters.
if you look at what the script decompiler does, it has to watch all of those flags for whenever they change, and then close any previously opened style/link/etc tag, and then open a tag for the new style/link/etc.
There was a problem hiding this comment.
It's probably not a serious issue for a majority of LM games out there, but it's still something people should be aware of.
| for cmd_nr, cmd in enumerate(lsb.commands): | ||
| if cmd.type == CommandType.TextIns: | ||
| scenario = cmd.get('Text') | ||
| text_line = None | ||
| block_nr = 0 | ||
| new_body = [] | ||
| last_ch = None | ||
| cmd_patched = False | ||
| for w in scenario.body: |
There was a problem hiding this comment.
for future reference, there's an api function for iterating over scripts in an LSB, which could save a few levels of indentation here
There was a problem hiding this comment.
Thanks for hint to the API documentation. Stupid me have used the source until now...
Python is such a terrible language for analysing foreign code. The more i work with it the more i dislike python.
|
By "test" i mean translating an playing a game. I have done this, but played only to the first few lines, who where ok. Yesterday i played a bit further and the test game got stuck too. scenario.body should not be writeable from outside the class, since scenario.replace_body(new_body) seems required for proper work. |
yeah, you should not be messing with |
|
closed in favor of #37 |
lmlsb: added extracttext and inserttext subcommands for line-wise text operations.
lmgoogle: tool for automated translation, using google translate. This tool needs your additional work for proper build system integration.