Search in sources :

Example 36 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LorebookDeedsDatabaseNormalization method doIt.

private void doIt() {
    File loreDir = LotroCoreConfig.getInstance().getLoreDir();
    File in = new File(loreDir, "deeds.xml");
    DeedXMLParser parser = new DeedXMLParser();
    List<DeedDescription> deeds = parser.parseXML(in);
    for (DeedDescription deed : deeds) {
        normalizeDeed(deed);
    }
    File out = new File(loreDir, "deeds_by_name.xml");
    DeedsContainer.writeSortedDeeds(deeds, out);
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) File(java.io.File) DeedXMLParser(delta.games.lotro.lore.deeds.io.xml.DeedXMLParser)

Example 37 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LotroWikiDeedPageParser method parseDeeds.

/**
 * Parse the lotro wiki deed page for the given deed ID.
 * @param from Source page.
 * @param deedId Deed ID.
 * @return A deed or <code>null</code> if an error occurred.
 */
public List<DeedDescription> parseDeeds(File from, String deedId) {
    _currentFile = from;
    List<DeedDescription> deeds = null;
    try {
        FileInputStream inputStream = new FileInputStream(from);
        Source source = new Source(inputStream);
        String name = null;
        Element backElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "contentSub");
        if (backElement != null) {
            Element a = JerichoHtmlUtils.findElementByTagName(backElement, HTMLElementName.A);
            if (a != null) {
                name = a.getAttributeValue("title");
            }
        }
        Element deedSource = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TEXTAREA, "id", "wpTextbox1");
        if (deedSource != null) {
            Segment content = deedSource.getContent();
            String text = content.toString();
            deeds = buildDeeds(text, name);
        }
        if (deeds != null) {
            // Fixes
            for (DeedDescription deed : deeds) {
                handleFixes(deed);
            }
        }
    } catch (Exception e) {
        _logger.error("Cannot parse deed page [" + from + "]", e);
    }
    return deeds;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) Element(net.htmlparser.jericho.Element) FileInputStream(java.io.FileInputStream) Source(net.htmlparser.jericho.Source) Segment(net.htmlparser.jericho.Segment)

Example 38 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LotroWikiDeedPageParser method buildDeeds.

private List<DeedDescription> buildDeeds(String rawData, String deedName) {
    String[] lines = rawData.split("\n");
    // Checks
    if (lines == null)
        return null;
    List<DeedDescription> ret = new ArrayList<DeedDescription>();
    int startIndex = 0;
    while (true) {
        Integer deedLineIndex = findDeedStartLine(lines, startIndex);
        if (deedLineIndex == null) {
            break;
        }
        startIndex = deedLineIndex.intValue() + 1;
        DeedDescription deed = parseDeed(deedLineIndex.intValue(), lines, deedName);
        if (deed != null) {
            ret.add(deed);
        }
    }
    return ret;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) ArrayList(java.util.ArrayList)

Example 39 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class MainLotroWikiDeedsLoader method writeResultFile.

private void writeResultFile() {
    List<DeedDescription> deeds = new ArrayList<DeedDescription>();
    DeedXMLParser parser = new DeedXMLParser();
    File currentDir = new File(".");
    for (File deedFile : currentDir.listFiles()) {
        if (deedFile.getName().endsWith(".xml")) {
            List<DeedDescription> newDeeds = parser.parseXML(deedFile);
            deeds.addAll(newDeeds);
        }
    }
    // Resolve deed links
    new DeedLinksResolver(deeds).doIt();
    int nbDeeds = deeds.size();
    System.out.println("Found " + nbDeeds + " deeds.");
    new CheckItemRewardsInDeeds().doIt(deeds);
    new NormalizeDeedsText().doIt(deeds);
    new CheckDeedLinks().doIt(deeds);
    File out = new File("../lotro-companion/data/lore/deeds.xml");
    DeedsContainer.writeSortedDeeds(deeds, out);
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) CheckItemRewardsInDeeds(delta.games.lotro.tools.lore.deeds.checks.CheckItemRewardsInDeeds) ArrayList(java.util.ArrayList) NormalizeDeedsText(delta.games.lotro.tools.lore.deeds.checks.NormalizeDeedsText) File(java.io.File) DeedXMLParser(delta.games.lotro.lore.deeds.io.xml.DeedXMLParser) CheckDeedLinks(delta.games.lotro.tools.lore.deeds.checks.CheckDeedLinks)

Example 40 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LotroCompendiumDeedsLoader method resolveProxies.

private void resolveProxies(List<DeedDescription> deeds) {
    for (DeedProxy proxy : _proxies) {
        int idToSearch = proxy.getId();
        for (DeedDescription deed : deeds) {
            if (deed.getIdentifier() == idToSearch) {
                proxy.setDeed(deed);
                proxy.setKey(deed.getKey());
                proxy.setName(deed.getName());
                break;
            }
        }
        if (proxy.getDeed() == null) {
            System.out.println("Unresolved deed: id=" + idToSearch);
        }
    }
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) DeedProxy(delta.games.lotro.lore.deeds.DeedProxy)

Aggregations

DeedDescription (delta.games.lotro.lore.deeds.DeedDescription)45 DeedProxy (delta.games.lotro.lore.deeds.DeedProxy)13 ArrayList (java.util.ArrayList)13 File (java.io.File)6 Rewards (delta.games.lotro.common.Rewards)5 DeedsManager (delta.games.lotro.lore.deeds.DeedsManager)4 HashSet (java.util.HashSet)4 DeedXMLParser (delta.games.lotro.lore.deeds.io.xml.DeedXMLParser)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 List (java.util.List)3 Title (delta.games.lotro.common.Title)2 Virtue (delta.games.lotro.common.Virtue)2 VirtueId (delta.games.lotro.common.VirtueId)2 ObjectItem (delta.games.lotro.common.objects.ObjectItem)2 ObjectsSet (delta.games.lotro.common.objects.ObjectsSet)2 DeedXMLWriter (delta.games.lotro.lore.deeds.io.xml.DeedXMLWriter)2 BorderLayout (java.awt.BorderLayout)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2