cache: consolidate ID class printing and split ObjectID
ObjectID hit the 32k field limit, so it needed to be split into multiple files to be updated.
This commit is contained in:
@@ -26,7 +26,6 @@ package net.runelite.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -41,13 +40,12 @@ import net.runelite.cache.fs.FSFile;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.util.Namer;
|
||||
import net.runelite.cache.util.IDClass;
|
||||
|
||||
public class ItemManager implements ItemProvider
|
||||
{
|
||||
private final Store store;
|
||||
private final Map<Integer, ItemDefinition> items = new HashMap<>();
|
||||
private final Namer namer = new Namer();
|
||||
|
||||
public ItemManager(Store store)
|
||||
{
|
||||
@@ -97,16 +95,9 @@ public class ItemManager implements ItemProvider
|
||||
|
||||
public void java(File java) throws IOException
|
||||
{
|
||||
System.setProperty("line.separator", "\n");
|
||||
java.mkdirs();
|
||||
File targ = new File(java, "ItemID.java");
|
||||
try (PrintWriter fw = new PrintWriter(targ))
|
||||
try (IDClass ids = IDClass.create(java, "ItemID"))
|
||||
{
|
||||
fw.println("/* This file is automatically generated. Do not edit. */");
|
||||
fw.println("package net.runelite.api;");
|
||||
fw.println("");
|
||||
fw.println("public final class ItemID");
|
||||
fw.println("{");
|
||||
for (ItemDefinition def : items.values())
|
||||
{
|
||||
if (def.name.equalsIgnoreCase("NULL"))
|
||||
@@ -114,15 +105,8 @@ public class ItemManager implements ItemProvider
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = namer.name(def.name, def.id);
|
||||
if (name == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fw.println(" public static final int " + name + " = " + def.id + ";");
|
||||
ids.add(def.name, def.id);
|
||||
}
|
||||
fw.println("}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.cache.definitions.NpcDefinition;
|
||||
@@ -38,13 +37,12 @@ import net.runelite.cache.fs.FSFile;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.util.Namer;
|
||||
import net.runelite.cache.util.IDClass;
|
||||
|
||||
public class NpcManager
|
||||
{
|
||||
private final Store store;
|
||||
private final List<NpcDefinition> npcs = new ArrayList<>();
|
||||
private final Namer namer = new Namer();
|
||||
|
||||
public NpcManager(Store store)
|
||||
{
|
||||
@@ -89,16 +87,9 @@ public class NpcManager
|
||||
|
||||
public void java(File java) throws IOException
|
||||
{
|
||||
System.setProperty("line.separator", "\n");
|
||||
java.mkdirs();
|
||||
File targ = new File(java, "NpcID.java");
|
||||
try (PrintWriter fw = new PrintWriter(targ))
|
||||
try (IDClass ids = IDClass.create(java, "NpcID"))
|
||||
{
|
||||
fw.println("/* This file is automatically generated. Do not edit. */");
|
||||
fw.println("package net.runelite.api;");
|
||||
fw.println("");
|
||||
fw.println("public final class NpcID");
|
||||
fw.println("{");
|
||||
for (NpcDefinition def : npcs)
|
||||
{
|
||||
if (def.name.equalsIgnoreCase("NULL"))
|
||||
@@ -106,15 +97,8 @@ public class NpcManager
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = namer.name(def.name, def.id);
|
||||
if (name == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fw.println(" public static final int " + name + " = " + def.id + ";");
|
||||
ids.add(def.name, def.id);
|
||||
}
|
||||
fw.println("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -40,13 +39,12 @@ import net.runelite.cache.fs.FSFile;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.util.Namer;
|
||||
import net.runelite.cache.util.IDClass;
|
||||
|
||||
public class ObjectManager
|
||||
{
|
||||
private final Store store;
|
||||
private final Map<Integer, ObjectDefinition> objects = new HashMap<>();
|
||||
private final Namer namer = new Namer();
|
||||
|
||||
public ObjectManager(Store store)
|
||||
{
|
||||
@@ -96,36 +94,23 @@ public class ObjectManager
|
||||
|
||||
public void java(File java) throws IOException
|
||||
{
|
||||
System.setProperty("line.separator", "\n");
|
||||
java.mkdirs();
|
||||
File targ = new File(java, "ObjectID.java");
|
||||
try (PrintWriter fw = new PrintWriter(targ))
|
||||
try (IDClass ids = IDClass.create(java, "ObjectID"))
|
||||
{
|
||||
fw.println("/* This file is automatically generated. Do not edit. */");
|
||||
fw.println("package net.runelite.api;");
|
||||
fw.println("");
|
||||
fw.println("public final class ObjectID");
|
||||
fw.println("{");
|
||||
for (ObjectDefinition def : objects.values())
|
||||
try (IDClass nulls = IDClass.create(java, "NullObjectID"))
|
||||
{
|
||||
String name;
|
||||
if (def.getName().equalsIgnoreCase("NULL"))
|
||||
for (ObjectDefinition def : objects.values())
|
||||
{
|
||||
name = namer.name("NULL", def.getId());
|
||||
if ("null".equals(def.getName()))
|
||||
{
|
||||
nulls.add(def.getName(), def.getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
ids.add(def.getName(), def.getId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = namer.name(def.getName(), def.getId());
|
||||
}
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fw.println(" public static final int " + name + " = " + def.getId() + ";");
|
||||
}
|
||||
fw.println("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
cache/src/main/java/net/runelite/cache/util/IDClass.java
vendored
Normal file
72
cache/src/main/java/net/runelite/cache/util/IDClass.java
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class IDClass extends PrintWriter
|
||||
{
|
||||
private final Namer namer = new Namer();
|
||||
|
||||
private IDClass(File file) throws FileNotFoundException
|
||||
{
|
||||
super(file);
|
||||
}
|
||||
|
||||
public static IDClass create(File directory, String name) throws IOException
|
||||
{
|
||||
System.setProperty("line.separator", "\n");
|
||||
IDClass c = new IDClass(new File(directory, name + ".java"));
|
||||
c.println("/* This file is automatically generated. Do not edit. */");
|
||||
c.println("package net.runelite.api;");
|
||||
c.println("");
|
||||
c.print("public final class ");
|
||||
c.println(name);
|
||||
c.println("{");
|
||||
return c;
|
||||
}
|
||||
|
||||
public void add(String name, int id)
|
||||
{
|
||||
String javaName = namer.name(name, id);
|
||||
if (javaName == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
println(" public static final int " + javaName + " = " + id + ";");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
println("\t/* This file is automatically generated. Do not edit. */");
|
||||
println("}");
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user