Пример #1
0
        public void CheckIPCLocation()
        {
            // don't use clean run because files are being written before osu! launches.
            using (var host = new TestRunHeadlessGameHost(nameof(CheckIPCLocation), null))
            {
                string basePath = Path.Combine(host.UserStoragePaths.First(), nameof(CheckIPCLocation));

                // Set up a fake IPC client for the IPC Storage to switch to.
                string testStableInstallDirectory = Path.Combine(basePath, "stable-ce");
                Directory.CreateDirectory(testStableInstallDirectory);

                string ipcFile = Path.Combine(testStableInstallDirectory, "ipc.txt");
                File.WriteAllText(ipcFile, string.Empty);

                try
                {
                    var osu = LoadTournament(host);
                    TournamentStorage storage = (TournamentStorage)osu.Dependencies.Get <Storage>();
                    FileBasedIPC      ipc     = null;

                    WaitForOrAssert(() => (ipc = osu.Dependencies.Get <MatchIPCInfo>() as FileBasedIPC)?.IsLoaded == true, @"ipc could not be populated in a reasonable amount of time");

                    Assert.True(ipc.SetIPCLocation(testStableInstallDirectory));
                    Assert.True(storage.AllTournaments.Exists("stable.json"));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Пример #2
0
        private void load(Storage storage, FrameworkConfigManager frameworkConfig)
        {
            Resources.AddStore(new DllResourceStore(@"osu.Game.Tournament.dll"));

            Fonts.AddStore(new GlyphStore(Resources, @"Resources/Fonts/Aquatico-Regular"));
            Fonts.AddStore(new GlyphStore(Resources, @"Resources/Fonts/Aquatico-Light"));

            Textures.AddStore(new TextureLoaderStore(new ResourceStore <byte[]>(new StorageBackedResourceStore(storage))));

            this.storage = storage;

            windowSize = frameworkConfig.GetBindable <Size>(FrameworkSetting.WindowedSize);

            readBracket();

            ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);

            dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
            Add(ipc);

            Add(new OsuButton
            {
                Text    = "Save Changes",
                Width   = 140,
                Height  = 50,
                Depth   = float.MinValue,
                Anchor  = Anchor.BottomRight,
                Origin  = Anchor.BottomRight,
                Padding = new MarginPadding(10),
                Action  = SaveChanges,
            });
        }
Пример #3
0
        private void load(Storage storage)
        {
            Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly));

            dependencies.CacheAs(tournamentStorage = new TournamentStorage(storage));

            Textures.AddStore(new TextureLoaderStore(tournamentStorage));

            this.storage = storage;

            readBracket();

            ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);

            dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
            Add(ipc);
        }
Пример #4
0
        private void load(Storage storage, FrameworkConfigManager frameworkConfig)
        {
            Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly));

            dependencies.CacheAs(tournamentStorage = new TournamentStorage(storage));

            Textures.AddStore(new TextureLoaderStore(tournamentStorage));

            this.storage = storage;

            windowSize = frameworkConfig.GetBindable <Size>(FrameworkSetting.WindowedSize);
            windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
            {
                var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;

                heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
            }), true);

            readBracket();

            ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);

            dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
            Add(ipc);

            AddRange(new[]
            {
                new Container
                {
                    CornerRadius = 10,
                    Depth        = float.MinValue,
                    Position     = new Vector2(5),
                    Masking      = true,
                    AutoSizeAxes = Axes.Both,
                    Anchor       = Anchor.BottomRight,
                    Origin       = Anchor.BottomRight,
                    Children     = new Drawable[]
                    {
                        new Box
                        {
                            Colour           = OsuColour.Gray(0.2f),
                            RelativeSizeAxes = Axes.Both,
                        },
                        new TourneyButton
                        {
                            Text    = "Save Changes",
                            Width   = 140,
                            Height  = 50,
                            Padding = new MarginPadding
                            {
                                Top  = 10,
                                Left = 10,
                            },
                            Margin = new MarginPadding
                            {
                                Right  = 10,
                                Bottom = 10,
                            },
                            Action = SaveChanges,
                        },
                    }
                },
                heightWarning = new Container
                {
                    Masking      = true,
                    CornerRadius = 5,
                    Depth        = float.MinValue,
                    Anchor       = Anchor.Centre,
                    Origin       = Anchor.Centre,
                    AutoSizeAxes = Axes.Both,
                    Children     = new Drawable[]
                    {
                        new Box
                        {
                            Colour           = Color4.Red,
                            RelativeSizeAxes = Axes.Both,
                        },
                        new TournamentSpriteText
                        {
                            Text    = "Please make the window wider",
                            Font    = OsuFont.Torus.With(weight: FontWeight.Bold),
                            Colour  = Color4.White,
                            Padding = new MarginPadding(20)
                        }
                    }
                },
            });
        }
Пример #5
0
        private void load(Storage storage, FrameworkConfigManager frameworkConfig)
        {
            Resources.AddStore(new DllResourceStore(@"osu.Game.Tournament.dll"));

            AddFont(Resources, @"Resources/Fonts/Aquatico-Regular");
            AddFont(Resources, @"Resources/Fonts/Aquatico-Light");

            Textures.AddStore(new TextureLoaderStore(new ResourceStore <byte[]>(new StorageBackedResourceStore(storage))));

            this.storage = storage;

            windowSize = frameworkConfig.GetBindable <Size>(FrameworkSetting.WindowedSize);
            windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
            {
                var minWidth = (int)(size.NewValue.Height / 9f * 16 + 400);

                heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
            }), true);

            readBracket();

            ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);

            dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
            Add(ipc);

            AddRange(new[]
            {
                new TourneyButton
                {
                    Text    = "Save Changes",
                    Width   = 140,
                    Height  = 50,
                    Depth   = float.MinValue,
                    Anchor  = Anchor.BottomRight,
                    Origin  = Anchor.BottomRight,
                    Padding = new MarginPadding(10),
                    Action  = SaveChanges,
                },
                heightWarning = new Container
                {
                    Masking      = true,
                    CornerRadius = 5,
                    Depth        = float.MinValue,
                    Anchor       = Anchor.Centre,
                    Origin       = Anchor.Centre,
                    AutoSizeAxes = Axes.Both,
                    Children     = new Drawable[]
                    {
                        new Box
                        {
                            Colour           = Color4.Red,
                            RelativeSizeAxes = Axes.Both,
                        },
                        new OsuSpriteText
                        {
                            Text    = "Please make the window wider",
                            Font    = OsuFont.Default.With(weight: "bold"),
                            Colour  = Color4.White,
                            Padding = new MarginPadding(20)
                        }
                    }
                },
            });
        }
Пример #6
0
        private void readBracket()
        {
            if (storage.Exists(bracket_filename))
            {
                using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
                    using (var sr = new StreamReader(stream))
                        ladder = JsonConvert.DeserializeObject <LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
            }

            ladder ??= new LadderInfo();
            ladder.Ruleset.Value ??= RulesetStore.AvailableRulesets.First();

            bool addedInfo = false;

            // assign teams
            foreach (var match in ladder.Matches)
            {
                match.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team1Acronym);
                match.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team2Acronym);

                foreach (var conditional in match.ConditionalMatches)
                {
                    conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
                    conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
                    conditional.Round.Value = match.Round.Value;
                }
            }

            // assign progressions
            foreach (var pair in ladder.Progressions)
            {
                var src  = ladder.Matches.FirstOrDefault(p => p.ID == pair.SourceID);
                var dest = ladder.Matches.FirstOrDefault(p => p.ID == pair.TargetID);

                if (src == null)
                {
                    continue;
                }

                if (dest != null)
                {
                    if (pair.Losers)
                    {
                        src.LosersProgression.Value = dest;
                    }
                    else
                    {
                        src.Progression.Value = dest;
                    }
                }
            }

            // link matches to rounds
            foreach (var round in ladder.Rounds)
            {
                foreach (var id in round.Matches)
                {
                    var found = ladder.Matches.FirstOrDefault(p => p.ID == id);

                    if (found != null)
                    {
                        found.Round.Value = round;
                        if (round.StartDate.Value > found.Date.Value)
                        {
                            found.Date.Value = round.StartDate.Value;
                        }
                    }
                }
            }

            addedInfo |= addPlayers();
            addedInfo |= addBeatmaps();

            if (addedInfo)
            {
                SaveChanges();
            }

            ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);

            Schedule(() =>
            {
                Ruleset.BindTo(ladder.Ruleset);

                dependencies.Cache(ladder);
                dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
                Add(ipc);

                taskCompletionSource.SetResult(true);
            });
        }
Пример #7
0
        private void readBracket()
        {
            try
            {
                if (storage.Exists(BRACKET_FILENAME))
                {
                    using (Stream stream = storage.GetStream(BRACKET_FILENAME, FileAccess.Read, FileMode.Open))
                        using (var sr = new StreamReader(stream))
                            ladder = JsonConvert.DeserializeObject <LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
                }

                ladder ??= new LadderInfo();

                var resolvedRuleset = ladder.Ruleset.Value != null
                    ? RulesetStore.GetRuleset(ladder.Ruleset.Value.ShortName)
                    : RulesetStore.AvailableRulesets.First();

                // Must set to null initially to avoid the following re-fetch hitting `ShortName` based equality check.
                ladder.Ruleset.Value = null;
                ladder.Ruleset.Value = resolvedRuleset;

                bool addedInfo = false;

                // assign teams
                foreach (var match in ladder.Matches)
                {
                    match.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team1Acronym);
                    match.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team2Acronym);

                    foreach (var conditional in match.ConditionalMatches)
                    {
                        conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
                        conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
                        conditional.Round.Value = match.Round.Value;
                    }
                }

                // assign progressions
                foreach (var pair in ladder.Progressions)
                {
                    var src  = ladder.Matches.FirstOrDefault(p => p.ID == pair.SourceID);
                    var dest = ladder.Matches.FirstOrDefault(p => p.ID == pair.TargetID);

                    if (src == null)
                    {
                        continue;
                    }

                    if (dest != null)
                    {
                        if (pair.Losers)
                        {
                            src.LosersProgression.Value = dest;
                        }
                        else
                        {
                            src.Progression.Value = dest;
                        }
                    }
                }

                // link matches to rounds
                foreach (var round in ladder.Rounds)
                {
                    foreach (int id in round.Matches)
                    {
                        var found = ladder.Matches.FirstOrDefault(p => p.ID == id);

                        if (found != null)
                        {
                            found.Round.Value = round;
                            if (round.StartDate.Value > found.Date.Value)
                            {
                                found.Date.Value = round.StartDate.Value;
                            }
                        }
                    }
                }

                addedInfo |= addPlayers();
                addedInfo |= addRoundBeatmaps();
                addedInfo |= addSeedingBeatmaps();

                if (addedInfo)
                {
                    SaveChanges();
                }

                ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
            }
            catch (Exception e)
            {
                bracketLoadTaskCompletionSource.SetException(e);
                return;
            }

            Schedule(() =>
            {
                Ruleset.BindTo(ladder.Ruleset);

                dependencies.Cache(ladder);
                dependencies.CacheAs <MatchIPCInfo>(ipc = new FileBasedIPC());
                Add(ipc);

                bracketLoadTaskCompletionSource.SetResult(true);

                initialisationText.Expire();
            });
        }