-
Notifications
You must be signed in to change notification settings - Fork 17
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
Json support #134
base: develop/1.13
Are you sure you want to change the base?
Json support #134
Conversation
public class CustomItemJson implements JsonDeserializer<Item> { | ||
@Override | ||
public Item deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
return Item.getByNameOrId(json.getAsString()); |
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.
Shouldn't this be pulling from ForgeRegistries.ITEM?
@Override | ||
public NBTTagCompound deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
try { | ||
return JsonToNBT.getTagFromJson(json.toString()); |
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.
Does this allow for doing straight JSON objects as json? or just as escaped strings.
try { | ||
return JsonToNBT.getTagFromJson(json.toString()); | ||
} catch (NBTException e) { | ||
e.printStackTrace(); |
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.
Shouldn't you be rethrowing as a JsonParseException? Rather than just eating the error and puking into the log?
} | ||
|
||
/* | ||
Not needed for now |
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.
Then Remove it. Don't leave commented out code to just sit.
public ItemInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
JsonObject obj = json.getAsJsonObject(); | ||
|
||
Item item = context.deserialize(obj.get("item"), Item.class); |
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.
What if Item is null? Should probably have some sorta of better validation here.
registerDeserializer(NBTTagCompound.class, new CustomNBTJson()); | ||
} | ||
|
||
public static void registerDeserializer(Type type, JsonDeserializer deserializer) { |
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.
Shouldn't this be accessible through the api somehow?
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.
I am leaving this up to pup, as I am not sure how he wants the API to look like.
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.
I think this is probably fine given the JSON stuff will probably be for a larger version such as 2.0 which will allow for refactoring a bunch of stuff without worrying about breaking API things. Given a bunch of the stuff in LevelLockHandler should probably be moved from the base package to an API package. The only reason it is in LevelLockHandler to begin with is that it basically grew as I was fixing and then expanding on things making them more generic and supporting custom registrations.
|
||
public static void loadFromConfig(String[] configValues) { | ||
configLocks = configValues; | ||
} | ||
|
||
public static void setupLocks() { | ||
registerDefaultLockKeys(); | ||
if (configLocks != null) { |
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.
Wasn't this code for pulling from the config file?
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.
I looked into how we are doing it currently and the setupLocks method is called in FMLPostInitializationEvent
so we use it to register the lock keys, and then if the config has locks we register them. We previously loaded the strings here https://github.com/Coders-After-Dark/Reskillable/blob/develop/1.12.2/src/main/java/codersafterdark/reskillable/base/ConfigHandler.java#L53 Looking at the new code the locks are loaded from json here (which makes sense as all custom locks should have been registered by now from addons). I think this is fine however I think the linked line and LevelLockHandler#loadFromConfig
and private static String[] configLocks;
should probably be removed as they are no longer used. That or an automated converter should be made to port existing config files to the JSON format. I will mark through the review the lines that should be able to be deleted.
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.
ConfigHandler description of locks through the line LevelLockHandler.loadFromConfig(locks)
can also be removed or have a converter be created.
@@ -42,44 +43,27 @@ | |||
private static Map<Class<?>, List<Class<? extends LockKey>>> lockTypesMap = new HashMap<>(); | |||
private static Map<LockKey, Set<FuzzyLockKey>> fuzzyLockInfo = new HashMap<>(); | |||
private static String[] configLocks; |
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.
Can be removed, same with the DEFAULT_SKILL_LOCKS a few lines up but it is not letting me mark it.
registerLockKeyName("itemstack", ItemInfo.class); | ||
registerLockKeyName("mod", ModLockKey.class); | ||
registerLockKeyName("nbt", GenericNBTLockKey.class); | ||
} | ||
|
||
public static void loadFromConfig(String[] configValues) { |
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.
Can be removed
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.
Why should this be able to be removed?
This is needed for the json parser to deserialize the key name.
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.
The loadFromConfig(String[] configValues)
method. Github in its infinite wisdom decided to also display those lines of your code.
|
||
public static void init(File file) { | ||
generateFolder(file); | ||
mainConfig = new Configuration(new File(configDir.getPath(), "reskillable.cfg")); | ||
mainConfig.load(); | ||
loadData(); | ||
loadJSONLocks(); | ||
// loadJSONLocks(); |
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.
Can remove this line as it is being loaded from LevelLockHandler#setupLocks
and there is no reason to have this here just commented out.
No description provided.