Ejemplo n.º 1
0
        public bool IsEqualTo(TileCell cell)
        {
            if (X != cell.X || Y != cell.Y)
            {
                return(false);
            }
            if (Alpha.Equals(cell.Alpha) == false)
            {
                return(false);
            }
            if (Rotation.Equals(cell.Rotation) == false)
            {
                return(false);
            }
            if (AutoTextureType != cell.AutoTextureType)
            {
                return(false);
            }
            if (FlipEffect != cell.FlipEffect)
            {
                return(false);
            }

            return(TextureSource.IsEqualTo(cell.TextureSource));
        }
Ejemplo n.º 2
0
    private static bool TryHandleState(
        State state,
        string folderPath,
        out Exported.State exportedState)
    {
        exportedState = default;
        TextureSource textureSource = state.GetComponent <TextureSource>();

        if (textureSource == null)
        {
            EditorUtility.DisplayDialog("Error", "State has no texture source!", "Ok");
            return(false);
        }
        var stateId = state.GetExportedId();

        exportedState = new Exported.State
        {
            id              = stateId,
            title           = state.title,
            url             = $"{Tour.Instance.linkPrefix}{textureSource.Export(folderPath, stateId)}",
            type            = textureSource.SourceType.ToString().ToLower(),
            pictureRotation = state.transform.rotation,
            links           = GetLinks(state),
            groupLinks      = GetGroupLinks(state)
        };
        return(true);
    }
    void OnTypeSelected(object type)
    {
        if (_currentState == null)
        {
            return;
        }

        if (_currentTextureSourceType != null && _currentTextureSourceType.Equals(type))
        {
            return;
        }

        Undo.RecordObject(_currentState, "Undo state changes");

        TextureSource textureSource = _currentState.GetComponent <TextureSource>();

        if (textureSource)
        {
            Undo.DestroyObjectImmediate(textureSource);
        }

        Undo.AddComponent(_currentState.gameObject, type as Type);
        _currentState.ReloadTexture();

        UpdateEditor(_currentState);
    }
Ejemplo n.º 4
0
        public static void Postfix(BlockEntityChisel __instance)
        {
            try
            {
                ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api);

                EnumChiselPlusMesh setMesh = accessor.Properties[__instance.Pos].Mesh;

                if (setMesh != EnumChiselPlusMesh.none && __instance.MaterialIds != null)
                {
                    Vec3f rot = accessor.Properties[__instance.Pos].Rotation;

                    ICoreClientAPI capi = (__instance.Api as ICoreClientAPI);
                    string         name = Enum.GetName(typeof(EnumChiselPlusMesh), setMesh);
                    if (name == null)
                    {
                        return;
                    }
                    string code = string.Format("chiselplus:genericblocks-{0}", name);

                    capi.Tesselator.TesselateBlock(capi.World.BlockAccessor.GetBlock(new AssetLocation(code)), out MeshData mesh);

                    TextureSource            texSource = new TextureSource(__instance.Api.World as ClientMain, capi.BlockTextureAtlas.Size, capi.World.BlockAccessor.GetBlock(__instance.MaterialIds.FirstOrDefault()));
                    Dictionary <string, int> textureCodeToIdMapping = AccessTools.Field(typeof(TextureSource), "textureCodeToIdMapping").GetValue(texSource) as Dictionary <string, int>;

                    mesh.SetTexPos(texSource[textureCodeToIdMapping.FirstOrDefault().Key]);
                    mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.DEG2RAD * rot.X, GameMath.DEG2RAD * rot.Y, GameMath.DEG2RAD * rot.Z);
                    __instance.Mesh = mesh;
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 5
0
        public static void Postfix(ChiselBlockModelCache __instance, ItemStack forStack, ref ICoreClientAPI ___capi, ref MeshRef __result)
        {
            int?setMesh = forStack.Attributes.TryGetInt("chiselplusmesh");

            if (setMesh != null && setMesh != (int)EnumChiselPlusMesh.none)
            {
                Vec3f rot = new Vec3f()
                {
                    X = forStack.Attributes.TryGetFloat("chiselplusRotX") ?? 0.0f,
                    Y = forStack.Attributes.TryGetFloat("chiselplusRotY") ?? 0.0f,
                    Z = forStack.Attributes.TryGetFloat("chiselplusRotZ") ?? 0.0f
                };

                string            name      = Enum.GetName(typeof(EnumChiselPlusMesh), setMesh);
                IntArrayAttribute materials = forStack.Attributes["materials"] as IntArrayAttribute;

                if (name == null || materials == null)
                {
                    return;
                }

                string code = string.Format("chiselplus:genericblocks-{0}", name);

                ___capi.Tesselator.TesselateBlock(___capi.World.BlockAccessor.GetBlock(new AssetLocation(code)), out MeshData mesh);

                TextureSource texSource = new TextureSource(___capi.World as ClientMain, ___capi.BlockTextureAtlas.Size, ___capi.World.BlockAccessor.GetBlock(materials.value.FirstOrDefault()));

                Dictionary <string, int> textureCodeToIdMapping = texSource.GetField <Dictionary <string, int> >("textureCodeToIdMapping");

                mesh.SetTexPos(texSource[textureCodeToIdMapping.FirstOrDefault().Key]);
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.DEG2RAD * rot.X, GameMath.DEG2RAD * rot.Y, GameMath.DEG2RAD * rot.Z);

                __result = ___capi.Render.UploadMesh(mesh);
            }
        }
Ejemplo n.º 6
0
        public Game()
        {
            _graphics = new GraphicsDeviceManager(this);
            _world    = new World();

            Content.RootDirectory = "Content";
            _textureSource        = new TextureSource(Content);
        }
Ejemplo n.º 7
0
        public virtual void Init()
        {
            SpriteRenderer        = GetComponent <SpriteRenderer>();
            SpriteRenderer.sprite = Sprite.Create(TextureSource.Texture, new Rect(0, 0, TextureSource.Texture.width, TextureSource.Texture.height), new Vector2(0.0f, 0.0f), TextureSource.PPU, 0, SpriteMeshType.FullRect);
            TextureSource.SetUpToRenderer(SpriteRenderer);

            SpriteRenderer.sortingLayerID = SortingLayerID;
        }
Ejemplo n.º 8
0
    private static bool TryHandleState(
        State state,
        string folderPath,
        ResourceHandlePath resourceHandlePath,
        int imageCroppingLevel,
        out Exported.State exportedState)
    {
        exportedState = default;
        TextureSource textureSource = state.GetComponent<TextureSource>();
        if (textureSource == null)
        {
            EditorUtility.DisplayDialog("Error", "State has no texture source!", "Ok");
            return false;
        }

        var stateId = state.GetExportedId();

        var textureFileLocation = textureSource.GetAssetPath();
        string url = null;
        string croppedImageUrl = null;
        switch (resourceHandlePath)
        {
            case ResourceHandlePath.CopyToDist:
                var stateFolderPath = Path.Combine(folderPath, stateId);
                ImageCropper.HandleImage(textureFileLocation, stateFolderPath, imageCroppingLevel);
                croppedImageUrl = stateId;
                break;
            case ResourceHandlePath.PublishPath:
                url = textureFileLocation;
                if (url.StartsWith("Packages"))
                {
                    EditorUtility.DisplayDialog("Error",
                        "You can't use texture from Packages while preview. Please use textures only from Assets",
                        "Ok");
                    return false;
                }

                break;
            default:
                throw new Exception($"incorrect ResourceHandlePath {resourceHandlePath}");
        }

        exportedState = new Exported.State
        {
            id = stateId,
            title = state.title,
            url = url,
            croppedImageUrl = croppedImageUrl,
            type = textureSource.SourceType.ToString().ToLower(),
            pictureRotation = state.transform.rotation,
            links = GetLinks(state),
            groupLinks = GetGroupLinks(state),
            fieldItems = GetFieldItems(state, folderPath, resourceHandlePath)
        };
        return true;
    }
Ejemplo n.º 9
0
    public void ReloadTexture()
    {
        TextureSource textureSource = GetComponent <TextureSource>();

        if (textureSource == null)
        {
            return;
        }

        StartCoroutine(LoadTexture(textureSource));
    }
Ejemplo n.º 10
0
    void Start()
    {
        _renderer = GetComponentInChildren <Renderer>();
        Assert.IsNotNull(_renderer);

        Assert.IsNotNull(firstState);

        Assert.IsTrue(colorSchemes.Length > 0, "Need minimum 1 element in colors collection");
        _currentState         = firstState;
        _currentTextureSource = PrepareState(_currentState);

        SpawnConnections();
    }
Ejemplo n.º 11
0
    public void StartTransition(State nextState)
    {
        if (_nextState != null || _transition > 0.0f)
        {
            return;
        }

        ClearConnections();

        _nextState         = nextState;
        _nextTextureSource = PrepareState(_nextState);

        _transition = 0.0f;
    }
Ejemplo n.º 12
0
        protected override void CustomFileExport(ExportParameters exportParameters)
        {
            var Blueprint = TextureSource.Create();

            Blueprint.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord);

            var outputPath = Path.GetFullPath(Path.Combine(exportParameters.OutputDirectory, exportParameters.FileRecord.Name + exportParameters.FileExtension));

            var text = JsonConvert.SerializeObject(Blueprint, Formatting.Indented);

            File.WriteAllText(outputPath, text);

            exportParameters.OnProgressReport?.Invoke(exportParameters.FileRecord, 0);
        }
        public TextureManager(ContentManager content)
        {
            Console.WriteLine("Loading Textures");
            tiles = content.Load <ShipGameLibrary.Tile[]>("Xml/Tile");

            sources = new TextureSource[tiles.Length];

            for (int i = 0; i < sources.Length; i++)
            {
                sources[i]        = new TextureSource();
                sources[i].id     = tiles[i].id;
                sources[i].source = SourceRect(tiles[i].id, "spritesheet", content);
                Console.WriteLine(sources[i].id + " " + sources[i].source);
            }
        }
Ejemplo n.º 14
0
 public Particle(TextureSource texture, int ttl, Vector2 position, float xvel, float yvel, float xfriction, float yfricition, Color color, float scale)
 {
     this.texture  = texture;
     this.ttl      = ttl;
     this.sttl     = ttl;
     this.position = position;
     //this.xvel = xvel;
     //this.yvel = yvel;
     this.velocity = new Vector2(xvel, yvel);
     this.color    = color;
     this.scolor   = color;
     this.scale    = scale;
     this.xfric    = xfriction;
     this.yfric    = yfricition;
 }
        public static void Load(string contentPackFile)
        {
            if (Directory.Exists(Path.Combine(GameController.GamePath, "ContentPacks")))
            {
                if (!File.Exists(contentPackFile))
                {
                    return;
                }
                foreach (var line in File.ReadAllLines(contentPackFile))
                {
                    switch (line.CountSplits("|"))
                    {
                    case 2:
                        //ResolutionChange
                        var textureName = line.GetSplit(0, "|");
                        var resolution  = Convert.ToInt32(line.GetSplit(1, "|"));

                        if (!TextureResolutions.ContainsKey(textureName))
                        {
                            TextureResolutions.Add(textureName, resolution);
                        }
                        break;

                    case 4:
                        //TextureReplacement
                        var oldTextureName = line.GetSplit(0, "|");
                        var newTextureName = line.GetSplit(2, "|");
                        var oRs            = line.GetSplit(1, "|");
                        //oRS = oldRectangleSource
                        var nRs = line.GetSplit(3, "|");
                        //nRS = newRectangleSource

                        var oldTextureSource = new TextureSource(oldTextureName, new Rectangle(Convert.ToInt32(oRs.GetSplit(0)), Convert.ToInt32(oRs.GetSplit(1)), Convert.ToInt32(oRs.GetSplit(2)), Convert.ToInt32(oRs.GetSplit(3))));
                        var newTextureSource = new TextureSource(newTextureName, new Rectangle(Convert.ToInt32(nRs.GetSplit(0)), Convert.ToInt32(nRs.GetSplit(1)), Convert.ToInt32(nRs.GetSplit(2)), Convert.ToInt32(nRs.GetSplit(3))));

                        if (!TextureReplacements.ContainsKey(oldTextureSource))
                        {
                            TextureReplacements.Add(oldTextureSource, newTextureSource);
                        }

                        break;
                    }
                }
            }
        }
Ejemplo n.º 16
0
    private IEnumerator LoadTexture(TextureSource textureSource)
    {
        yield return(StartCoroutine(textureSource.LoadTexture()));

        if (_renderer == null)
        {
            _renderer = GetComponent <Renderer>();
        }

        if (_materialProperties == null)
        {
            _materialProperties = new MaterialPropertyBlock();
        }

        _renderer.GetPropertyBlock(_materialProperties);
        _materialProperties.SetTexture("_MainTex", textureSource.LoadedTexture);
        _renderer.SetPropertyBlock(_materialProperties);
    }
Ejemplo n.º 17
0
 public Heatmap(string _name)
 {
     heatmapResolution = 64;
     flipAutoConstrain = false;
     autoConstrain     = false;
     alphaMapData      = null;
     heatmapValues     = null;
     lowerValueLimit   = 0;
     higherValueLimit  = 100;
     name              = _name;
     texSource         = TextureSource.DefaultColors;
     splatPrototypes   = null;
     interpolationMode = InterpolationMode.NearestNeighbor;
     heatmapDataPoints = null;
     dataType          = HeatmapData.HeightMap;
     heatmapSplatMaps  = new List <HeatmapSplatprototype>();
     baseValue         = 0.0f;
     filter            = "";
 }
    void UpdateEditor(State state)
    {
        _currentState = state;

        TextureSource textureSource = state.GetComponent <TextureSource>();

        if (textureSource == null)
        {
            textureSource = Undo.AddComponent <FileImageSource>(state.gameObject);
        }

        _currentTextureSourceType = textureSource.GetType();

        if (_currentTextureSourceEditor != null)
        {
            GameObject.DestroyImmediate(_currentTextureSourceEditor);
        }

        _currentTextureSourceEditor = Editor.CreateEditor(textureSource);
    }
Ejemplo n.º 19
0
    void Update()
    {
        if (_nextState != null)
        {
            _transition += Time.deltaTime;

            if (_transition >= 1.0f)
            {
                _currentTextureSource.InUse = false;
                _currentState         = _nextState;
                _currentTextureSource = _nextTextureSource;
                _nextState            = null;
                _nextTextureSource    = null;
                _transition           = 0.0f;
                SpawnConnections();
            }
        }

        UpdateMaterial();
    }
Ejemplo n.º 20
0
 public Sprite(Level level)
 {
     position   = Vector2.Zero;
     source     = null;
     this.level = level;
 }
Ejemplo n.º 21
0
 public Particle(TextureSource texture, int ttl, Vector2 position, float xvel, float yvel, float xfriction, float yfricition, Color color, float scale, ParticleForce force)
     : this(texture, ttl, position, xvel, yvel, xfriction, yfricition, color, scale)
 {
     this.force = force;
 }
Ejemplo n.º 22
0
        private static MeshRef GenerateMesh(ClientMain game, string meshId, ItemStack stack)
        {
            MeshRef         meshRef = null;
            UnloadableShape shape   = new UnloadableShape();

            if (stack.Item.Shape?.Base != null)
            {
                shape.Load(game, new AssetLocationAndSource(stack.Item.Shape.Base));
            }
            if (shape.Textures == null)
            {
                shape.Textures = new Dictionary <string, AssetLocation>();
            }
            if (shape.AttachmentPointsByCode == null)
            {
                shape.AttachmentPointsByCode = new Dictionary <string, AttachmentPoint>();
            }
            Item item = new Item();

            item.Textures = new Dictionary <string, CompositeTexture>();

            foreach (ItemstackAttribute attr in stack.Attributes.GetOrAddTreeAttribute("toolparts").Values)
            {
                ItemStack partstack = attr.GetValue() as ItemStack;
                IToolPart part      = partstack.Item as IToolPart;
                if (part != null)
                {
                    if (part.TinkerProps?.ProvidedTextures == null)
                    {
                        partstack.Item.Textures.ToList().ForEach(kp =>
                        {
                            shape.Textures[kp.Key] = kp.Value.Base;
                            item.Textures[kp.Key]  = kp.Value;
                        });
                        UnloadableShape tmp = new UnloadableShape();
                        if (!tmp.Load(game, new AssetLocationAndSource(partstack.Item.Shape.Base)))
                        {
                            continue;
                        }


                        ShapeElement slot = shape.GetElementByName(part.TinkerProps.PartType);

                        if (slot != null)
                        {
                            slot.Children = slot.Children.Concat(tmp.CloneElements()[0].Children).ToArray();
                        }

                        if (tmp.AttachmentPointsByCode != null)
                        {
                            tmp.AttachmentPointsByCode.ToList().ForEach(kp => shape.AttachmentPointsByCode[kp.Key] = kp.Value);
                        }
                    }
                    else
                    {
                        part.TinkerProps.ProvidedTextures.ToList().ForEach(kp =>
                        {
                            shape.Textures[kp.Key] = kp.Value;
                            item.Textures[kp.Key]  = new CompositeTexture()
                            {
                                Base = kp.Value.Clone()
                            };
                        });
                    }
                }
            }

            ShapeTesselatorManager  manager    = game.GetType().GetField("TesselatorManager", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ShapeTesselatorManager;
            ItemTextureAtlasManager blockAtlas = game.GetType().GetField("ItemAtlasManager", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ItemTextureAtlasManager;
            ClientPlatformAbstract  platform   = game.GetType().GetField("Platform", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ClientPlatformAbstract;

            if (manager != null && blockAtlas != null && platform != null)
            {
                TextureSource       source  = new TextureSource(game, blockAtlas.Size, item);
                var                 field   = manager.Tesselator.GetType().GetField("meta", BindingFlags.Instance | BindingFlags.NonPublic);
                var                 oldMeta = field.GetValue(manager.Tesselator) as TesselationMetaData;
                TesselationMetaData meta    = oldMeta.Clone();
                meta.texSource    = source;
                meta.withJointIds = false;
                MeshData meshData;
                manager.TLTesselator.Value.TesselateShape((Shape)shape, out meshData, new Vec3f(), new Vec3f(), meta);
                meshRef          = platform.UploadMesh(meshData);
                MeshRefs[meshId] = new AccessLifetime <MeshRef>(meshRef);
            }
            return(meshRef);
        }
Ejemplo n.º 23
0
 public virtual void LoadContent(ContentManager content)
 {
     TextureSource.LoadContent(content);
 }
Ejemplo n.º 24
0
		public Texture ()
		{
			_textureBitmap = null;
			_source = null;
		}