Esempio n. 1
0
        public void CreateWindowService()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .AddHardware <IWindowHardware, TestWindowHardware>()
                        .AddService <IWindowService, TestWindowService>() as TypeO;

            typeO.Start();

            var testGame = typeO.Context.Game as TestGame;

            Assert.NotNull(testGame.WindowService);
            Assert.IsType <TestWindowService>(testGame.WindowService);

            Assert.NotNull((testGame.WindowService as TestWindowService)?.WindowHardware);
            Assert.IsType <TestWindowHardware>((testGame.WindowService as TestWindowService)?.WindowHardware);

            var window = testGame.WindowService.CreateWindow();

            Assert.NotNull(window);
            Assert.IsType <TestWindow>(window);

            var canvas = testGame.WindowService.CreateCanvas(window);

            Assert.NotNull(canvas);
            Assert.IsType <TestCanvas>(canvas);

            var contentLoader = testGame.WindowService.CreateContentLoader(canvas);

            Assert.NotNull(contentLoader);
            Assert.IsType <TestContentLoader>(contentLoader);
        }
Esempio n. 2
0
        public void LoggerTest()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);

            typeO = TypeO.Create <TestGame>(GameName)
                    .SetLogger(LogLevel.None) as TypeO;
            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);
            Assert.Equal(LogLevel.None, typeO.Context.Logger.LogLevel);

            typeO = TypeO.Create <TestGame>(GameName)
                    .SetLogger <TestLogger>(LogLevel.None) as TypeO;
            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <TestLogger>(typeO.Context.Logger);
            Assert.Equal(LogLevel.None, typeO.Context.Logger.LogLevel);
        }
Esempio n. 3
0
        public void AddModule()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .LoadModule <TestModule>() as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(TestModule)) as TestModule;

            Assert.NotNull(module);
            Assert.IsType <TestModule>(module);
            Assert.NotEmpty(typeO.Context.Modules);
            Assert.Null(module.TestService);
            Assert.Null(module.TestHardware);

            typeO
            .AddHardware <ITestHardware, TestHardware>()
            .AddService <ITestService, TestServiceWithHardware>();

            typeO.Start();

            Assert.NotNull(module.TestService);
            Assert.NotNull(module.TestHardware);

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.RequireModule <TestModule>(new TypeOEngine.Typedeaf.Core.Engine.Version(1, 0, 0));
            Assert.Throws <InvalidOperationException>(() => typeO.Start());

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.LoadModule <TestRefModule>();
            Assert.Throws <InvalidOperationException>(() => typeO.Start());

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.LoadModule <TestRefModule>();
            typeO.LoadModule <TestModule>();
            Assert.Throws <InvalidOperationException>(() => typeO.Start());
        }
Esempio n. 4
0
 public override void LoadExtensions()
 {
     TypeO.AddHardware <IWindowHardware, SDLWindowHardware>();
     TypeO.AddHardware <IKeyboardHardware, SDLKeyboardHardware>();
     TypeO.AddHardware <IMouseHardware, SDLMouseHardware>();
     TypeO.BindContent <Texture, SDLTexture>();
     TypeO.BindContent <Font, SDLFont>();
 }
Esempio n. 5
0
            public static ITypeO Create <G>(string name) where G : Game, new()
            {
                var typeO = new TypeO();

                typeO.Context = new Context(new G(), typeO, name);

                return(typeO);
            }
Esempio n. 6
0
        public void CreateGame()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            Assert.NotNull(typeO);
            Assert.NotNull(typeO.Context);
            Assert.NotNull(typeO.Context.Game);
            Assert.IsType <TestGame>(typeO.Context.Game);
        }
Esempio n. 7
0
        public void LoadDesktopModule()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .LoadModule <DesktopModule>() as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(DesktopModule)) as DesktopModule;

            Assert.NotNull(module);
            Assert.IsType <DesktopModule>(module);
            Assert.NotEmpty(typeO.Context.Modules);
        }
Esempio n. 8
0
        public void BindContent()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .BindContent <BaseContent, SubContent>() as TypeO;

            typeO.Start();

            Assert.NotEmpty(typeO.Context.ContentBinding);
            Assert.NotNull(typeO.Context.ContentBinding[typeof(BaseContent)]);
        }
Esempio n. 9
0
 static void Main()
 {
     TypeO.Create <BreakoutGame>("Breakout")
     .LoadModule <DesktopModule>(new DesktopModuleOption()
     {
         SaveLogsToDisk = false
     })
     .LoadModule <SDLModule>()
     .SetLogger(LogLevel.Info)
     .Start();
 }
Esempio n. 10
0
 public static void Main()
 {
     TypeO.Create <SpaceInvaderGame>("Space invader")
     .LoadModule <DesktopModule>(new DesktopModuleOption()
     {
         SaveLogsToDisk = false
     })
     .LoadModule <SDLModule>()
     .SetLogger(LogLevel.Info)
     .Start();
 }
Esempio n. 11
0
        public override void Initialize()
        {
            TypeO.RequireTypeO(new Version(0, 1, 1));

            if (TypeO.Context.Logger is DefaultLogger)
            {
                (TypeO.Context.Logger as DefaultLogger).LogToDisk = Option.SaveLogsToDisk;
                if (!string.IsNullOrEmpty(Option.LogPath))
                {
                    (TypeO.Context.Logger as DefaultLogger).LogPath = Option.LogPath;
                }
            }
        }
Esempio n. 12
0
 internal Context(Game game, TypeO typeO, string name) : base()
 {
     Name                 = name;
     Game                 = game;
     TypeO                = typeO;
     LastTick             = DateTime.UtcNow;
     Modules              = new List <Module>();
     ModuleRequirements   = new List <Tuple <Type, Version> >();
     RequiredTypeOVersion = new Version(0, 0, 0);
     Hardwares            = new Dictionary <Type, Hardware>();
     Services             = new Dictionary <Type, Service>();
     ContentBinding       = new Dictionary <Type, Type>();
 }
Esempio n. 13
0
        public void AddHardware()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .AddHardware <ITestHardware, TestHardware>()
                        .AddService <ITestService, TestServiceWithHardware>() as TypeO;

            typeO.Start();

            var game = typeO.Context.Game as TestGameWithService;

            Assert.NotNull((game.TestService as TestServiceWithHardware)?.TestHardware);
            Assert.IsType <TestHardware>((game.TestService as TestServiceWithHardware)?.TestHardware);
            Assert.NotEmpty(typeO.Context.Hardwares);
        }
Esempio n. 14
0
        public void TestDefaultLogger()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .LoadModule <DesktopModule>(new DesktopModuleOption()
            {
                LogPath = "test"
            }, false) as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(DesktopModule)) as DesktopModule;

            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);
            Assert.Equal("test", (typeO.Context.Logger as DefaultLogger).LogPath);
        }
Esempio n. 15
0
        public void CreateKeyboardInputService()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .AddHardware <IKeyboardHardware, TestKeyboardHardware>()
                        .AddService <IKeyboardInputService, TestKeyboardInputService>() as TypeO;

            typeO.Start();

            var testGame = typeO.Context.Game as TestGame;

            Assert.NotNull(testGame.KeyboardInputService);
            Assert.IsType <TestKeyboardInputService>(testGame.KeyboardInputService);

            Assert.NotNull((testGame.KeyboardInputService as TestKeyboardInputService)?.KeyboardHardware);
            Assert.IsType <TestKeyboardHardware>((testGame.KeyboardInputService as TestKeyboardInputService)?.KeyboardHardware);
        }
Esempio n. 16
0
        public void AddService()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .AddService <ITestService, TestService>() as TypeO;

            typeO.Start();

            var game = typeO.Context.Game as TestGameWithService;

            Assert.NotNull(game.TestService);
            Assert.IsType <TestService>(game.TestService);
            Assert.NotEmpty(typeO.Context.Services);

            typeO = TypeO.Create <TestGameWithService>(GameName)
                    .AddService <ITestService, TestServiceWithHardware>() as TypeO;
            Assert.Throws <InvalidOperationException>(() => typeO.Start());
        }
Esempio n. 17
0
        public void SwitchScene()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.LoadModule <DesktopModule>()
            .LoadModule <SDLModule>()
            .Start();

            var testGame = (typeO.Context.Game as TestGame);

            testGame.Scenes.SetScene <TestScene1>();

            Assert.NotNull(testGame.Scenes.CurrentScene);
            Assert.IsType <TestScene1>(testGame.Scenes.CurrentScene);

            var testScene = testGame.Scenes.CurrentScene as TestScene1;

            Assert.NotNull(testScene.Logger);
            Assert.IsType <DefaultLogger>(testScene.Logger);

            Assert.NotNull(testScene.WindowService);
            Assert.NotNull((testScene.WindowService as WindowService).WindowHardware);
            Assert.IsType <SDLWindowHardware>((testScene.WindowService as WindowService).WindowHardware);

            Assert.NotNull(testScene.KeyboardInputService);
            Assert.NotNull((testScene.KeyboardInputService as KeyboardInputService).KeyboardHardware);
            Assert.IsType <SDLKeyboardHardware>((testScene.KeyboardInputService as KeyboardInputService).KeyboardHardware);

            Assert.NotNull(testScene.Scenes);

            Assert.NotNull(testScene.Scenes.Window);
            Assert.IsType <SDLWindow>(testScene.Scenes.Window);

            Assert.NotNull(testScene.Scenes.Canvas);
            Assert.IsType <SDLCanvas>(testScene.Scenes.Canvas);

            Assert.NotNull(testScene.Scenes.ContentLoader);
            Assert.IsType <SDLContentLoader>(testScene.Scenes.ContentLoader);

            testGame.Scenes.SetScene <TestScene2>();
            Assert.NotNull(testGame.Scenes.CurrentScene);
            Assert.IsType <TestScene2>(testGame.Scenes.CurrentScene);
        }
Esempio n. 18
0
        public override void Initialize()
        {
            TypeO.RequireTypeO(new Core.Engine.Version(0, 1, 1));
            TypeO.RequireModule <DesktopModule>(new Core.Engine.Version(0, 1, 1));
            TypeO.AddService <ISDLService, SDLService>();
            ((ISDLService)TypeO.Context.Services[typeof(ISDLService)]).Option = Option;

            //Initial SDL
            foreach (var hint in Option.Hints)
            {
                SDL2.SDL.SDL_SetHint(hint.Key, hint.Value);
            }

            foreach (var eventState in Option.EventStates)
            {
                SDL2.SDL.SDL_EventState(eventState.Key, eventState.Value);
            }

            if (SDL2.SDL.SDL_Init(Option.SDLInitFlags) != 0)
            {
                var message = $"SDL_Init Error: {SDL2.SDL.SDL_GetError()}";
                Logger.Log(LogLevel.Fatal, message);
                TypeO.Context.Exit();
                throw new ApplicationException(message);
            }

            if (SDL_image.IMG_Init(Option.IMGInitFlags) == 0)
            {
                var message = $"IMG_Init Error: {SDL2.SDL.SDL_GetError()}";
                Logger.Log(LogLevel.Fatal, message);
                TypeO.Context.Exit();
                throw new ApplicationException(message);
            }

            if (SDL_ttf.TTF_Init() != 0)
            {
                var message = $"TTF_Init Error: {SDL2.SDL.SDL_GetError()}";
                Logger.Log(LogLevel.Fatal, message);
                TypeO.Context.Exit();
                throw new ApplicationException(message);
            }
        }
Esempio n. 19
0
        public void LoadDefaults()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.LoadModule <DesktopModule>()
            .LoadModule <SDLModule>()
            .Start();

            Assert.NotEmpty(typeO.Context.ContentBinding);
            Assert.NotEmpty(typeO.Context.Hardwares);
            Assert.NotEmpty(typeO.Context.Services);

            var testGame = (typeO.Context.Game as TestGame);

            Assert.NotNull(testGame.Logger);
            Assert.IsType <DefaultLogger>(testGame.Logger);

            Assert.NotNull(testGame.WindowService);
            Assert.NotNull((testGame.WindowService as WindowService).WindowHardware);
            Assert.IsType <SDLWindowHardware>((testGame.WindowService as WindowService).WindowHardware);

            Assert.NotNull(testGame.KeyboardInputService);
            Assert.NotNull((testGame.KeyboardInputService as KeyboardInputService).KeyboardHardware);
            Assert.IsType <SDLKeyboardHardware>((testGame.KeyboardInputService as KeyboardInputService).KeyboardHardware);

            Assert.NotNull(testGame.Scenes);

            Assert.NotNull(testGame.Scenes.Window);
            Assert.IsType <SDLWindow>(testGame.Scenes.Window);

            Assert.NotNull(testGame.Scenes.Canvas);
            Assert.IsType <SDLCanvas>(testGame.Scenes.Canvas);

            Assert.NotNull(testGame.Scenes.ContentLoader);
            Assert.IsType <SDLContentLoader>(testGame.Scenes.ContentLoader);
        }
Esempio n. 20
0
 public override void Initialize()
 {
     TypeO.RequireModule <TestModule>(new TypeOEngine.Typedeaf.Core.Engine.Version(2, 2, 2));
 }
Esempio n. 21
0
 public override void LoadExtensions()
 {
     TypeO.AddService <IWindowService, WindowService>();
     TypeO.AddService <IKeyboardInputService, KeyboardInputService>();
     TypeO.AddService <IMouseInputService, MouseInputService>();
 }
Esempio n. 22
0
 public Ordonnance(string recommandations, TypeO typeO)
 {
     Recommandations = recommandations;
     TypeO           = typeO;
     DateC           = DateTime.Now;
 }
Esempio n. 23
0
 public Ordonnance(string recommandations, TypeO typeO, DateTime datec)
 {
     Recommandations = recommandations;
     TypeO           = typeO;
     DateC           = datec;
 }