public PlayerProfile(ProfileLoader loader, String playerpath, String stagepath) { if (playerpath == null) { throw new ArgumentNullException("playerpath"); } if (loader == null) { throw new ArgumentNullException("loader"); } m_loader = loader; //May be null m_playerstagepath = stagepath; IO.TextFile textfile = m_loader.SubSystems.GetSubSystem <IO.FileSystem>().OpenTextFile(playerpath); TextSection infosection = textfile.GetSection("info"); if (infosection == null) { throw new InvalidOperationException("No 'info' section in .def file"); } TextSection filesection = textfile.GetSection("files"); if (filesection == null) { throw new InvalidOperationException("No 'files' section in .def file"); } m_defpath = playerpath; m_basepath = Path.GetDirectoryName(textfile.Filepath); m_playername = infosection.GetAttribute <String>("name", String.Empty); m_displayname = infosection.GetAttribute <String>("displayname", m_playername); m_author = infosection.GetAttribute <String>("author", String.Empty); m_version = infosection.GetAttribute <String>("versiondate", String.Empty); m_mugenversion = infosection.GetAttribute <String>("mugenversion", String.Empty); m_paletteorder = BuildPaletteOrder(infosection.GetAttribute <String>("pal.defaults", null)); m_commandfile = FilterPath(filesection.GetAttribute <String>("cmd", String.Empty)); m_constantsfile = FilterPath(filesection.GetAttribute <String>("cns", String.Empty)); m_commonstatefile = GetCommonStateFile(filesection.GetAttribute <String>("stcommon")); m_statesfiles = BuildStateFiles(filesection); m_spritesfile = FilterPath(filesection.GetAttribute <String>("sprite", String.Empty)); m_animationfile = FilterPath(filesection.GetAttribute <String>("anim", String.Empty)); m_soundfile = FilterPath(filesection.GetAttribute <String>("sound", String.Empty)); m_palettefiles = BuildPaletteFiles(filesection); m_spritemanager = m_loader.SubSystems.GetSubSystem <Drawing.SpriteSystem>().CreateManager(SpritePath); SpriteManager.GetSprite(SpriteId.LargePortrait); SpriteManager.GetSprite(SpriteId.SmallPortrait); }
/// <summary> /// Creates Animations from a xnaMugen.IO.TextFile. /// </summary> /// <param name="textfile">A textfile whose xnaMugen.IO.TextSection can be used to create Animations.</param> /// <returns>A collection of Animations created from the supplied textfile.</returns> public KeyedCollection<Int32, Animation> LoadAnimations(TextFile textfile) { if (textfile == null) throw new ArgumentNullException("textfile"); KeyedCollection<Int32, Animation> animations = new KeyedCollection<Int32, Animation>(x => x.Number); foreach (TextSection section in textfile) { Animation animation = CreateAnimation(section); if (animation != null) { if (animations.Contains(animation.Number) == false) { animations.Add(animation); } else { Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Duplicate animation #{0}. Discarding duplicate.", animation.Number); } } } return animations; }
public void LoadBackgrounds(String prefix, TextFile textfile) { if (prefix == null) throw new ArgumentNullException("prefix"); if (textfile == null) throw new ArgumentNullException("textfile"); Regex regex = new Regex("^" + prefix + "BG (.*)$", RegexOptions.IgnoreCase); foreach (TextSection section in textfile) { Match match = regex.Match(section.Title); if (match.Success == true) { m_backgrounds.CreateBackground(section); } } m_backgrounds.Reset(); }
public override void Initialize() { IO.TextFile inifile = LoadIniFile(); IO.TextSection videosettings = inifile.GetSection("Video Settings"); if (videosettings != null) { m_screensize = videosettings.GetAttribute <Point>("ScreenSize", m_screensize); m_useoldshader = videosettings.GetAttribute <Boolean>("UseOldShader", m_useoldshader); m_vsync = videosettings.GetAttribute <Boolean>("VSync", m_vsync); m_screenshotformat = videosettings.GetAttribute <ScreenShotFormat>("ScreenShotFormat", m_screenshotformat); } IO.TextSection replaysettings = inifile.GetSection("Replay Settings"); if (replaysettings != null) { m_recordreplay = replaysettings.GetAttribute <Boolean>("RecordReplay", m_recordreplay); m_quitafterreplay = replaysettings.GetAttribute <Boolean>("QuitAfterReplay", m_quitafterreplay); } IO.TextSection debugsettings = inifile.GetSection("Debug Settings"); if (debugsettings != null) { m_diagonsticwindow = debugsettings.GetAttribute <Boolean>("ShowDiagnosticWindow", m_diagonsticwindow); m_keeplog = debugsettings.GetAttribute <Boolean>("Keep Log", m_keeplog); } IO.TextSection gamesettings = inifile.GetSection("Game Settings"); if (gamesettings != null) { m_preloadsprites = gamesettings.GetAttribute <Boolean>("PreloadCharacterSprites", m_preloadsprites); m_roundlength = gamesettings.GetAttribute <Int32>("RoundLength", m_roundlength); m_soundchannels = gamesettings.GetAttribute <Int32>("SoundChannels", m_soundchannels); } IO.TextSection systemkeys = inifile.GetSection("System Keys"); if (systemkeys != null) { foreach (SystemButton systembutton in Enum.GetValues(typeof(SystemButton))) { if (systembutton == SystemButton.None) { continue; } Keys key = systemkeys.GetAttribute <Keys>(systembutton.ToString(), Keys.None); if (key == Keys.None) { continue; } m_systemkeys.Add(systembutton, key); } } IO.TextSection p1keys = inifile.GetSection("Player 1 Keys"); if (p1keys != null) { foreach (PlayerButton playerbutton in Enum.GetValues(typeof(PlayerButton))) { if (playerbutton == PlayerButton.None) { continue; } Keys key = p1keys.GetAttribute <Keys>(playerbutton.ToString(), Keys.None); if (key == Keys.None) { continue; } m_p1keys.Add(playerbutton, key); } } IO.TextSection p2keys = inifile.GetSection("Player 2 Keys"); if (p2keys != null) { foreach (PlayerButton playerbutton in Enum.GetValues(typeof(PlayerButton))) { if (playerbutton == PlayerButton.None) { continue; } Keys key = p2keys.GetAttribute <Keys>(playerbutton.ToString(), Keys.None); if (key == Keys.None) { continue; } m_p2keys.Add(playerbutton, key); } } #if TEST m_screensize = Mugen.ScreenSize * 3; #endif }
public PlayerConstants(Player player, TextFile textfile) { if (player == null) throw new ArgumentNullException("player"); if (textfile == null) throw new ArgumentNullException("textfile"); TextSection datasection = textfile.GetSection("Data"); TextSection sizesection = textfile.GetSection("Size"); TextSection velocitysection = textfile.GetSection("Velocity"); TextSection movementsection = textfile.GetSection("Movement"); StringConverter converter = player.Engine.GetSubSystem<StringConverter>(); if (datasection == null) throw new ArgumentException("Constants file '" + textfile.Filepath + "' does not have a 'Data' section"); if (sizesection == null) throw new ArgumentException("Constants file '" + textfile.Filepath + "' does not have a 'Size' section"); if (velocitysection == null) throw new ArgumentException("Constants file '" + textfile.Filepath + "' does not have a 'Velocity' section"); if (movementsection == null) throw new ArgumentException("Constants file '" + textfile.Filepath + "' does not have a 'Movement' section"); m_scale = new Vector2(1, 1); m_life = datasection.GetAttribute<Int32>("life", 1000); m_maxpower = datasection.GetAttribute<Int32>("power", 3000); m_attackpower = datasection.GetAttribute<Int32>("attack", 100); m_defensivepower = datasection.GetAttribute<Int32>("defence", 100); m_falldefenseincrease = datasection.GetAttribute<Int32>("fall.defence_up", 50); m_liedowntime = datasection.GetAttribute<Int32>("liedown.time", 60); m_airjuggle = datasection.GetAttribute<Int32>("airjuggle", 15); m_defaultspark = datasection.GetAttribute<Evaluation.PrefixedExpression>("sparkno", null); m_defaultguardspark = datasection.GetAttribute<Evaluation.PrefixedExpression>("guard.sparkno", null); m_KOecho = datasection.GetAttribute<Boolean>("KO.echo", false); m_volumeoffset = datasection.GetAttribute<Int32>("volume", 0); m_persistanceintindex = datasection.GetAttribute<Int32>("IntPersistIndex", 60); m_persistancefloatindex = datasection.GetAttribute<Int32>("FloatPersistIndex", 40); m_scale.X = sizesection.GetAttribute<Single>("xscale", 1.0f); m_scale.Y = sizesection.GetAttribute<Single>("yscale", 1.0f); m_groundback = sizesection.GetAttribute<Int32>("ground.back", 15); m_groundfront = sizesection.GetAttribute<Int32>("ground.front", 16); m_airback = sizesection.GetAttribute<Int32>("air.back", 12); m_airfront = sizesection.GetAttribute<Int32>("air.front", 12); m_height = sizesection.GetAttribute<Int32>("height", 60); m_attackdistance = sizesection.GetAttribute<Int32>("attack.dist", 160); m_projectileattackdist = sizesection.GetAttribute<Int32>("proj.attack.dist", 90); m_projectilescaling = sizesection.GetAttribute<Boolean>("proj.doscale", false); m_headposition = sizesection.GetAttribute<Vector2>("head.pos", Vector2.Zero); m_midposition = sizesection.GetAttribute<Vector2>("mid.pos", Vector2.Zero); m_shadowoffset = sizesection.GetAttribute<Int32>("shadowoffset", 0); m_drawoffset = sizesection.GetAttribute<Point>("draw.offset", new Point(0, 0)); m_walk_forward = velocitysection.GetAttribute<Single>("walk.fwd"); m_walk_back = velocitysection.GetAttribute<Single>("walk.back"); m_run_fwd = velocitysection.GetAttribute<Vector2>("run.fwd"); m_run_back = velocitysection.GetAttribute<Vector2>("run.back"); m_jump_neutral = velocitysection.GetAttribute<Vector2>("jump.neu"); m_jump_back = velocitysection.GetAttribute<Vector2>("jump.back"); if (m_jump_back.Y == 0) m_jump_back.Y = m_jump_neutral.Y; m_jump_forward = velocitysection.GetAttribute<Vector2>("jump.fwd"); if (m_jump_forward.Y == 0) m_jump_forward.Y = m_jump_neutral.Y; m_runjump_back = velocitysection.GetAttribute<Vector2>("runjump.back", m_run_back); m_runjump_fwd = velocitysection.GetAttribute<Vector2>("runjump.fwd", m_run_fwd); m_airjump_neutral = velocitysection.GetAttribute<Vector2>("airjump.neu", Jump_neutral); m_airjump_back = velocitysection.GetAttribute<Vector2>("airjump.back", Jump_back); if (m_airjump_back.Y == 0) m_airjump_back.Y = m_airjump_neutral.Y; m_airjump_forward = velocitysection.GetAttribute<Vector2>("airjump.fwd", Jump_forward); if (m_airjump_forward.Y == 0) m_airjump_forward.Y = m_airjump_neutral.Y; m_airjumps = movementsection.GetAttribute<Int32>("airjump.num", 0); m_airjumpheight = movementsection.GetAttribute<Int32>("airjump.height", 0); m_vert_acceleration = movementsection.GetAttribute<Single>("yaccel"); m_standfriction = movementsection.GetAttribute<Single>("stand.friction"); m_crouchfriction = movementsection.GetAttribute<Single>("crouch.friction"); m_airjump_forward.Y = m_airjump_neutral.Y; m_airjump_back.Y = m_airjump_neutral.Y; }
Replay.Recording BuildRecording(String filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } ProfileLoader profiles = m_subsystems.GetSubSystem <ProfileLoader>(); if (m_subsystems.GetSubSystem <IO.FileSystem>().DoesFileExist(filepath) == false) { return(null); } IO.TextFile text = m_subsystems.GetSubSystem <IO.FileSystem>().OpenTextFile(filepath); IO.TextSection header = text.GetSection("xnaMugen Replay Header"); IO.TextSection data = text.GetSection("xnaMugen Replay Data"); if (header == null || data == null) { return(null); } Int32 version = header.GetAttribute <Int32>("Version", 0); CombatMode mode = header.GetAttribute <CombatMode>("Combat Mode", CombatMode.None); String p1name = header.GetAttribute <String>("Player 1 Name", null); String p1version = header.GetAttribute <String>("Player 1 Version", null); Int32 p1palette = header.GetAttribute <Int32>("Player 1 Palette", Int32.MinValue); String p2name = header.GetAttribute <String>("Player 2 Name", null); String p2version = header.GetAttribute <String>("Player 2 Version", null); Int32 p2palette = header.GetAttribute <Int32>("Player 2 Palette", Int32.MinValue); String stagepath = header.GetAttribute <String>("Stage Path", null); Int32 seed = header.GetAttribute <Int32>("Seed", Int32.MinValue); if (version != 1 || mode == CombatMode.None || stagepath == null || seed == Int32.MinValue) { return(null); } if (p1name == null || p1version == null || p1palette == Int32.MinValue) { return(null); } PlayerProfile p1profile = profiles.FindPlayerProfile(p1name, p1version); PlayerProfile p2profile = profiles.FindPlayerProfile(p2name, p2version); StageProfile stageprofile = profiles.FindStageProfile(stagepath); if (p1profile == null || p2profile == null || stageprofile == null) { return(null); } Combat.EngineInitialization initsettings = new Combat.EngineInitialization(mode, p1profile, p1palette, p2profile, p2palette, stageprofile, seed); List <Replay.RecordingData> replaydata = new List <Replay.RecordingData>(); Regex line_regex = new Regex(@"^(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)$", RegexOptions.IgnoreCase); StringConverter converter = profiles.GetSubSystem <StringConverter>(); foreach (String dataline in data.Lines) { Match match = line_regex.Match(dataline); if (match.Success == false) { continue; } Replay.RecordingData inputdata = new Replay.RecordingData( converter.Convert <Int32>(match.Groups[1].Value), converter.Convert <Int32>(match.Groups[2].Value), converter.Convert <Int32>(match.Groups[3].Value), converter.Convert <Int32>(match.Groups[4].Value), converter.Convert <Int32>(match.Groups[5].Value) ); replaydata.Add(inputdata); } return(new Replay.Recording(initsettings, replaydata)); }