public NscLayer(ClientResourceLocator?resourceLocator = null, string?layerPath = null, params object[] args) : base(resourceLocator ?? ClientSkinService.CurrentlySelectedSkin, layerPath, args) { m_script["AutoPlayTargets"] = typeof(AutoPlayTargets); m_script["HiSpeedMod"] = typeof(HiSpeedMod); m_script["nsc"] = tblNsc = m_script.NewTable(); tblNsc["charts"] = tblNscCharts = m_script.NewTable(); tblNsc["input"] = tblNscInput = m_script.NewTable(); //tblNsc["pushGameplay"] = (Action<ChartInfoHandle>)(chartInfo => Push(new GameLayer(ResourceLocator, chartInfo, AutoPlayTargets.None))); tblNsc["pushGameplay"] = DynValue.NewCallback((context, args) => { if (args.Count == 0) { throw new ScriptRuntimeException("Chart info expected for pushGameplay."); } args = args.SkipMethodCall(); ChartInfoHandle chartInfo = args.AsUserData <ChartInfoHandle>(0, "pushGameplay");; var autoPlay = AutoPlayTargets.None; if (args.Count >= 2) { autoPlay = args.AsUserData <AutoPlayTargets>(1, "pushGameplay"); } var layer = new GameLayer(ResourceLocator, chartInfo, autoPlay); Push(layer); return(DynValue.Void); }); tblNscCharts["scanForKshCharts"] = (Action)(() => { Client.DatabaseWorker.SetToPopulate(); }); tblNscInput["getController"] = (Func <Controller>)(() => Input.Controller); }
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); }