Replies: 2 comments 1 reply
-
Hello The type of your config variable should not change its serialization, in the end it's the You can try an older version to see if it improves your problem. |
Beta Was this translation helpful? Give feedback.
-
Hey yeah the switch to v 3.6.4 fixed the issue thanks 😄 I also watched inside the Toml code real quick, at first im not anything near of understanding java completely, but can it be that the following code inside the writeNormal() Function from the Table Writer can "trigger" this issue? int nonSimpleValuesCount = tablesEntries.size() + tableArraysEntries.size();
int simpleValuesCount = config.size() - nonSimpleValuesCount;
if (simpleValuesCount > 0 && nonSimpleValuesCount > 0) {
writer.writeNewline(output);
} because in version 3.6.4 it simply calls: writer.writeNewline(output); But i only watched quickly for any difference in the code and this is the first that catched my attention. UPDATE - Compare v3.6.4 and v3.6.7:Ok after downloading the code for version 3.6.7 and comment out the first code block and adding the second code block back it seems to fix the issue This is the console Output of the writeToString Test from TomlWriterTest with the check:
And this without the check and reverted back to v3.6.4 approach
UPDATE 2 - Dumb/Useless Fix:After printing the nonSimpleValuesCount and the simpleValuesCount to the console this gets printed:
So my solution to the "non blank line" issue would be the following: int nonSimpleValuesCount = tablesEntries.size() + tableArraysEntries.size();
int simpleValuesCount = config.size() - nonSimpleValuesCount;
if (simpleValuesCount > 0 && nonSimpleValuesCount >= 0) {
writer.writeNewline(output);
} Simply allow that the nonSimpleValuesCount can also be 0 to print a new line, but i think this bigger than 0 check has a specific reason to be there and by the same time it makes the check basically useless because it gets the same result as by simply call the writeNewLine method. UPDATE 3 - Usefull Fix?Another Solution for my after work brain could be the following: for (UnmodifiableCommentedConfig.Entry entry : tablesEntries) {
// Writes the comment, if there is one
writer.writeComment(entry.getComment(), output);
// Writes the table declaration
configPath.add(entry.getKey());// path level ++
writeTableName(configPath, output, writer);
writer.writeNewline(output);
// Writes the table's content
writeNormal(entry.<UnmodifiableConfig>getValue(), configPath, output, writer);
configPath.remove(configPath.size() - 1);// path level --
writer.writeNewline(output); // After work brain solution
} This would only separate the tablesEntries without "splitting" the table arrays. Final Result and Pull Request #154When modifying the for loops inside the writeNormal Method like this: // Writes the tables:
for (UnmodifiableCommentedConfig.Entry entry : tablesEntries) {
// Writes the comment, if there is one
writer.writeComment(entry.getComment(), output);
// Writes the table declaration
configPath.add(entry.getKey());// path level ++
writeTableName(configPath, output, writer);
writer.writeNewline(output);
// Writes the table's content
writeNormal(entry.<UnmodifiableConfig>getValue(), configPath, output, writer);
configPath.remove(configPath.size() - 1);// path level --
writer.writeNewline(output); // separates Tables
}
// Writes the arrays of tables:
for (UnmodifiableCommentedConfig.Entry entry : tableArraysEntries) {
// Writes the comment, if there is one
writer.writeComment(entry.getComment(), output);
// Writes the tables
configPath.add(entry.getKey());// path level ++
List<Config> tableArray = entry.getValue();
for (UnmodifiableConfig table : tableArray) {
writeTableArrayName(configPath, output, writer);
writer.writeNewline(output);
writeNormal(table, configPath, output, writer);
}
configPath.remove(configPath.size() - 1);// path level --
writer.writeNewline(output); // separates each written ArrayList Table
}
writer.decreaseIndentLevel();// Indent-- The Console output from the writeToString Test looks like this:
Now the tableEntries and tableArrayEntries get separated when a new Entry or Array is written. |
Beta Was this translation helpful? Give feedback.
-
I'm confused about why on Neo-/Forge categories in the toml file get writen with a blank line between/above them, but when i use it on Fabric they get "crunshed" together. Is there a setting for the CommentedConfig or the TomlWriter i can set to achive this?
Neo-/Forge:
Fabric:
For all Modloaders i use my simple API to Build and create the Config File.
My current approach, i guess, is not the best but for now i cant imagine a better way:
Repo for the Config API
Writing every Config Entry to the Commented Config
Method for writing the Values to the CommentedConfig wich is initialized as inMemory():
Method for saving/generating the toml file:
I tried to "modify" the TomlWriter, by adding the writer.setNewLine() like below, but then every value has a blank line above.
When i only add one \n the result is the same, that the categories get crunshed together.
After checking how the ModConfig from Forge handles the saving, i also tried like Forge to cast my CommentedConfig to the CommentedFileConfig to use the .save() method but this produces an Exception that a CommentedConfig cannot be cast to CommentedFileConfig
Beta Was this translation helpful? Give feedback.
All reactions