Skip to content

Commit

Permalink
cache: consolidate ID class printing and split ObjectID
Browse files Browse the repository at this point in the history
ObjectID hit the 32k field limit, so it needed to be split into multiple files to be updated.
  • Loading branch information
abextm committed Jun 16, 2018
1 parent 850167c commit 929d770
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 65 deletions.
22 changes: 3 additions & 19 deletions cache/src/main/java/net/runelite/cache/ItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -41,13 +40,12 @@
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)
{
Expand Down Expand Up @@ -97,32 +95,18 @@ public void export(File out) throws IOException

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"))
{
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("}");
}
}

Expand Down
22 changes: 3 additions & 19 deletions cache/src/main/java/net/runelite/cache/NpcManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

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;
Expand All @@ -38,13 +37,12 @@
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)
{
Expand Down Expand Up @@ -89,32 +87,18 @@ public void dump(File out) throws IOException

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"))
{
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("}");
}
}
}
39 changes: 12 additions & 27 deletions cache/src/main/java/net/runelite/cache/ObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -40,13 +39,12 @@
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)
{
Expand Down Expand Up @@ -96,36 +94,23 @@ public void dump(File out) throws IOException

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 changes: 72 additions & 0 deletions cache/src/main/java/net/runelite/cache/util/IDClass.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 929d770

Please sign in to comment.