JSFiddle - React, Tailwind, and code Playground
by Drath
HTML
[14:53] <@jday> var itemTypes = [["Hat", 5, 4, 3, [1, 2, 3]], ["Cigar", 9, 9, 9, [9, 9, 9]], ["Dried Squid", 2, -1, 3, [4, 3, 2]];
[14:54] <@jday> (I left out the closing ].)
[14:54] <@jday> function newItem(id, x, y) {return {type: itemTypes[id], x: x, y: y}};
JavaScript
items = [];
item = function(id, x, y, i) {
i = i || {};
i.id = id;
i.x = x;
i.y = y;
//have tons more props here than just x, y - other things that are unique to each item
return i;
}
//Look-up for things that are not unique to each item
function iteminfo(id) {
switch(id) {
case 1:
return ["This is a really long description of the item", "Item Name", [3, 4, 33, 11], "Other stuff"];
break;
case 2:
return ["This is a really long description of the item.", "Item Name 2", [44, 4, 0, 0], "Other stuff"];
break;
}
}
//Simulating game stuff below
//This is how new items are created, thousands may be pushed in this fashion
items.push(item(1, 33, 44));
items.push(item(2, 77, 21));
//Showing the description?
var iinfo = iteminfo(1);
alert(iinfo[0]);