public static ValMap ToMap(StardewValley.Object obj) { var result = new ValMap(); string type = obj.Type; if (type == "asdf") { type = obj.Name; // because, c'mon. } result.map[_type] = new ValString(type); // ToDo: limit the following to ones that really apply for this type. result.map[_name] = new ValString(obj.Name); result["displayName"] = new ValString(obj.DisplayName); result["health"] = new ValNumber(obj.getHealth()); if (obj.isLamp.Get()) { result["isOn"] = ValNumber.Truth(obj.IsOn); } result["quality"] = new ValNumber(obj.Quality); result.map[_harvestable] = ValNumber.Truth(obj.readyForHarvest.Get()); result["minutesTillReady"] = new ValNumber(obj.MinutesUntilReady); result["value"] = new ValNumber(obj.sellToStorePrice()); result["description"] = new ValString(obj.getDescription()); return(result); }
//inverse of pack. we take a vanilla object and create a new SimpleItem from it. public static SimpleObject Unpack(StardewValley.Object o) { SimpleObject i = new SimpleObject(); i.showNextIndex = o.showNextIndex; i.minutesUntilReady = o.minutesUntilReady; i.flipped = o.flipped; i.hasBeenPickedUpByFarmer = o.hasBeenPickedUpByFarmer; i.isRecipe = o.isRecipe; i.isLamp = o.isLamp; i.heldObject = o.heldObject; //we will need to revisit this if we make machines that can accept SimpleItems i.boundingBox = o.boundingBox; i.preservedParentSheetIndex = o.preservedParentSheetIndex; i.lightSource = o.lightSource; i.shakeTimer = o.shakeTimer; i.internalSound = o.internalSound; i.preserve = o.preserve; i.honeyType = o.honeyType; i.displayName = o.displayName; i.readyForHarvest = o.readyForHarvest; i.scale = o.scale; i.setIndoors = o.setIndoors; i.parentSheetIndex = o.parentSheetIndex; i.bigCraftable = o.bigCraftable; i.tileLocation = o.tileLocation; i.setOutdoors = o.setOutdoors; i.name = o.name; i.type = o.type; i.canBeSetDown = o.canBeSetDown; i.canBeGrabbed = o.canBeGrabbed; i.isHoedirt = o.isHoedirt; i.owner = o.owner; i.questItem = o.questItem; i.isOn = o.isOn; i.fragility = o.fragility; i.price = o.price; i.edibility = o.edibility; i.isSpawnedObject = o.isSpawnedObject; i.stack = o.stack; i.quality = o.quality; i.setHealth(o.getHealth()); i.category = o.category; i.specialVariable = o.specialVariable; i.specialItem = o.specialItem; i.hasBeenInInventory = o.hasBeenInInventory; //override the substitute's id i.parentSheetIndex = SDVX3Mod.itemID; //unpack our secret sauce string[] meta = o.name.Split(new string[] { "::" }, StringSplitOptions.None); i.name = meta[0]; i.ModItemId = meta[1].Split('.')[2]; if (meta.Length > 2) { i.ParseMetadata(meta[2]); } ; i.bigCraftable = false; //not supported //return the result SDVX3Mod.instance.Monitor.Log("Unpacked a SimpleObject: " + i.ModItemId); return(i); }