Search in sources :

Example 1 with Ingredient

use of delta.games.lotro.lore.crafting.recipes.Ingredient in project lotro-tools by dmorcellet.

the class RecipePageParser method parseIngredient.

private Ingredient parseIngredient(Element ingredientRow, boolean optional) {
    Ingredient ingredient = new Ingredient();
    ingredient.setOptional(optional);
    ItemReference itemRef = new ItemReference();
    ingredient.setItem(itemRef);
    Element ingredientIcon = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingicon");
    if (ingredientIcon != null) {
        Element img = JerichoHtmlUtils.findElementByTagName(ingredientIcon, HTMLElementName.IMG);
        if (img != null) {
            String itemIcon = img.getAttributeValue("src");
            itemRef.setIcon(itemIcon);
        // System.out.println("Icon: "+itemIcon);
        }
    }
    Element ingredientQuantity = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingquan");
    if (ingredientQuantity != null) {
        String quantityStr = CharacterReference.decodeCollapseWhiteSpace(ingredientQuantity.getContent());
        int quantity = parseQuantityString(quantityStr);
        ingredient.setQuantity(quantity);
    // System.out.println("Quantity: "+quantity);
    }
    Element ingredientName = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingname");
    if (ingredientName != null) {
        Element a = JerichoHtmlUtils.findElementByTagName(ingredientName, HTMLElementName.A);
        String itemURL = a.getAttributeValue("href");
        String itemId = extractItemIdentifier(itemURL);
        itemRef.setItemKey(itemId);
        String itemName = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
        itemRef.setName(itemName);
    }
    return ingredient;
}
Also used : ItemReference(delta.games.lotro.lore.crafting.recipes.ItemReference) Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) Element(net.htmlparser.jericho.Element)

Example 2 with Ingredient

use of delta.games.lotro.lore.crafting.recipes.Ingredient in project lotro-tools by dmorcellet.

the class RecipePageParser method parseIngredients.

private List<Ingredient> parseIngredients(Element ingredientsSection) {
    /*
<tr class="ingredientrow">
<td class="ingicon"><a href="/wiki/Item:Ancient_Steel_Ingot"><img class="icon" rel="" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/item/component/it_craft_ancient_steel_ingot.png"></img></a></td>
<td class="ingquan">x4 (optional)</td>
<td class="ingname"><a href="/wiki/Item:Ancient_Steel_Ingot"></a></td>
</tr>
     */
    List<Ingredient> ingredients = new ArrayList<Ingredient>();
    List<Element> ingredientRows = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(ingredientsSection, HTMLElementName.TR, "class", "ingredientrow");
    if ((ingredientRows != null) && (ingredientRows.size() > 0)) {
        for (Element ingredientRow : ingredientRows) {
            Ingredient ingredient = parseIngredient(ingredientRow, false);
            ingredients.add(ingredient);
        }
    }
    List<Element> optionalIngredientRows = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(ingredientsSection, HTMLElementName.TR, "class", "ingredientrow optional");
    if ((optionalIngredientRows != null) && (optionalIngredientRows.size() > 0)) {
        for (Element optionalIngredientRow : optionalIngredientRows) {
            Ingredient ingredient = parseIngredient(optionalIngredientRow, true);
            ingredients.add(ingredient);
        }
    }
    return ingredients;
}
Also used : Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList)

Example 3 with Ingredient

use of delta.games.lotro.lore.crafting.recipes.Ingredient in project lotro-tools by dmorcellet.

the class ResolveItemLinksInRecipes method handleRecipes.

private void handleRecipes(ItemsResolver resolver) {
    // Load recipes
    RecipesManager rMgr = RecipesManager.getInstance();
    File recipesDir = LotroCoreConfig.getInstance().getRecipesDir();
    FileFilter fileFilter = new ExtensionPredicate("xml");
    File[] recipeFiles = recipesDir.listFiles(fileFilter);
    if (recipeFiles != null) {
        Set<String> missingKeys = new HashSet<String>();
        for (File recipeFile : recipeFiles) {
            String idStr = recipeFile.getName();
            idStr = idStr.substring(0, idStr.length() - 4);
            int id = NumericTools.parseInt(idStr, -1);
            if (id != -1) {
                Recipe recipe = rMgr.getRecipe(Integer.valueOf(id));
                List<Ingredient> ingredients = recipe.getIngredients();
                for (Ingredient ingredient : ingredients) {
                    ItemReference itemRef = ingredient.getItem();
                    handleItemRef(resolver, missingKeys, itemRef);
                }
                /*
          ItemReference scroll=recipe.getRecipeScroll();
          if (scroll!=null)
          {
            handleItemRef(ids,missingKeys,scroll);
          }
          */
                List<RecipeVersion> versions = recipe.getVersions();
                for (RecipeVersion version : versions) {
                    CraftingResult regular = version.getRegular();
                    if (regular != null) {
                        ItemReference ref = regular.getItem();
                        handleItemRef(resolver, missingKeys, ref);
                    }
                    CraftingResult critical = version.getCritical();
                    if (critical != null) {
                        ItemReference ref = critical.getItem();
                        handleItemRef(resolver, missingKeys, ref);
                    }
                }
            }
        }
        List<String> sortedKeys = new ArrayList<String>(missingKeys);
        Collections.sort(sortedKeys);
        for (String missingKey : sortedKeys) {
            System.out.println("Missing : " + missingKey);
        }
        System.out.println("Missing : " + sortedKeys.size());
    }
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) ArrayList(java.util.ArrayList) ExtensionPredicate(delta.common.utils.files.filter.ExtensionPredicate) RecipesManager(delta.games.lotro.lore.crafting.recipes.RecipesManager) ItemReference(delta.games.lotro.lore.crafting.recipes.ItemReference) Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) RecipeVersion(delta.games.lotro.lore.crafting.recipes.RecipeVersion) FileFilter(java.io.FileFilter) File(java.io.File) CraftingResult(delta.games.lotro.lore.crafting.recipes.CraftingResult) HashSet(java.util.HashSet)

Example 4 with Ingredient

use of delta.games.lotro.lore.crafting.recipes.Ingredient in project lotro-tools by dmorcellet.

the class RecipePageParser method parseRecipeSection.

private Recipe parseRecipeSection(Element recipeSection) {
    Recipe ret = null;
    try {
        _recipe = new Recipe();
        // Element mainIconElement=JerichoHtmlUtils.findElementByTagNameAndAttributeValue(recipeSection,HTMLElementName.DIV,"class","mainicon");
        List<Element> officialSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(recipeSection, HTMLElementName.DIV, "class", "officialsection");
        // 1 - summary
        // 2 - ingredients
        // 3 - results
        int nbSections = officialSections.size();
        if (nbSections != 3) {
            System.out.println("Warning: found " + nbSections + " sections!");
        }
        Element summarySection = officialSections.get(0);
        parseRecipeSummary(summarySection);
        // System.out.println("Ingredients:");
        Element ingredientsSection = officialSections.get(1);
        List<Ingredient> ingredients = parseIngredients(ingredientsSection);
        _recipe.setIngredients(ingredients);
        // System.out.println("Results:");
        Element resultsSection = officialSections.get(2);
        List<RecipeVersion> results = parseResults(resultsSection);
        _recipe.setVersions(results);
        ret = _recipe;
        _recipe = null;
    } catch (Exception e) {
        ret = null;
        _logger.error("Recipe [" + _key + "]. Cannot parse recipe section!", e);
    }
    return ret;
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) Element(net.htmlparser.jericho.Element) RecipeVersion(delta.games.lotro.lore.crafting.recipes.RecipeVersion)

Aggregations

Ingredient (delta.games.lotro.lore.crafting.recipes.Ingredient)4 Element (net.htmlparser.jericho.Element)3 ItemReference (delta.games.lotro.lore.crafting.recipes.ItemReference)2 Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)2 RecipeVersion (delta.games.lotro.lore.crafting.recipes.RecipeVersion)2 ArrayList (java.util.ArrayList)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 CraftingResult (delta.games.lotro.lore.crafting.recipes.CraftingResult)1 RecipesManager (delta.games.lotro.lore.crafting.recipes.RecipesManager)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 HashSet (java.util.HashSet)1