Skip to content

Config Rewrite#183

Merged
Unknown025 merged 34 commits intoUltimatefrom
wip_config_rewrite
Jul 7, 2023
Merged

Config Rewrite#183
Unknown025 merged 34 commits intoUltimatefrom
wip_config_rewrite

Conversation

@GoldSloth
Copy link
Copy Markdown
Collaborator

Description of changes

Completely replace the config loading system with a reworked system. Instead of reading each line of a file with a long list of if/else statements, all lines are instead read into a ConfigMap, then each type file uses methods from ConfigUtils to parse int/float/bool, read a string or retrieve splits.

Each config read using logic that can throw exceptions should be individually wrapped by a try/catch, there are only a few errors which should cause parsing to fail. Furthermore, a standardized logging system has been introduced with FlansMod.logPackError which can print filename, packname, shortname, a message, the split that caused an error and the exception. This should help pack makers easily see issues in their packs.

There's also a small amount of validation introduced, which should be expanded in future to correct common issues such as missing wheels e.t.c.

Intended usage in Content Packs/Users of the mod

The underlying config reading systems should not be of interest, however improved logging should be of use to pack makers.

Compatibility

I do not anticipate this update will occur configs to be interpreted differently, however there are likely to be issues due to things we've missed. A long list of changed behavior will be amended when this is manually merged.

Where a config which is meant to be set once (like Driver -10 4 59) is specified multiple times, the FIRST usage will be used instead of the LAST.

Wheel positions will be read in a more "generous" manner if they're not properly specified.

Other

WillyJ started this project a few months ago to tidy up the code, implemented the bulk of ConfigMap and ConfigUtils and started to convert the existing type files. However, he soon disappeared and it was left to me to finish conversion and implement error handling and logging. Hence, this took up a lot more of my time than I anticipated.

Jordan and others added 30 commits January 23, 2023 21:26
Finished DriveableType, but not yet tested.
Next step, testing.
…dling of passengers + wheels.

Discovered ShootableType needs a rework.
# Conflicts:
#	src/main/java/com/flansmod/client/model/RenderGun.java
#	src/main/java/com/flansmod/common/FlansMod.java
#	src/main/java/com/flansmod/common/guns/BulletType.java
#	src/main/java/com/flansmod/common/guns/GunType.java
#	src/main/java/com/flansmod/common/guns/ShootableType.java
#	src/main/java/com/flansmod/common/paintjob/PaintableType.java
@GoldSloth GoldSloth requested a review from Unknown025 July 2, 2023 12:10
Copy link
Copy Markdown
Owner

@Unknown025 Unknown025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, nice to see a modernization of config handling. Only major concerns would be case sensitivity (which seemed to be hit or miss in the old implementation, but crucial for old packs to work the same way) and referencing model classes in server side contexts.

if (FlansMod.printStackTrace) {
ex.printStackTrace();
}
FlansMod.logPackError(file.name, packName, shortName, "Erorred while reading Driver/Pilot", null, ex);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably say "Errored" instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that's correct :)

Comment thread src/main/java/com/flansmod/common/driveables/DriveableType.java
onRadar = ConfigUtils.configBool(config, "OnRadar", onRadar);


splits = ConfigUtils.getSplitsFromKey(config, new String[] { "AddParticle", "AddEmitter" });
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still case insensitive? The original code used equalsIgnoreCase.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/main/java/com/flansmod/common/driveables/VehicleType.java Outdated
protected void read(ConfigMap config, TypeFile file) {
super.read(config, file);
try {
model = FlansMod.proxy.loadModel(modelString, shortName, ModelAAGun.class);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might fail on the server side. Even though the server side proxy won't crash, referencing ModelAAGun.class might be enough on its own.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, it was previously if'ed out with Side.Client before I think. I'll test it out.

String typeString = ConfigUtils.configString(config, "AttachmentType", type.toString());
type = EnumAttachmentType.get(typeString);

model = FlansMod.proxy.loadModel(modelString, shortName, ModelAttachment.class);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, referencing the model class server-side might cause an exception and not load the remainder of the config file.

deployableModelString = ConfigUtils.configString(configMap, "DeployedModel", null);
deployableModel = FlansMod.proxy.loadModel(deployableModelString, shortName, ModelMG.class);

model = FlansMod.proxy.loadModel(modelString, shortName, ModelGun.class);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern here.

@GoldSloth
Copy link
Copy Markdown
Collaborator Author

Looks good overall, nice to see a modernization of config handling. Only major concerns would be case sensitivity (which seemed to be hit or miss in the old implementation, but crucial for old packs to work the same way) and referencing model classes in server side contexts.

Iirc this is now equivelant to equalsIgnoreCase for config keywords which shouldn't cause any issues afaik

@GoldSloth
Copy link
Copy Markdown
Collaborator Author

I think I've resolved all issues there, I also tested on a local server which I forgot to do before - could you give it a quick check @Unknown025 please?

Copy link
Copy Markdown
Owner

@Unknown025 Unknown025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project does not compile due to unresolved references.

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import org.classpath.icedtea.Config;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for? I'm unable to compile the project due to this reference here. It's present in GunType, ShootableType, PartType, and ToolType.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh... Rip I missed that sorry. I think that's something IntelliJ inserts when you type in Config instead of ConfigMap. That can definitely be removed.

Copy link
Copy Markdown
Owner

@Unknown025 Unknown025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good now.

@Unknown025 Unknown025 merged commit 1df74bb into Ultimate Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants