Beispiel #1
0
    public void loadConfig()
    {
        LoadContext loadContext = LoadContext.FromFile("offCenterCamera");

        left               = loadContext.Load <float>("left");
        top                = loadContext.Load <float>("top");
        bottom             = loadContext.Load <float>("bottom");
        transform.position = loadContext.Load <Vector3>("position");
        transform.rotation = loadContext.Load <Quaternion>("rotation");
    }
Beispiel #2
0
        public static LoadResult Load(ISaveDriver driver, bool loadAsLateInitialize)
        {
            DefinitionContext definitionContext = new DefinitionContext();

            definitionContext.FillWithCurrentTypes();
            LoadContext loadContext = new LoadContext(definitionContext, driver);
            LoadData    loadData    = driver.Load();
            LoadResult  loadResult;

            if (loadContext.Load(loadData, loadAsLateInitialize))
            {
                LoadCallbackInitializator loadCallbackInitializator = (LoadCallbackInitializator)null;
                if (loadAsLateInitialize)
                {
                    loadCallbackInitializator = loadContext.CreateLoadCallbackInitializator(loadData);
                }
                loadResult = LoadResult.CreateSuccessful(loadContext.RootObject, loadData.MetaData, loadCallbackInitializator);
            }
            else
            {
                loadResult = LoadResult.CreateFailed((IEnumerable <LoadError>) new LoadError[1]
                {
                    new LoadError("Not implemented")
                });
            }
            return(loadResult);
        }
        public void InitializeModule()
        {
            LoadContext.Load();
            var module = TypeManager.InstantiateModule(ModuleType, LoadContext);

            module.ModuleAttributes = ModuleAttributes;
            module.Host             = Host;
            Module = module;
        }
Beispiel #4
0
        public static Stylesheet LoadFromSource(string stylesheetXml,
                                                Func <string, IBrush> textureGetter,
                                                Func <string, SpriteFont> fontGetter)
        {
            var xDoc = XDocument.Parse(stylesheetXml);

            var colors     = new Dictionary <string, Color>();
            var colorsNode = xDoc.Root.Element("Colors");

            if (colorsNode != null)
            {
                foreach (var el in colorsNode.Elements())
                {
                    var color = ColorStorage.FromName(el.Attribute("Value").Value);
                    if (color != null)
                    {
                        colors[el.Attribute(BaseContext.IdName).Value] = color.Value;
                    }
                }
            }

            Func <Type, string, object> resourceGetter = (t, s) =>
            {
                if (typeof(IBrush).IsAssignableFrom(t))
                {
                    return(textureGetter(s));
                }
                else if (t == typeof(SpriteFont))
                {
                    return(fontGetter(s));
                }

                throw new Exception(string.Format("Type {0} isn't supported", t.Name));
            };

            var result = new Stylesheet();

            var loadContext = new LoadContext
            {
                Namespaces = new[]
                {
                    typeof(WidgetStyle).Namespace
                },
                ResourceGetter      = resourceGetter,
                NodesToIgnore       = new HashSet <string>(new[] { "Designer", "Colors", "Fonts" }),
                LegacyClassNames    = LegacyClassNames,
                LegacyPropertyNames = LegacyPropertyNames,
                Colors = colors
            };

            loadContext.Load(result, xDoc.Root);

            return(result);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void LoadContent(LoadContext context)
        {
            var textureNames = TextureNames;

            if (textureNames != null && textureNames.Length > 0)
            {
                var textures = new List <Texture2D>(textureNames.Length);

                for (int i = 0; i < textureNames.Length; i++)
                {
                    textures.Add(context.Load <Texture2D>(textureNames[i]));
                }

                Textures = textures.ToArray();
            }
        }
Beispiel #6
0
        public static Stylesheet LoadFromSource(string stylesheetXml,
                                                Func <string, IRenderable> textureGetter,
                                                Func <string, SpriteFont> fontGetter)
        {
            var xDoc = XDocument.Parse(stylesheetXml);

            var colors     = new Dictionary <string, Color>();
            var colorsNode = xDoc.Root.Element("Colors");

            if (colorsNode != null)
            {
                foreach (var el in colorsNode.Elements())
                {
                    var color = el.Attribute("Value").Value.FromName();
                    if (color != null)
                    {
                        colors[el.Attribute(BaseContext.IdName).Value] = color.Value;
                    }
                }
            }

            var result = new Stylesheet();

            var loadContext = new LoadContext
            {
                Namespace           = typeof(WidgetStyle).Namespace,
                TextureGetter       = textureGetter,
                FontGetter          = fontGetter,
                NodesToIgnore       = new HashSet <string>(new[] { "Designer", "Colors" }),
                LegacyClassNames    = LegacyClassNames,
                LegacyPropertyNames = LegacyPropertyNames,
                Colors = colors
            };

            loadContext.Load(result, xDoc.Root);

            return(result);
        }
Beispiel #7
0
        public static Stylesheet LoadFromSource(string stylesheetXml,
                                                TextureRegionAtlas textureRegionAtlas,
                                                Dictionary <string, SpriteFontBase> fonts)
        {
            var xDoc = XDocument.Parse(stylesheetXml);

            var colors     = new Dictionary <string, Color>();
            var colorsNode = xDoc.Root.Element("Colors");

            if (colorsNode != null)
            {
                foreach (var el in colorsNode.Elements())
                {
                    var color = ColorStorage.FromName(el.Attribute("Value").Value);
                    if (color != null)
                    {
                        colors[el.Attribute(BaseContext.IdName).Value] = color.Value;
                    }
                }
            }

            Func <Type, string, object> resourceGetter = (t, name) =>
            {
                if (typeof(IBrush).IsAssignableFrom(t))
                {
                    TextureRegion region;

                    if (!textureRegionAtlas.Regions.TryGetValue(name, out region))
                    {
                        var color = ColorStorage.FromName(name);
                        if (color != null)
                        {
                            return(new SolidBrush(color.Value));
                        }
                    }
                    else
                    {
                        return(region);
                    }

                    throw new Exception(string.Format("Could not find parse IBrush '{0}'", name));
                }
                else if (t == typeof(SpriteFontBase))
                {
                    return(fonts[name]);
                }

                throw new Exception(string.Format("Type {0} isn't supported", t.Name));
            };

            var result = new Stylesheet
            {
                Atlas = textureRegionAtlas,
                Fonts = fonts
            };

            var loadContext = new LoadContext
            {
                Namespaces = new[]
                {
                    typeof(WidgetStyle).Namespace
                },
                ResourceGetter      = resourceGetter,
                NodesToIgnore       = new HashSet <string>(new[] { "Designer", "Colors", "Fonts" }),
                LegacyClassNames    = LegacyClassNames,
                LegacyPropertyNames = LegacyPropertyNames,
                Colors = colors
            };

            loadContext.Load(result, xDoc.Root);

            return(result);
        }