private /*static*/ DmiIcon tryGetInventoryIcon(/*DmiIconData dmi, string[] invSheetPaths, string icon = ""*/) { //determining invIcon for (int i = 0; i < invSheetPaths.Length; i++) { var iconPath = DmiIconData.getIconPath(invSheetPaths[i]); //add extension junk if (!iconPath.Equals("") && DmiIconData.Data.ContainsKey(iconPath) && icon.Equals("")) { // Debug.Log(name + ": iSheet = dmi.DataHier[" + iconPath +"] = " + dmi.Data[iconPath]); return(DmiIconData.Data[iconPath]); } } if (!icon.Equals("")) { // Debug.Log(name + ": iSheet = dmi.DataIcon["+icon+"] = "+iSheet); return(DmiIconData.Data[icon]); } //pretty bad choice, should use this only as last resort as it's usually pretty inaccurate var invIcon = dmi.getIconByState(icon_state); if (invIcon != null) { Debug.LogWarningFormat("{0} is doing bad dmi.getIconByState({1}) = {2}", name, icon_state, invIcon.icon); return(invIcon); } // Debug.LogError(); return(new DmiIcon()); }
private static void EnsureInit() { if (dm == null) { dm = Resources.Load("DmObjectData") as DmObjectData; } if (dmi == null) { dmi = Resources.Load("DmiIconData") as DmiIconData; } }
/// <summary> /// Tries to get the inventory icon for the unicloth with the specified hier string /// </summary> /// <param name="hier">hier to get the icon for</param> /// <param name="invSheetPaths">Pass the cached value here to speed up the method. /// Sheet paths to get it from, if null will be looked up from the hier.</param> /// <param name="icon">Pass a value here to speed up the method. /// icon to get, if null will be looked up from the hier.</param> /// <param name="icon_state">Pass a value here to speed up the method. /// icon_state of the icon to get, if null will be looked up from the hier.</param> /// <returns>DmiIcon for the specified hier, empty DmiIcon if unable</returns> public static DmiIcon GetInventoryIcon(string hier, string[] invSheetPaths = null, string icon = null, string icon_state = null) { EnsureInit(); var objectAttrs = icon == null || icon_state == null?dm.getObject(hier) : null; if (icon == null) { objectAttrs.TryGetValue("icon", out icon); icon = icon ?? ""; } if (icon_state == null) { objectAttrs.TryGetValue("icon_state", out icon_state); icon_state = icon_state ?? ""; } invSheetPaths = invSheetPaths ?? GetItemClothSheetHier(GetItemType(hier)); //determining invIcon for (int i = 0; i < invSheetPaths.Length; i++) { string iconPath = DmiIconData.getIconPath(invSheetPaths[i]); //add extension junk if (!iconPath.Equals("") && DmiIconData.Data.ContainsKey(iconPath) && icon.Equals("")) { // Logger.Log(name + ": iSheet = dmi.DataHier[" + iconPath +"] = " + dmi.Data[iconPath]); return(DmiIconData.Data[iconPath]); } } if (!icon.Equals("")) { // Logger.Log(name + ": iSheet = dmi.DataIcon["+icon+"] = "+iSheet); return(DmiIconData.Data[icon]); } //pretty bad choice, should use this only as last resort as it's usually pretty inaccurate DmiIcon invIcon = dmi.getIconByState(icon_state); if (invIcon != null) { Logger.Log($"UniItemUtils is doing bad dmi.getIconByState({icon_state}) = {invIcon.icon}", Category.DmMetadata); return(invIcon); } // Logger.LogError(); return(new DmiIcon()); }
// Enum test: // // private void OnEnable() // { // if (hierarchy == null || hierarchy.Equals("")) // { // hierarchy = cloth.GetDescription(); // } // ConstructItem(hierarchy); // } public void ConstructItem(string hierString) { //randomize clothing! uncomment only if you spawn without any clothes on! // randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { // Debug.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { // Debug.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); //custom inventory(?) icon, if present icon = tryGetAttr("icon"); // states icon_state = tryGetAttr("icon_state"); item_color = tryGetAttr("item_color"); //also a state item_state = tryGetAttr("item_state"); var states = new[] { icon_state, item_color, item_state }; masterType = getMasterType(hier);// aka SpriteType itemType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(itemType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = getItemType(inventoryIcon.getName()); } //inventory item sprite Sprite stateSprite = tryGetStateSprite(inventoryIcon, icon_state); //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = itemType; itemName = name; itemDescription = desc; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; // Debug.Log(name + " size=" + size + " type=" + type + " spriteType=" // + spriteType + " (" + desc + ") : " // + icon_state + " / " + item_state + " / C: " + clothingReference // + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' // + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); }
public void ConstructItem(string hierString) { //randomize clothing! randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { // Logger.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { // Logger.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); //custom inventory(?) icon, if present icon = tryGetAttr("icon"); // states icon_state = tryGetAttr("icon_state"); item_color = tryGetAttr("item_color"); //also a state item_state = tryGetAttr("item_state"); string[] states = { icon_state, item_color, item_state }; throwDamage = TryParseFloat("throwforce") ?? throwDamage; throwSpeed = TryParseFloat("throw_speed") ?? throwSpeed; throwRange = TryParseFloat("throw_range") ?? throwRange; hitDamage = TryParseFloat("force") ?? hitDamage; attackVerb = TryParseList("attack_verb") ?? attackVerb; masterType = getMasterType(hier); // aka SpriteType itemType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(itemType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = getItemType(inventoryIcon.getName()); } //inventory item sprite Sprite stateSprite = tryGetStateSprite(inventoryIcon, icon_state); //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = itemType; itemName = name; itemDescription = desc; spriteType = masterType; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; //assign an order in layer so we don't have arbitrary ordering GetComponentInChildren <SpriteRenderer>().sortingOrder = clothingOffset; // Logger.Log(name + " size=" + size + " type=" + type + " spriteType=" // + spriteType + " (" + desc + ") : " // + icon_state + " / " + item_state + " / C: " + clothingReference // + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' // + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); CheckEvaCapatibility(); }
public void ConstructItem(string hierString) { //randomize clothing! RandomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { dm = Resources.Load("DmObjectData") as DmObjectData; } dmDic = dm.getObject(hier); //basic attributes itemName = TryGetAttr("name"); itemDescription = TryGetAttr("desc"); icon = TryGetAttr("icon"); //states icon_state = TryGetAttr("icon_state"); item_color = TryGetAttr("item_color"); //also a state item_state = TryGetAttr("item_state"); string[] states = { icon_state, item_color, item_state }; throwDamage = TryParseFloat("throwforce") ?? throwDamage; throwSpeed = TryParseFloat("throw_speed") ?? throwSpeed; throwRange = TryParseFloat("throw_range") ?? throwRange; hitDamage = TryParseFloat("force") ?? hitDamage; attackVerb = TryParseList("attack_verb") ?? attackVerb; spriteType = UniItemUtils.GetMasterType(hier); itemType = UniItemUtils.GetItemType(hier); invSheetPaths = UniItemUtils.GetItemClothSheetHier(itemType); int[] inHandOffsets = TryGetInHand(); inHandReferenceLeft = inHandOffsets[0]; inHandReferenceRight = inHandOffsets[1]; inventoryIcon = UniItemUtils.GetInventoryIcon(hier, invSheetPaths, icon, icon_state); clothingReference = TryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = UniItemUtils.GetItemType(inventoryIcon.getName()); } CanConnectToTank = TryGetConnectedToTank(); //inventory item sprite Sprite stateSprite = UniItemUtils.TryGetStateSprite(inventoryIcon, icon_state); var childSpriteRenderer = GetComponentInChildren <SpriteRenderer>(); childSpriteRenderer.sprite = stateSprite; //assign an order in layer so we don't have arbitrary ordering childSpriteRenderer.sortingOrder = clothingReference; CheckEvaCapatibility(); }
private void OnEnable() { //todo: make more methods static //randomize clothing! uncomment only if you spawn without any clothes on! randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierarchy.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { Debug.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { Debug.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); icon_state = tryGetAttr("icon_state"); item_state = tryGetAttr("item_state"); icon = tryGetAttr("icon"); masterType = getMasterType(hier); iType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(iType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(); //determine item type via sheet name if hier name failed if (iType == ItemType.None) { iType = getItemType(inventoryIcon.getName()); } //inventory item sprite DmiState iState = inventoryIcon.getState(icon_state); Sprite stateSprite = inventoryIcon.spriteSheet[iState.offset]; //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = iType; itemName = name; itemDescription = desc; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; Debug.Log(name + " size=" + size + " type=" + type + " spriteType=" + spriteType + " (" + desc + ") : " + icon_state + " / " + item_state + " / C: " + clothingReference + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); }