I was researching different ways of creating and inventory and I stumbled upon https://twinery.org/forum/discussion/comment/21051/ . In the latter half user Disane , talks about creating something very similar to what I want. I'm not a total noob to twine and scripting, but i am pretty beginner and am trying to re-engineer it from the pieces. Using sugarcube2 and twine2. Sorry if this looks familiar, I locked my old question and tried to be more specific.
I have gotten to the part were I am planning on altering the equip macro to implement checks to see if a clothing slot is occupied before equipping a new item, but i have a initial stumbling block. Is it possible to have a clothing item have 2 or more "clothingType" properties, i.e. having overalls occupy both "shirts" and "pants", i can't figure out a good way to fit it in the structure.
most of the original macro's from disane and the madexiles disscusion
Macro.add('equipClothingJS',
{
handler : function()
{
var character = this.args[0];
var clothing = this.args[1];
if(!character.hasOwnProperty('inventory'))
{
this.error('the passed character has no inventory');
}
if(!clothing.hasOwnProperty('clothingType'))
{
this.error('clothing provided has no ClothingType defined');
}
var item = getItemById(character.inventory, clothing.id);
if (!item)
{
this.error("could not find item in player's inventory");
}
switch(clothing.clothingType)
{
case "hats":
character.clothing.hats.isEquipped = false;
character.clothing.hats = item
item.isEquipped = true;
break;
case "shirts":
character.clothing.shirts.isEquipped = false;
character.clothing.shirts = item;
item.isEquipped = true;
break;
case "pants":
character.clothing.pants.isEquipped = false;
character.clothing.pants = item;
item.isEquipped = true;
break;
case "shoes":
character.clothing.shoes.isEquipped = false;
character.clothing.shoes = item;
item.isEquipped = true;
break;
}
}
});
window.getItemById = function (container, searchId) {
if (!Array.isArray(container)) {
return null;
}
var searched_item = container.find(function (item) {
console.log("getItemById, item.id: " + item.id);
return item.id === searchId;
});
return searched_item;
};
Macro.add('listEquipped', {
handler : function ()
{
var container = this.args[0];
var $list = $(document.createDocumentFragment());
if (container.length === 0)
{
$list.text('nothing');
}
else
{
container.forEach(function (item)
{
if (item.isEquipped == true)
{
$list
.wiki('[[' + item.name + ']]')
.append('\u00A0\u00D7' + item.count)
.append('<br>');
}
}); // end of function() - end of foreach()
}
$list.appendTo(this.output);
}
});
Macro.add('listWorn', {
handler : function ()
{
var character = this.args[0];
var $list = $(document.createDocumentFragment());
var clothes
if (character.clothing.length === 0)
{
$list.text('nothing');
}
else
{
clothes = Object.values(character.clothing)
}
clothes.forEach(function (item)
{
if (item)
{
$list
.wiki('[[' + item.name + ']]')
.append('\u00A0\u00D7' + item.count)
.append('<br>');
}
})
$list.appendTo(this.output);
}
});
StoryInit
<<set $player = {
"money" : 0,
"inventory" : [],
"clothing" :
{
"hats" : [],
"pants" : [],
"shirt" : [],
"shoes" : []
}
}>>
<<initContainer player.inventory>>
<<set $BaseballHat =
{
"type" : "item",
"isEquipped" : false,
"clothingType" : "hats",
"id" : "baseball.hat",
"name" : "Baseball Hat",
"count" : 1,
"cost" : 50,
"description" : "A simple baseball hat inherited from your grandfather.",
"image" : "images/BaseballHat.jpg"
}>>
<<set $Tshirt =
{
"type" : "item",
"isEquipped" : 0,
"clothingType" : "shirts",
"id" : "tshirt",
"name" : "T Shirt",
"count" : 1,
"cost" : 15,
"description" : "Your Tshirt. Not the most elegant piece of clothing.",
"image" : "images/Tshirt.jpg"
}>>
<<set $OldTrousers =
{
"type" : "item",
"isEquipped" : true,
"clothingType" : "pants",
"id" : "trousers.clothing.old",
"name" : "Old Trousers",
"count" : 1,
"cost" : 5,
"description" : "Old trousers with full of holes. You feel embarassed wearing it publicly.",
"image" : "images/OldTrousers.jpg"
}>>
<<set $Sneakers =
{
"type" : "item",
"isEquipped" : false,
"clothingType" : "shoes",
"id" : "sneakers.shoes",
"name" : "Sneakers",
"count" : 1,
"cost" : 15,
"description" : "These sneakers are cheap and not too comfortable.",
"image" : "images/Sneakers.jpg"
}>>
<<set $overalls =
{
"type" : "item",
"isEquipped" : false,
"clothingType" : "pants",
"id" : "overall.clothing",
"name" : "overalls",
"count" : 1,
"cost" : 75,
"description" : "Nice overalls for you to wear.",
"image" : "images/trousers.jpg"
}>>
<<addToContainer $player.inventory $BaseballHat>>
etc...
2nd little question, the inventory system I am emulating points each inventory item to its own passage. Rather than creating a passage for each, how would i script it so that it just displays the "description" property and equip/unequip/back links.