JSFiddle - React, Tailwind, and code Playground

by Drath

JavaScript

function crafttable() {
    //Twigs + Tree Bark = Kindling
    //Leaves x4 = Leaf Bedroll
    //Large Rock x2 = Sharp Rock (1 is left over)
    //Sharp Rock + Large Rock = Smooth Rock
    //Smooth Rock x2 = Mortar and Pestle
    
    //Reset the craft window each time
    $('#craft').empty();
    
    cleaves = []; ctwigs = []; ctreebark = [];clargerock = []; csharprock = []; csmoothrock = [];
    
    for (var i in invitems) {
        switch (invitems[i].type) {
            case "leaves":
                cleaves.push(i);
                break;
            case "twigs":
                ctwigs.push(i);
                break;
            case "treebark":
                ctreebark.push(i);
                break;
            case "largerock":
                clargerock.push(i);
                break;
            case "sharprock":
                csharprock.push(i);
                break;
            case "smoothrock":
                csmoothrock.push(i);
                break;
        }
    }
    
    if (cleaves.length >= 4) {
        craftitem("leafbedroll");
    }
    if (ctwigs.length >= 1 && ctreebark.length >= 1) {
        craftitem("kindling");
    }
    if (clargerock.length >= 2) {
        craftitem("sharprock");    
    }
    if (clargerock.length >= 1 && csharprock.length >= 1) {
        craftitem("smoothrock");
    }
    if (csmoothrock.length >= 2) {
        craftitem("mortarandpestle");    
    }
    
}

function craftitem(item) {
    //This simply just shows the item to craft in my window/dialog system, with the ability to double click it (with function below)
    propername = items(item);
    $('#craft').append('<div id="craftaction" class="' + item + '"><img src="' + item + '.png" alt="' + propername[0] + '" title="' + propername[0] + '" /></div>');    
}

//Craftables
$('#craft div').live("dblclick",function(e){
    var craftclass = $(this).attr("class");
    //This is used to remove the items as needed, there will be some examples of the recipe not...