Exemple #1
0
        public static IRsiStateLike RsiStateLike(this SpriteSpecifier specifier)
        {
            var resC = IoCManager.Resolve <IResourceCache>();

            switch (specifier)
            {
            case SpriteSpecifier.Texture tex:
                return(tex.GetTexture(resC));

            case SpriteSpecifier.Rsi rsi:
                return(rsi.GetState(resC));

            case SpriteSpecifier.EntityPrototype prototypeIcon:
                var protMgr = IoCManager.Resolve <IPrototypeManager>();
                if (!protMgr.TryIndex <EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
                {
                    Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
                    return(SpriteComponent.GetFallbackState(resC));
                }

                return(SpriteComponent.GetPrototypeIcon(prototype, resC));

            default:
                throw new NotSupportedException();
            }
        }
Exemple #2
0
    public RSI.State GetState(SpriteSpecifier.Rsi rsiSpecifier)
    {
        if (_resourceCache.TryGetResource <RSIResource>(
                SharedSpriteComponent.TextureRoot / rsiSpecifier.RsiPath,
                out var theRsi) &&
            theRsi.RSI.TryGetState(rsiSpecifier.RsiState, out var state))
        {
            return(state);
        }

        Logger.Error("Failed to load RSI {0}", rsiSpecifier.RsiPath);
        return(SpriteComponent.GetFallbackState(_resourceCache));
    }
Exemple #3
0
    public IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
    {
        var icon = IconComponent.GetPrototypeIcon(prototype, _resourceCache);

        if (icon != null)
        {
            return(icon);
        }

        if (!prototype.Components.ContainsKey("Sprite"))
        {
            return(SpriteComponent.GetFallbackState(resourceCache));
        }

        var dummy           = Spawn(prototype.ID, MapCoordinates.Nullspace);
        var spriteComponent = EnsureComp <SpriteComponent>(dummy);
        var result          = spriteComponent.Icon ?? SpriteComponent.GetFallbackState(resourceCache);

        Del(dummy);

        return(result);
    }
Exemple #4
0
    public IRsiStateLike RsiStateLike(SpriteSpecifier specifier)
    {
        switch (specifier)
        {
        case SpriteSpecifier.Texture tex:
            return(tex.GetTexture(_resourceCache));

        case SpriteSpecifier.Rsi rsi:
            return(GetState(rsi));

        case SpriteSpecifier.EntityPrototype prototypeIcon:
            if (!_proto.TryIndex <EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
            {
                Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
                return(SpriteComponent.GetFallbackState(_resourceCache));
            }

            return(SpriteComponent.GetPrototypeIcon(prototype, _resourceCache));

        default:
            throw new NotSupportedException();
        }
    }