AtlasPlugin.CodeGeneration.VariableAssignmentCodeGenerator.HandleWriteInstanceVariableAssignment C# (CSharp) Method

HandleWriteInstanceVariableAssignment() public static method

public static HandleWriteInstanceVariableAssignment ( NamedObjectSave instance, ICodeBlock code, InstructionSave variable ) : void
instance FlatRedBall.Glue.SaveClasses.NamedObjectSave
code ICodeBlock
variable InstructionSave
return void
        public static void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
        {
            var shouldHandle = variable.Member == "AtlasedTexture" && instance.SourceClassType == "Sprite";

            if(shouldHandle)
            {
                var memberName = instance.InstanceName;

                // The code should look something like:
                // 
                // SpriteInstance.AtlasedTexture = FlatRedBall.Graphics.Texture.AtlasLoader.LoadAtlasedTexture("asdf");
                //
                // But I still need to make the AtlasLoader keep track of all loaded assets, and I need to have a "priority" system

                code = code.Block();
                {
                    // eventually this might exist
                    //var atlas = instance.GetInstructionFromMember("");
                    // for now we assume that the texture packer project is in global content
                    var rfs = GlueState.Self.CurrentGlueProject.GlobalFiles.FirstOrDefault(item =>
                    {
                        var ati = item.GetAssetTypeInfo();
                        if(ati != null)
                        {
                            return ati == AtiManager.Self.TextureAtlasAti;
                        }

                        return false;
                    });

                    if (rfs != null)
                    {
                        var atlas = $"{GlueState.Self.ProjectNamespace}.GlobalContent.{rfs.GetInstanceName()}";
                        code.Line($"var atlas = {atlas};");

                        code.Line($"{memberName}.AtlasedTexture = atlas.Sprite(\"{variable.Value}\");");
                    }
                }
            }
        }
VariableAssignmentCodeGenerator