Ejemplo n.º 1
0
        public override void Initialize()
        {
            base.Initialize();
            playback    = new SlidingChartPlayback(BimsChartFactory.Instance.TestChart());
            highwayView = new HighwayView(playback, 50, 0);

            playback.DefaultViewTime         = 4 * 60.0 / 120;
            playback.ObjectHeadCrossPrimary += (dir, entity) =>
            {
                if (entity is NoteEntity note)
                {
                    highwayView.renderableEntities[entity.Lane].Add(note);
                }
            };
            playback.ObjectHeadCrossSecondary += (dir, entity) =>
            {
                if (entity is NoteEntity note)
                {
                    highwayView.renderableEntities[entity.Lane].Remove(note);
                }
            };
            playback.Position = 0;

            Controller.Instance().ButtonPressed  = OnControllerButtonPressed;
            Controller.Instance().ButtonReleased = OnControllerButtonReleased;
        }
Ejemplo n.º 2
0
        public override void Init()
        {
            base.Init();

            m_highwayControl = new HighwayControl(HighwayControlConfig.CreateDefaultKsh168());
            m_background.Init();

            m_playback = new SlidingChartPlayback(m_chart);
            m_playback.ObjectHeadCrossPrimary += (dir, obj) =>
            {
                if (dir == PlayDirection.Forward)
                {
                    m_highwayView.RenderableObjectAppear(obj);
                }
                else
                {
                    m_highwayView.RenderableObjectDisappear(obj);
                }
            };
            m_playback.ObjectTailCrossSecondary += (dir, obj) =>
            {
                if (dir == PlayDirection.Forward)
                {
                    m_highwayView.RenderableObjectDisappear(obj);
                }
                else
                {
                    m_highwayView.RenderableObjectAppear(obj);
                }
            };

            // TODO(local): Effects wont work with backwards motion, but eventually the
            //  editor (with the only backwards motion support) will pre-render audio instead.
            m_playback.ObjectHeadCrossCritical += (dir, obj) =>
            {
                if (dir != PlayDirection.Forward)
                {
                    return;
                }

                if (obj is ChartEvent evt)
                {
                    PlaybackEventTrigger(evt, dir);
                }
                else
                {
                    PlaybackObjectBegin(obj);
                }
            };
            m_playback.ObjectTailCrossCritical += (dir, obj) =>
            {
                if (dir == PlayDirection.Backward && obj is ChartEvent evt)
                {
                    PlaybackEventTrigger(evt, dir);
                }
                else
                {
                    PlaybackObjectEnd(obj);
                }
            };

            m_highwayView.ViewDuration = m_playback.LookAhead;

            ForegroundGui = new Panel()
            {
                Children = new GuiElement[]
                {
                    m_critRoot     = new CriticalLine(m_resources),
                    m_comboDisplay = new ComboDisplay(m_resources)
                    {
                        RelativePositionAxes = Axes.Both,
                        Position             = new Vector2(0.5f, 0.7f)
                    },
                }
            };

            m_judge = new MasterJudge(m_chart);
            for (int i = 0; i < 6; i++)
            {
                int stream = i;

                var judge = (ButtonJudge)m_judge[i];
                //judge.JudgementOffset = 0.032;
                judge.JudgementOffset  = Plugin.Config.GetInt(NscConfigKey.InputOffset) / 1000.0f;
                judge.AutoPlay         = AutoButtons;
                judge.OnChipPressed   += Judge_OnChipPressed;
                judge.OnTickProcessed += Judge_OnTickProcessed;
                judge.OnHoldPressed   += Judge_OnHoldPressed;
                judge.OnHoldReleased  += Judge_OnHoldReleased;
            }

            m_highwayControl = new HighwayControl(HighwayControlConfig.CreateDefaultKsh168());
            m_highwayView.Reset();

            m_audio.Volume    = 0.8f;
            m_audio.Position  = m_chart.Offset;
            m_audioController = new AudioEffectController(8, m_audio, true)
            {
                RemoveFromChannelOnFinish = true,
            };
            m_audioController.Finish += () =>
            {
                Logger.Log("track complete");
                Host.PopToParent(this);
            };

            time_t firstObjectTime = double.MaxValue;

            for (int s = 0; s < m_chart.StreamCount; s++)
            {
                firstObjectTime = MathL.Min((double)firstObjectTime, m_chart.ObjectStreams[s].FirstObject?.AbsolutePosition.Seconds ?? double.MaxValue);
            }

            m_audioController.Position = MathL.Min(0.0, (double)firstObjectTime - 2);
            m_audioController.Play();
        }
Ejemplo n.º 3
0
        public override bool AsyncLoad()
        {
            m_script["game"]    = m_gameTable = m_script.NewTable();
            m_script["scoring"] = m_scoringTable = m_script.NewTable();
            //m_script["game"] = m_gameTable;
            m_gameTable["chart"] = new ChartInfoHandle(new ChartSetInfoHandle(m_resources, m_script, Client.DatabaseWorker, m_chartInfo.Set), m_chartInfo);

            if (!base.AsyncLoad())
            {
                return(false);
            }

            string chartsDir = TheoriConfig.ChartsDirectory;
            var    setInfo   = m_chartInfo.Set;

            if (m_chart == null)
            {
                if (ChartDatabaseService.TryLoadChart(m_chartInfo) is Chart chart)
                {
                    m_chart = chart;

                    string audioFile = Path.Combine(chartsDir, setInfo.FilePath, m_chart.Info.SongFileName);
                    m_audio         = AudioTrack.FromFile(audioFile);
                    m_audio.Channel = Mixer.MasterChannel;
                    m_audio.Volume  = m_chart.Info.SongVolume / 100.0f;
                }
                else
                {
                    Logger.Log($"Failed to load chart {m_chartInfo.SongTitle}");

                    Pop();
                    return(false);
                }
            }

            m_audioPlayback  = new SlidingChartPlayback(m_chart, false);
            m_visualPlayback = new SlidingChartPlayback(m_chart, true);

            m_highwayView = new HighwayView(m_locator, m_visualPlayback);
            //m_script = new ScriptProgram(m_locator);

#if false
            m_gameTable["meta"]    = m_metaTable = m_script.NewTable();
            m_gameTable["scoring"] = m_scoringTable = m_script.NewTable();

            m_metaTable["songTitle"]  = m_chart.Info.SongTitle;
            m_metaTable["songArtist"] = m_chart.Info.SongArtist;

            m_metaTable["difficultyName"]      = m_chart.Info.DifficultyName;
            m_metaTable["difficultyNameShort"] = m_chart.Info.DifficultyNameShort;
            m_metaTable["difficultyLevel"]     = m_chart.Info.DifficultyLevel;
            m_metaTable["difficultyColor"]     = (m_chart.Info.DifficultyColor ?? new Vector3(1, 1, 1)) * 255;
#endif

            //m_guiScript.LoadFile(m_locator.OpenFileStream("scripts/generic-layer.lua"));
            //m_script.LoadFile(m_locator.OpenFileStream("scripts/game/main.lua")!, "scripts/game/main.lua");

            //if (!m_script.LuaAsyncLoad()) return false;

            if (!m_highwayView.AsyncLoad())
            {
                return(false);
            }
            if (!m_background.AsyncLoad())
            {
                return(false);
            }

            m_slamSample = m_resources.QueueAudioLoad("audio/slam");

            m_hitSounds["clap"]        = m_resources.QueueAudioLoad("audio/sample_clap");
            m_hitSounds["clap_punchy"] = m_resources.QueueAudioLoad("audio/sample_clap");
            m_hitSounds["clap_impact"] = m_resources.QueueAudioLoad("audio/sample_kick");
            m_hitSounds["snare"]       = m_resources.QueueAudioLoad("audio/sample_snare");
            m_hitSounds["snare_lo"]    = m_resources.QueueAudioLoad("audio/sample_snare_lo");

            foreach (var lane in m_chart.Lanes)
            {
                foreach (var entity in lane)
                {
                    switch (entity)
                    {
                    case ButtonEntity button:
                    {
                        if (!button.HasSample)
                        {
                            break;
                        }

                        if (!m_hitSounds.ContainsKey(button.Sample))
                        {
                            string samplePath = Path.Combine(chartsDir, setInfo.FilePath, button.Sample);
                            if (!File.Exists(samplePath))
                            {
                                break;
                            }

                            var sample = AudioTrack.FromFile(samplePath);
                            m_resources.Manage(sample);

                            m_hitSounds[button.Sample] = sample;
                        }
                    } break;
                    }
                }
            }

            ForegroundGui = new Panel()
            {
                Children = new GuiElement[]
                {
                    m_critRootUi    = new CriticalLineUi(m_resources),
                    m_critRootWorld = new CriticalLineWorld(m_resources),

                    m_comboDisplay = new ComboDisplay(m_resources)
                    {
                        RelativePositionAxes = Axes.Both,
                        Position             = new Vector2(0.5f, 0.7f)
                    },
                }
            };

            if (!m_critRootUi.AsyncLoad())
            {
                return(false);
            }
            if (!m_critRootWorld.AsyncLoad())
            {
                return(false);
            }
            if (!m_comboDisplay.AsyncLoad())
            {
                return(false);
            }

            if (!m_resources.LoadAll())
            {
                return(false);
            }

            return(true);
        }