예제 #1
0
    private /*static*/ DmiIcon tryGetInventoryIcon(/*DmiIconData dmi, string[] invSheetPaths, string icon = ""*/)
    {
        //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($"{name} is doing bad dmi.getIconByState({icon_state}) = {invIcon.icon}", Category.DmMetadata);
            return(invIcon);
        }
        //			Logger.LogError();
        return(new DmiIcon());
    }
예제 #2
0
    public DmiState searchStateInIcon(string state, string[] icons, int dirs, bool deepSearch)
    {
        for (int i = 0; i < icons.Length; i++)
        {
            if (icons[i] != "" && state != "")
            {
                string s = getIconPath(icons[i]);

                if (Data.ContainsKey(s))
                {
                    DmiIcon icon = Data[s];                     /*data.Values.ToList().Find(x => x.icon == s);*/

                    DmiState foundState = icon.states.Find(x => x.state == state && (dirs == -1 || x.dirs == dirs));
                    if (foundState != null)
                    {
                        Logger.LogTrace("foundState: " + foundState, Category.DmMetadata);
                        return(foundState);
                    }
                }
            }
        }
        if (deepSearch)
        {
            Logger.LogTrace("Could not find " + state + " in " + icons + ". Deepscanning!", Category.DmMetadata);
            return(searchState(state, dirs));
        }
        Logger.LogTrace("Couldn't find state " + state + " using shallowSearch", Category.DmMetadata);
        return(null);
    }
예제 #3
0
    public Sprite getSprite(string spriteSheet, string unityName)
    {
        //if it's a proper unityName with offset
        int uOffset = DmiIcon.getOffsetFromUnityName(unityName);

        if (!uOffset.Equals(-1))
        {
            return(getSprite(spriteSheet, uOffset));
        }
        //if it's something custom ,like tileconnect handwritten stuff
        DmiIcon icon = getIconBySheet(spriteSheet);

        if (!icon.getName().Equals(""))
        {
            DmiState dmiState = icon.states.Find(state => state.unityName.Equals(unityName));
            if (dmiState != null)
            {
                int offset = dmiState.offset;
                if (icon.spriteSheet.Length > offset && !offset.Equals(-1))
                {
                    return(icon.spriteSheet[offset]);
                }
            }
            Logger.LogErrorFormat("Couldn't find sprite by UN: {0}({1}) in {2}", Category.DmMetadata, spriteSheet, unityName, icon.icon);
        }
        return(new Sprite());
    }
예제 #4
0
    public Sprite getSpriteFromLegacyName(string spriteSheet, string legacyUnityName)
    {
        string iPath = getIconPath(spriteSheet);

        if (legacyData.ContainsKey(iPath))
        {
            DmiIcon  icon         = legacyData[iPath];
            int      legacyOffset = DmiIcon.getOffsetFromUnityName(legacyUnityName);
            int      relativeOffset;
            DmiState legacyDmiState = icon.getStateAtOffset(legacyOffset, out relativeOffset);
            if (legacyDmiState != null && Data.ContainsKey(iPath))
            {
                string   legacyState = legacyDmiState.state;
                DmiState newState    = Data[iPath].getState(legacyState);              //searchStateInIcon(legacyState, spriteSheet, false);
                if (newState != null)
                {
                    //					if (legacyUnityName.Contains("shuttle_wall"))
                    //					{
                    //						Logger.Log("found ya!");
                    //					}
                    return(getSprite(spriteSheet, newState.offset + relativeOffset));
                }
            }
        }
        Logger.LogErrorFormat("failed to getSpriteFromLegacyName: {0} {1}", Category.DmMetadata, spriteSheet, legacyUnityName);
        return(new Sprite());
    }
예제 #5
0
    /// <summary>
    /// Tries to get the inventory icon sprite for the unicloth with the specified hier string. If there are multiple
    /// sprites, just gets the first.
    /// </summary>
    /// <param name="hier"></param>
    /// <returns>first sprite for the specified hier</returns>
    public static Sprite GetInventoryIconSprite(string hier)
    {
        EnsureInit();
        DmiIcon icon        = GetInventoryIcon(hier);
        var     objectAttrs = dm.getObject(hier);

        objectAttrs.TryGetValue("icon_state", out var icon_state);

        return(TryGetStateSprite(icon, icon_state));
    }
예제 #6
0
    public Sprite getSprite(string spriteSheet, int offset)
    {
        DmiIcon icon = getIconBySheet(spriteSheet);

        if (!icon.getName().Equals("") && offset >= 0 && offset < icon.spriteSheet.Length)
        {
            return(icon.spriteSheet[offset]);
        }
        Logger.LogErrorFormat("Couldn't find sprite by offset: {0}({1}) in {2}", Category.DmMetadata, spriteSheet, offset, icon.icon);
        return(new Sprite());
    }
예제 #7
0
    public DmiIcon getIconBySheet(string path)
    {
        string iPath = getIconPath(path);

        if (Data.ContainsKey(iPath))
        {
            DmiIcon icon = Data[iPath];
            if (icon != null)
            {
                return(icon);
            }
        }
        Logger.LogError("Could not find Icon for sheet " + iPath, Category.DmMetadata);
        return(new DmiIcon());
    }
예제 #8
0
    private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state)
    {
        if (dmiIcon == null || dmiIcon.getName().Equals(""))
        {
            Debug.LogErrorFormat("DmiIcon '{0}' is null, unable to get state '{1}'", dmiIcon, icon_state);
            return(new Sprite());
        }

        DmiState iState = dmiIcon.getState(icon_state);

        if (!iState.state.Equals(""))
        {
            return(dmiIcon.spriteSheet[iState.offset]);
        }
        Debug.LogErrorFormat("Failed to find inventory sprite '{1}' in icon '{0}'", dmiIcon.icon, icon_state);
        return(new Sprite());
    }
예제 #9
0
    private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state)
    {
        if (dmiIcon == null || dmiIcon.getName().Equals(""))
        {
            Logger.Log($"DmiIcon '{dmiIcon}' is null, unable to get state '{icon_state}'", Category.DmMetadata);
            return(new Sprite());
        }

        DmiState iState = dmiIcon.getState(icon_state);

        if (!iState.state.Equals(""))
        {
            return(dmiIcon.spriteSheet[iState.offset]);
        }

        Logger.Log($"Failed to find inventory sprite '{icon_state}' in icon '{dmiIcon.icon}'", Category.DmMetadata);
        return(new Sprite());
    }
예제 #10
0
    /// <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());
    }
예제 #11
0
//    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"));
    }
예제 #12
0
 protected bool Equals(DmiIcon other)
 {
     return(string.Equals(icon, other.icon));
 }
예제 #13
0
    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();
    }
예제 #14
0
    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();
    }
예제 #15
0
        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"));
        }