Exemple #1
0
        /// <summary>
        /// Checks if the wall in other tile is compatible with this type.
        /// It checks if the wall in other tile has exactly the same type as the wall in this tile.
        /// </summary>
        private static bool SharedIsSameWallType(IProtoObjectWall protoWall, Tile tile, bool isConsiderDestroyed)
        {
            foreach (var o in tile.StaticObjects)
            {
                if (o.IsDestroyed)
                {
                    continue;
                }

                if (o.ProtoWorldObject == protoWall)
                {
                    return(true);
                }

                if (isConsiderDestroyed &&
                    o.ProtoWorldObject is ObjectWallDestroyed &&
                    ReferenceEquals(protoWall, ObjectWallDestroyed.GetPublicState(o).OriginalProtoObjectWall))
                {
                    // destroyed wall of the same type
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        private static ITextureAtlasResource ClientGetTextureAtlas(IStaticWorldObject worldObject)
        {
            if (worldObject.ProtoGameObject is ObjectWallDestroyed)
            {
                var protoWall = ObjectWallDestroyed.GetPublicState(worldObject)
                                .OriginalProtoObjectWall;

                if (protoWall == null)
                {
                    Api.Logger.Important("Incorrect destroyed wall - no protoWall defined: " + worldObject);
                    protoWall = Api.GetProtoEntity <ObjectWallWood>();
                }

                return(protoWall.TextureAtlasDestroyed);
            }

            return(ClientGetTextureAtlas(worldObject.ProtoStaticWorldObject));
        }
Exemple #3
0
        public static void ClientRefreshRenderer(IStaticWorldObject worldObject)
        {
            var isDestroyedWall = false;

            if (!(worldObject.ProtoGameObject is IProtoObjectWall protoWall))
            {
                if (!(worldObject.ProtoGameObject is ObjectWallDestroyed))
                {
                    return;
                }

                isDestroyedWall = true;
                protoWall       = ObjectWallDestroyed.GetPublicState(worldObject)
                                  .OriginalProtoObjectWall;
            }

            var result = SharedGetAtlasTextureChunkPosition(worldObject.OccupiedTile,
                                                            protoWall,
                                                            isConsiderDestroyed: !isDestroyedWall,
                                                            isConsiderConstructionSites: !isDestroyedWall);

            try
            {
                var textureAtlas           = ClientGetTextureAtlas(worldObject);
                var primaryTextureResource = textureAtlas.Chunk(
                    (byte)result.Primary.AtlasChunkPosition.X,
                    (byte)result.Primary.AtlasChunkPosition.Y);

                var clientState = worldObject.GetClientState <ObjectWallClientState>();
                clientState.Renderer.TextureResource = primaryTextureResource;
                var destroyedWallYOffset = isDestroyedWall
                                               ? result.Primary.DrawOffsetDestroyed
                                               : result.Primary.DrawOffsetNormal;

                clientState.Renderer.DrawOrderOffsetY = isDestroyedWall
                                                            ? destroyedWallYOffset
                                                            : result.Primary.DrawOffsetNormal;

                // destroy previous overlay renderers
                var overlayRenderers = clientState.RenderersObjectOverlay;
                if (overlayRenderers?.Count > 0)
                {
                    foreach (var renderer in overlayRenderers)
                    {
                        renderer.Destroy();
                    }

                    overlayRenderers.Clear();
                }

                var overlayChunkPreset = result.Overlay;
                if (overlayChunkPreset == null ||
                    overlayChunkPreset.Count == 0)
                {
                    // no overlay renderers needed
                    return;
                }

                // add overlay renderers
                foreach (var preset in overlayChunkPreset.AsList())
                {
                    var overlayRenderer = Api.Client.Rendering.CreateSpriteRenderer(
                        worldObject,
                        textureAtlas.Chunk((byte)preset.AtlasChunkPosition.X,
                                           (byte)preset.AtlasChunkPosition.Y));

                    if (overlayRenderers == null)
                    {
                        overlayRenderers = new List <IComponentSpriteRenderer>();
                        clientState.RenderersObjectOverlay = overlayRenderers;
                    }

                    overlayRenderers.Add(overlayRenderer);
                    overlayRenderer.DrawOrderOffsetY = isDestroyedWall
                                                           ? destroyedWallYOffset
                                                           : preset.DrawOffsetNormal;
                }
            }
            finally
            {
                result.Dispose();
            }
        }