/**********************************************************/
 /* !@brief      : テクスチャ名からテクスチャを探してオブジェクトにセット
  *  @param[in]  : texName   -> テクスチャ名
  *  @param[in]  : obj       -> テクスチャをセットするオブジェクト
  *  @retval     : bool
  *  @date       : 2014/05/02
  *  @author     : コロソブス(korombus)
  **********************************************************/
 public bool SetTexture(string texName, GameObject obj, string texturePath) {
     if (texName == null || obj == null) { return false; }
     Texture2D tex = GetTexture(texName);
     if (tex == null) {
         CommonResource resource = new CommonResource();
         tex = resource.Load(this, texturePath, typeof(Texture2D)) as Texture2D;
     }
     SetTexture(tex, obj);
     return true;
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //todo : walidacja
            if (textBox1.Text == String.Empty)
                throw new ArgumentException("Wpisz wartości");

            threadGroupOne = new Thread[Convert.ToInt32(this.textBox1.Text)];
            threadGroupTwo = new Thread[Convert.ToInt32(this.textBox2.Text)];

            commonResource = new CommonResource();

            this.startProcess();
        }
Exemplo n.º 3
0
            public Definition(FileDescriptor fileDesc, MessageDescriptor msgDesc, string type, string nameField, CommonResource common, IEnumerable <string> patterns)
            {
                MsgDesc  = msgDesc;
                FileName = fileDesc.Name;
                UnifiedResourceTypeName = type;
                var typeNameParts = type.Split('/');

                if (typeNameParts.Length != 2)
                {
                    throw new InvalidOperationException($"Invalid unified resource name: '{type}' used in message '{msgDesc?.Name}'");
                }
                ShortName = typeNameParts[1];
                FieldName = ShortName.ToLowerCamelCase();
                NameField = string.IsNullOrEmpty(nameField) ? "name" : nameField;
                DocName   = ShortName;
                Patterns  = patterns.Select(x => new Pattern(x)).ToList();
                if (patterns.Distinct().Count() != Patterns.Count)
                {
                    throw new InvalidOperationException("All patterns must be unique within a resource-name.");
                }
                IsCommon        = common != null;
                ResourceNameTyp = IsCommon ?
                                  Typ.Manual(common.CsharpNamespace, common.CsharpClassName) :
                                  Typ.Manual(fileDesc.CSharpNamespace(), $"{ShortName}Name");
                ResourceParserTyp = ResourceNameTyp;
                IsUnparsed        = false;
            }
Exemplo n.º 4
0
        public void MultiLevelTest_Doom2()
        {
            using (var resource = CommonResource.CreateDummy(WadPath.Doom2, @"data\multilevel_test_doom2.wad"))
            {
                var demo = new Demo(@"data\multilevel_test_doom2.lmp");
                var cmds = Enumerable.Range(0, Player.MaxPlayerCount).Select(i => new TicCmd()).ToArray();
                var game = new DoomGame(resource, demo.Options);
                game.DeferedInitNew();

                var lastMobjHash = 0;
                var aggMobjHash  = 0;

                // MAP01
                {
                    for (var i = 0; i < 801; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xc88d8c72u, (uint)lastMobjHash);
                    Assert.AreEqual(0x50d51db4u, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 378; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // MAP02
                {
                    for (var i = 0; i < 334; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xeb24ae67u, (uint)lastMobjHash);
                    Assert.AreEqual(0xa08bf6ceu, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 116; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // MAP03
                {
                    for (var i = 0; i < 653; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xb4d74694u, (uint)lastMobjHash);
                    Assert.AreEqual(0xd813ac0fu, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 131; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // MAP04
                {
                    for (var i = 0; i < 469; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xaf214214u, (uint)lastMobjHash);
                    Assert.AreEqual(0xad054ab5u, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 236; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // MAP05
                {
                    for (var i = 0; i < 312; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xeb01a1fau, (uint)lastMobjHash);
                    Assert.AreEqual(0x0e4e66ffu, (uint)aggMobjHash);
                }
            }
        }
Exemplo n.º 5
0
        public void MultiLevelTest_Doom1()
        {
            using (var resource = CommonResource.CreateDummy(WadPath.Doom1, @"data\multilevel_test_doom1.wad"))
            {
                var demo = new Demo(@"data\multilevel_test_doom1.lmp");
                demo.Options.GameMode = GameMode.Retail;
                var cmds = Enumerable.Range(0, Player.MaxPlayerCount).Select(i => new TicCmd()).ToArray();
                var game = new DoomGame(resource, demo.Options);
                game.DeferedInitNew();

                var lastMobjHash = 0;
                var aggMobjHash  = 0;

                // E1M1
                {
                    for (var i = 0; i < 456; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xd76283ddu, (uint)lastMobjHash);
                    Assert.AreEqual(0x8e50483eu, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 523; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // E1M2
                {
                    for (var i = 0; i < 492; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0x4499dad4u, (uint)lastMobjHash);
                    Assert.AreEqual(0xf2bdb9dfu, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 368; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // E1M3
                {
                    for (var i = 0; i < 424; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0x807bef69u, (uint)lastMobjHash);
                    Assert.AreEqual(0x7fcd8281u, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 28; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // E1M4
                {
                    for (var i = 0; i < 507; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0xd79ad915u, (uint)lastMobjHash);
                    Assert.AreEqual(0x504e3b27u, (uint)aggMobjHash);
                }

                // Intermission
                {
                    for (var i = 0; i < 253; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                    }
                }

                // E1M5
                {
                    for (var i = 0; i < 532; i++)
                    {
                        demo.ReadCmd(cmds);
                        game.Update(cmds);
                        lastMobjHash = DoomDebug.GetMobjHash(game.World);
                        aggMobjHash  = DoomDebug.CombineHash(aggMobjHash, lastMobjHash);
                    }

                    Assert.AreEqual(0x233e5471u, (uint)lastMobjHash);
                    Assert.AreEqual(0xc5060c4eu, (uint)aggMobjHash);
                }
            }
        }
    // Use this for initialization
    void Start()
    {
        // View 初期化
        _handViews = new List <HandView>(NumberOfPlayers);
        for (int i = 0; i < NumberOfPlayers; i++)
        {
            _handViews.Add(Instantiate(_handPrefab).GetComponent <HandView>());
            _handViews[i].transform.position = new Vector3(-22, (i + 1) * -21, 0);
        }

        _commonRes = GameObject.Find("ComRes").GetComponent <CommonResourceView>();

        _bacterias = new List <BacteriaPlaceView>();
        _bacterias.Add(GameObject.Find("bacteria_place_red").GetComponent <BacteriaPlaceView>());
        _bacterias.Add(GameObject.Find("bacteria_place_blue").GetComponent <BacteriaPlaceView>());
        _bacterias.Add(GameObject.Find("bacteria_place_yellow").GetComponent <BacteriaPlaceView>());
        _bacterias.Add(GameObject.Find("bacteria_place_green").GetComponent <BacteriaPlaceView>());
        _bacterias.Add(GameObject.Find("bacteria_place_purple").GetComponent <BacteriaPlaceView>());

        // Model 初期化
        deckModel    = CreateDeck();
        bacteriaSrc  = new BacteriaSource();
        playerModels = new List <Player>();
        for (int index = 0; index < NumberOfPlayers; index++)
        {
            playerModels.Add(new Player());
        }
        resourceModel  = new CommonResource(CommonResourcesCapacity);
        bacteriaPlaces = new List <BacteriaPlace>();
        foreach (ColorElement color in Enum.GetValues(typeof(ColorElement)))
        {
            var place = new BacteriaPlace(color);
            bacteriaPlaces.Add(place);
        }

        bacteriaPlaces[0].LeftSide = bacteriaPlaces[4];
        for (int i = 0; i < bacteriaPlaces.Count; i++)
        {
            bacteriaPlaces[i].RightSide = bacteriaPlaces[i % bacteriaPlaces.Count];
            bacteriaPlaces[i % bacteriaPlaces.Count].LeftSide = bacteriaPlaces[i].RightSide;
            _bacterias[i].bacteriaPlace = bacteriaPlaces[i];
        }

        _ripenerVeiws = new List <List <RipenerView> >();
        for (int i = 0; i < NumberOfPlayers; i++)
        {
            var ripener = new List <RipenerView>();
            for (int j = 0; j < NumberOfRipeners; j++)
            {
                var view = Instantiate(_ripenerPrefab).GetComponent <RipenerView>();
                view.ModelID = playerModels[i].Ripeners[j].ID;
                view.ripener = playerModels[i].Ripeners[j];
                ripener.Add(view);
                ripener[j].transform.position = new Vector3((i + 1) * 32.5f, 7 - (j * 20), 0);
            }
            _ripenerVeiws.Add(ripener);
        }



        Observable.FromCoroutine(PhaseControlMain).Subscribe().AddTo(gameObject);
    }
Exemplo n.º 7
0
        public EditBGView(int currentPage, int lastPage)
        {
            bgView = new View();
            bgView.HeightResizePolicy     = ResizePolicyType.FillToParent;
            bgView.WidthResizePolicy      = ResizePolicyType.FillToParent;
            bgView.ParentOrigin           = Tizen.NUI.ParentOrigin.Center;
            bgView.PivotPoint             = Tizen.NUI.PivotPoint.Center;
            bgView.PositionUsesPivotPoint = true;
            bgView.BackgroundColor        = Color.Black;
            bgView.Scale        = new Vector3(0.9f, 0.9f, 1.0f);
            bgView.CornerRadius = 180.0f;
            this.Add(bgView);

            //this.BackgroundColor = Color.Black;
            this.currentPage = currentPage;
            this.lastPage    = lastPage;

            int screen_size = ApplicationConstants.SCREEN_SIZE_RADIUS * 2;

            Size = new Size(screen_size, screen_size);

            editEfView = new ImageView();
            editEfView.BackgroundImage        = CommonResource.GetResourcePath() + "/b_home_screen_edit_mode_ef.png";
            editEfView.ParentOrigin           = Tizen.NUI.ParentOrigin.Center;
            editEfView.PivotPoint             = Tizen.NUI.PivotPoint.Center;
            editEfView.PositionUsesPivotPoint = true;
            this.Add(editEfView);

            editRightSelectView                        = new ImageView();
            editRightSelectView.Color                  = new Color(0.1f, 0.5f, 0.85f, 1.0f);
            editRightSelectView.BackgroundImage        = CommonResource.GetResourcePath() + "/b_home_screen_edit_mode_ef_r.png";
            editRightSelectView.ParentOrigin           = Tizen.NUI.ParentOrigin.CenterRight;
            editRightSelectView.PivotPoint             = Tizen.NUI.PivotPoint.Center;
            editRightSelectView.PositionUsesPivotPoint = true;
            editRightSelectView.Position               = new Position(20, 0);
            editRightSelectView.TouchEvent            += EditRightSelectView_TouchEvent;

            this.Add(editRightSelectView);

            editLeftSelectView                        = new ImageView();
            editLeftSelectView.Color                  = new Color(0.1f, 0.5f, 0.85f, 1.0f);
            editLeftSelectView.BackgroundImage        = CommonResource.GetResourcePath() + "/b_home_screen_edit_mode_ef_l.png";
            editLeftSelectView.ParentOrigin           = Tizen.NUI.ParentOrigin.CenterLeft;
            editLeftSelectView.PivotPoint             = Tizen.NUI.PivotPoint.Center;
            editLeftSelectView.PositionUsesPivotPoint = true;
            editLeftSelectView.Position               = new Position(-20, 0);
            editLeftSelectView.TouchEvent            += EditLeftSelectView_TouchEvent;
            this.Add(editLeftSelectView);

            Animation ani = new Animation(333);

            ani.AnimateBy(editRightSelectView, "Position", new Position(-20.0f, 0.0f), new AlphaFunction(new Vector2(0.25f, 0.46f), new Vector2(0.45f, 1.0f)));
            ani.AnimateBy(editLeftSelectView, "Position", new Position(20.0f, 0.0f), new AlphaFunction(new Vector2(0.25f, 0.46f), new Vector2(0.45f, 1.0f)));
            ani.Play();

            CheckNextPrevPage(currentPage, lastPage);


            checkingEnterTimer       = new Timer(500);
            checkingEnterTimer.Tick += Timer_Tick;
        }
Exemplo n.º 8
0
        public World(CommonResource resorces, GameOptions options, DoomGame game)
        {
            this.options = options;
            this.game    = game;

            if (game != null)
            {
                this.random = game.Random;
            }
            else
            {
                this.random = new DoomRandom();
            }

            this.map = new Map(resorces, this);

            this.thinkers         = new Thinkers(this);
            this.specials         = new Specials(this);
            this.thingAllocation  = new ThingAllocation(this);
            this.thingMovement    = new ThingMovement(this);
            this.thingInteraction = new ThingInteraction(this);
            this.mapCollision     = new MapCollision(this);
            this.mapInteraction   = new MapInteraction(this);
            this.pathTraversal    = new PathTraversal(this);
            this.hitscan          = new Hitscan(this);
            this.visibilityCheck  = new VisibilityCheck(this);
            this.sectorAction     = new SectorAction(this);
            this.playerBehavior   = new PlayerBehavior(this);
            this.itemPickup       = new ItemPickup(this);
            this.weaponBehavior   = new WeaponBehavior(this);
            this.monsterBehavior  = new MonsterBehavior(this);
            this.lightingChange   = new LightingChange(this);
            this.autoMap          = new AutoMap(this);
            this.cheat            = new Cheat(this);

            options.IntermissionInfo.TotalFrags = 0;
            options.IntermissionInfo.ParTime    = 180;

            for (var i = 0; i < Player.MaxPlayerCount; i++)
            {
                options.Players[i].KillCount   = 0;
                options.Players[i].SecretCount = 0;
                options.Players[i].ItemCount   = 0;
            }

            // Initial height of view will be set by player think.
            options.Players[options.ConsolePlayer].ViewZ = Fixed.Epsilon;

            this.totalKills   = 0;
            this.totalItems   = 0;
            this.totalSecrets = 0;

            this.LoadThings();

            this.statusBar = new StatusBar(this);

            // If deathmatch, randomly spawn the active players.
            if (options.Deathmatch != 0)
            {
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    if (options.Players[i].InGame)
                    {
                        options.Players[i].Mobj = null;
                        this.thingAllocation.DeathMatchSpawnPlayer(i);
                    }
                }
            }

            this.specials.SpawnSpecials();

            this.levelTime    = 0;
            this.doneFirstTic = false;
            this.secretExit   = false;
            this.completed    = false;

            this.validCount = 0;

            this.displayPlayer = options.ConsolePlayer;

            options.Music.StartMusic(Map.GetMapBgm(options), true);
        }
Exemplo n.º 9
0
 public World(CommonResource resorces, GameOptions options)
     : this(resorces, options, null)
 {
 }
Exemplo n.º 10
0
        public SfmlRenderer(Config config, RenderWindow window, CommonResource resource)
        {
            try
            {
                Console.Write("Initialize renderer: ");

                this.config = config;

                config.video_gamescreensize  = Math.Clamp(config.video_gamescreensize, 0, MaxWindowSize);
                config.video_gammacorrection = Math.Clamp(config.video_gammacorrection, 0, MaxGammaCorrectionLevel);

                sfmlWindow = window;
                palette    = resource.Palette;

                sfmlWindowWidth  = (int)window.Size.X;
                sfmlWindowHeight = (int)window.Size.Y;

                if (config.video_highresolution)
                {
                    screen            = new DrawScreen(resource.Wad, 640, 400);
                    sfmlTextureWidth  = 512;
                    sfmlTextureHeight = 1024;
                }
                else
                {
                    screen            = new DrawScreen(resource.Wad, 320, 200);
                    sfmlTextureWidth  = 256;
                    sfmlTextureHeight = 512;
                }

                sfmlTextureData = new byte[4 * screen.Width * screen.Height];

                sfmlTexture = new SFML.Graphics.Texture((uint)sfmlTextureWidth, (uint)sfmlTextureHeight);
                sfmlSprite  = new SFML.Graphics.Sprite(sfmlTexture);

                sfmlSprite.Position = new Vector2f(0, 0);
                sfmlSprite.Rotation = 90;
                var scaleX = (float)sfmlWindowWidth / screen.Width;
                var scaleY = (float)sfmlWindowHeight / screen.Height;
                sfmlSprite.Scale       = new Vector2f(scaleY, -scaleX);
                sfmlSprite.TextureRect = new IntRect(0, 0, screen.Height, screen.Width);

                sfmlStates = new RenderStates(BlendMode.None);

                menu            = new MenuRenderer(resource.Wad, screen);
                threeD          = new ThreeDRenderer(resource, screen, config.video_gamescreensize);
                statusBar       = new StatusBarRenderer(resource.Wad, screen);
                intermission    = new IntermissionRenderer(resource.Wad, screen);
                openingSequence = new OpeningSequenceRenderer(resource.Wad, screen, this);
                autoMap         = new AutoMapRenderer(resource.Wad, screen);
                finale          = new FinaleRenderer(resource, screen);

                pause = Patch.FromWad(resource.Wad, "M_PAUSE");

                var scale = screen.Width / 320;
                wipeBandWidth = 2 * scale;
                wipeBandCount = screen.Width / wipeBandWidth + 1;
                wipeHeight    = screen.Height / scale;
                wipeBuffer    = new byte[screen.Data.Length];

                palette.ResetColors(gammaCorrectionParameters[config.video_gammacorrection]);

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 11
0
        public DoomApplication(IPlatform platform, CommandLineArgs args)
        {
            DoomApplication.Instance = this;

            this.FileSystem = new VirtualFileSystem();

            var wads = this.GetWadPaths(args);

            foreach (var wad in wads)
            {
                this.FileSystem.Add(new WadFileSystem(this.FileSystem.Read(wad)));
            }

            this.config = new Config(platform, "managed-doom.cfg");

            try
            {
                this.config.video_screenwidth  = Math.Clamp(this.config.video_screenwidth, 320, 3200);
                this.config.video_screenheight = Math.Clamp(this.config.video_screenheight, 200, 2000);

                this.window = platform.CreateWindow(ApplicationInfo.Title, this.config);
                this.window.Clear(Color.FromArgb(64, 64, 64));
                this.window.Display();

                this.Resource = new CommonResource();

                this.renderer = platform.CreateRenderer(this.config, this.window, this.Resource);

                if (!args.nosound.Present && !args.nosfx.Present)
                {
                    this.sound = platform.CreateSound(this.config);
                }

                if (!args.nosound.Present && !args.nomusic.Present)
                {
                    this.music = platform.CreateMusic(this.config);
                }

                this.userInput = platform.CreateUserInput(this.config, this.window, args.nomouse.Present);

                this.events = new List <DoomEvent>();

                this.options           = new GameOptions();
                this.options.Renderer  = this.renderer;
                this.options.Sound     = this.sound;
                this.options.Music     = this.music;
                this.options.UserInput = this.userInput;

                this.menu = new DoomMenu(this);

                this.opening = new OpeningSequence(this.options);

                this.cmd = new TicCmd();

                this.game = new DoomGame(this.Resource, this.options);

                this.wipe   = new WipeEffect(this.renderer.WipeBandCount, this.renderer.WipeHeight);
                this.wiping = false;

                this.currentState = ApplicationState.None;
                this.nextState    = ApplicationState.Opening;
                this.needWipe     = false;

                this.sendPause = false;

                this.quit        = false;
                this.quitMessage = null;

                this.CheckGameArgs(args);

                this.window.Closed      += (sender, e) => this.window.Close();
                this.window.KeyPressed  += this.KeyPressed;
                this.window.KeyReleased += this.KeyReleased;

                this.window.SetFramerateLimit(35);
            }
            catch (Exception e)
            {
                this.Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 12
0
 public IRenderer CreateRenderer(Config config, IWindow window, CommonResource resource)
 {
     return(new SfmlRenderer(config, (SfmlWindow)window, resource));
 }
Exemplo n.º 13
0
        public async Task <IActionResult> AddNewStorage([Bind("StorageId, CommonResourceId, CommonResource, OwnerId, StorageName, StorageType, Products")] Storage storage, string commonResourceId, string commonResourceName)
        {
            // Probably overcomplicated, split into functions at some point
            if (string.IsNullOrEmpty(storage.StorageName) || (string.IsNullOrEmpty(commonResourceId) && string.IsNullOrEmpty(commonResourceName)))
            {
                var error = new ErrorViewModel()
                {
                    ErrorMessage = "Error 11: Storage name empty or common resource not set/empty."
                };
                return(RedirectToAction("Index", "Error", error));
            }
            //get user and she's/he's CommonResources from database
            var user = await _appUserContext.ApplicationUser.Where(u => u.Id == _user.GetUserId(HttpContext.User))
                       .Include(u => u.UserCommonResource)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                var error = new ErrorViewModel()
                {
                    ErrorMessage = "Error 10: unable to get user's data"
                };
                return(RedirectToAction("Index", "Error", error));
            }

            storage.OwnerId = user.Id;

            CommonResource common;

            //if commonResourceId specified, get it from database, add storage
            if (!string.IsNullOrEmpty(commonResourceId))
            {
                common = await _appUserContext.CommonResources.Where(c => c.CommonResourceId == commonResourceId)
                         .Include(c => c.Storages)
                         .FirstOrDefaultAsync();

                if (common == null)
                {
                    var error = new ErrorViewModel()
                    {
                        ErrorMessage = "Error 13"
                    };
                    return(RedirectToAction("Index", "Error", error));
                }
                common.Storages.Add(storage);
                _appUserContext.CommonResources.Update(common);
                _appUserContext.SaveChanges();
                return(RedirectToAction("Index", "Storage"));
            }

            //if commonResourceId is not specified
            common = new CommonResource
            {
                CommonResourceName = commonResourceName,
                OwnerId            = user.Id
            };
            common.Storages.Add(storage);
            var join = new UserCommonResource
            {
                UserCommonResourceId = null, //autogenerated by database
                UserId           = user.Id,
                User             = user,
                CommonResourceId = common.CommonResourceId,
                CommonResource   = common
            };

            user.UserCommonResource.Add(join);

            _appUserContext.ApplicationUser.Update(user);
            await _appUserContext.SaveChangesAsync();

            return(RedirectToAction("Index", "Storage"));
        }
Exemplo n.º 14
0
 public Map(CommonResource resorces, World world)
     : this(resorces.Textures, resorces.Flats, resorces.Animation, world)
 {
 }