@@ -669,7 +669,76 @@ void TextDataProcessor::importLevel(TranslationData &origin, const QString &path
669669 }
670670
671671 if (hasStrings)
672+ {
673+ // Try to merge comments from the previous copy
674+ if (origin.levels .contains (shortPath))
675+ {
676+ // Backup
677+ const auto old = origin.levels [shortPath];
678+
679+ // Copy back the title's note
680+ tr.title .note = old.title .note ;
681+
682+ // Import dialogues' notes
683+ for (int i = 0 ; i < old.dialogues .size (); ++i)
684+ {
685+ auto &di_n = tr.dialogues [i];
686+
687+ // Check if dialogue equal:
688+ if (i >= tr.dialogues .size ())
689+ continue ; // Not ours
690+
691+ auto &di_o = old.dialogues [i];
692+
693+ if (di_o.messages .size () != di_n.messages .size ())
694+ continue ; // Also not ours
695+
696+ bool equal = true ;
697+ // Compare messages
698+ for (int m = 0 ; m < di_o.messages .size (); ++m)
699+ {
700+ if (di_o.messages [m].type != di_n.messages [m].type ||
701+ di_o.messages [m].item_index != di_n.messages [m].item_index )
702+ {
703+ equal = false ;
704+ break ;
705+ }
706+ }
707+
708+ if (!equal)
709+ continue ; // Also not ours
710+
711+ // And now, it's really ours, so, import the note
712+ di_n.note = di_o.note ;
713+ }
714+
715+ // Import NPC source notes
716+ for (auto &no : old.npc )
717+ {
718+ for (auto &nn : tr.npc )
719+ {
720+ if (no.npc_index != nn.npc_index || no.npc_id != nn.npc_id )
721+ continue ; // Not ours
722+
723+ nn.talk .note = no.talk .note ;
724+ }
725+ }
726+
727+ // Import NPC source notes
728+ for (auto &no : old.events )
729+ {
730+ for (auto &nn : tr.events )
731+ {
732+ if (no.event_index != nn.event_index )
733+ continue ; // Not ours
734+
735+ nn.message .note = no.message .note ;
736+ }
737+ }
738+ }
739+
672740 origin.levels .insert (shortPath, tr);
741+ }
673742 else
674743 {
675744 QFileInfo f (path);
@@ -724,7 +793,35 @@ void TextDataProcessor::importWorld(TranslationData &origin, const QString &path
724793 }
725794
726795 if (hasStrings)
796+ {
797+ // Try to merge comments from the previous copy
798+ if (origin.worlds .contains (shortPath))
799+ {
800+ // Backup
801+ const auto old = origin.worlds [shortPath];
802+
803+ // Copy back the title's note
804+ tr.title .note = old.title .note ;
805+ // Copy back the credits' note
806+ tr.credits .note = old.credits .note ;
807+
808+ // Import NPC source notes
809+ for (auto &no : old.level_titles )
810+ {
811+ for (auto &nn : tr.level_titles )
812+ {
813+ if (no.level_index != nn.level_index || no.filename != nn.filename )
814+ continue ; // Not ours
815+
816+ nn.title .note = no.title .note ;
817+ }
818+ }
819+
820+ origin.worlds .insert (shortPath, tr);
821+ }
822+
727823 origin.worlds .insert (shortPath, tr);
824+ }
728825 else
729826 {
730827 QFileInfo f (path);
@@ -906,7 +1003,30 @@ void TextDataProcessor::importScript(TranslationData &origin, const QString &pat
9061003#undef PARSE_FMT_STR_2
9071004
9081005 if (hasStrings)
1006+ {
1007+ // Try to merge comments from the previous copy
1008+ if (origin.scripts .contains (shortPath))
1009+ {
1010+ // Backup
1011+ const auto old = origin.scripts [shortPath];
1012+
1013+ // Import NPC source notes
1014+ for (auto &no : old.lines )
1015+ {
1016+ for (auto &nn : tr.lines )
1017+ {
1018+ if (no.line != nn.line || no.source != nn.source )
1019+ continue ; // Not ours
1020+
1021+ nn.translation .note = no.translation .note ;
1022+ }
1023+ }
1024+
1025+ origin.scripts .insert (shortPath, tr);
1026+ }
1027+
9091028 origin.scripts .insert (shortPath, tr);
1029+ }
9101030}
9111031
9121032void TextDataProcessor::recountStats (TranslateProject &proj, TranslationData &tr, bool isOrigin)
0 commit comments