Search in sources :

Example 1 with TextFileWriter

use of delta.common.utils.files.TextFileWriter in project lotro-tools by dmorcellet.

the class BuildItemsDbForIcons method buildDb.

/**
 * Build a LUA database using the given item IDs.
 * @param items Items database.
 * @param ids Identifiers to use.
 */
public void buildDb(HashMap<Integer, Item> items, List<Integer> ids) {
    StringBuilder sb = new StringBuilder();
    sb.append("_ITEMSDB =").append("\n");
    sb.append("{").append("\n");
    Collections.sort(ids);
    List<String> iconIds = new ArrayList<String>();
    for (Integer id : ids) {
        Item item = items.get(id);
        int iconId = NumericTools.parseInt(item.getProperty(ItemPropertyNames.ICON_ID), 0);
        String name = item.getName();
        if (name == null)
            name = "";
        name = name.replace("\n", "");
        name = name.replace("\r", "");
        String hexIconId = Integer.toHexString(iconId).toUpperCase();
        int backgroundIconId = NumericTools.parseInt(item.getProperty(ItemPropertyNames.BACKGROUND_ICON_ID), 0);
        String hexBackgroundIconId = Integer.toHexString(backgroundIconId).toUpperCase();
        sb.append("[").append(id).append("]={[1]=\"");
        sb.append(name).append("\";[2]=\"\";[3]=5;[4]=4;[5]=3;[6]=false;[7]=false;[8]=0x");
        sb.append(hexIconId).append(";[9]=0x").append(hexBackgroundIconId).append(";};\n");
        iconIds.add(iconId + "-" + backgroundIconId);
    }
    sb.append("};\n");
    // Write LUA file
    {
        TextFileWriter writer = new TextFileWriter(LUA_FILE);
        writer.start();
        writer.writeSomeText(sb.toString());
        writer.terminate();
    }
    // Write icon IDs file
    {
        TextFileWriter writer = new TextFileWriter(ICON_IDS_FILE);
        writer.start();
        for (String iconId : iconIds) {
            writer.writeNextLine(iconId);
        }
        writer.terminate();
    }
}
Also used : Item(delta.games.lotro.lore.items.Item) ArrayList(java.util.ArrayList) TextFileWriter(delta.common.utils.files.TextFileWriter)

Aggregations

TextFileWriter (delta.common.utils.files.TextFileWriter)1 Item (delta.games.lotro.lore.items.Item)1 ArrayList (java.util.ArrayList)1