public void ReadXml(XmlLoad X) { if(!X.Read()) return; switch (X.ElementName) { case "player": NickName = X.GetAttribute("nick"); Rank = X.GetIntAttribute("rank"); Rating = X.GetIntAttribute("rating"); string S = X.GetAttribute("sex"); switch (S) { case "M": Sex = Sex.Male; break; case "F": Sex = Sex.Female; break; case "C": Sex = Sex.Computer; break; default: Sex = Sex.Unknown; break; } break; } }
public void Load(string FileName) { FileName = "round/" + FileName; XmlLoad X = new XmlLoad(); if (!X.Load(FileName)) return; this.FileName = FileName; while (X.Read()) { switch (X.ElementName) { case "hash": Hash = X.GetAttribute("value"); break; case "playercount": PlayerCount = X.GetIntAttribute("value"); break; case "lobby": Lobby = X.GetIntAttribute("value"); break; case "lobbytype": LobbyType = (LobbyType)X.GetIntAttribute("value"); break; case "game": Index = X.GetIntAttribute("index"); break; case "round": CurrentRound = X.GetIntAttribute("index"); break; case "result": StringResult = X.GetAttribute("value"); break; case "drawreason": DrawReason = X.GetIntAttribute("value"); break; case "riichistick": RiichiStick = X.GetIntAttribute("value"); break; case "renchanstick": RenchanStick = X.GetIntAttribute("value"); break; case "balancebefore": BalanceBefore = X.ReadIntArray(); break; case "balanceafter": BalanceAfter = X.ReadIntArray(); break; case "pay": Pay = X.ReadIntArray(); break; case "winner": Winner = X.ReadBoolArray(); break; case "loser": Loser = X.ReadBoolArray(); break; case "openedsets": OpenedSets = X.ReadIntArray(); break; case "naki": Naki = X.ReadIntArray(); break; case "riichi": Riichi = X.ReadIntArray(); break; case "dealer": Dealer = X.ReadBoolArray(); break; case "tempai": Tempai = X.ReadBoolArray(); break; case "wind": Wind = X.ReadIntArray(); break; case "stepcount": StepCount = X.ReadIntArray(); break; case "firstdora": FirstDora = X.GetIntAttribute("pointer"); break; case "wall": { if (Wall == null) Wall = new Mahjong.Wall(); Wall.Dice = DecompositeIntList(X.GetAttribute("dice")); Wall.Tiles = DecompositeIntList(X.GetAttribute("tiles")); } break; case "steps": { int Count = X.GetIntAttribute("count"); XmlLoad Subtree = X.GetSubtree(); for (int j = 0; j < Count; j++) { Step NewStep = new Step(-1); NewStep.ReadXml(Subtree); Steps.Add(NewStep); } Subtree.Close(); } break; case "hands": { XmlLoad Subtree = X.GetSubtree(); while (Subtree.Read()) { switch (Subtree.ElementName) { case "hand": { int Player = Subtree.GetIntAttribute("player"); XmlLoad HandData = Subtree.GetSubtree(); StartHands[Player] = new Hand(); StartHands[Player].ReadXml(HandData); HandData.Close(); } break; } } Subtree.Close(); } break; case "shantenlist": { XmlLoad Subtree = X.GetSubtree(); while (Subtree.Read()) { switch (Subtree.ElementName) { case "shanten": { int Player = Subtree.GetIntAttribute("player"); int Count = Subtree.GetIntAttribute("shanten"); XmlLoad ShantenData = Subtree.GetSubtree(); while (ShantenData.Read()) { switch (ShantenData.ElementName) { case "step": { int Value = ShantenData.GetIntAttribute("value"); Shanten[Player].Add(Value); } break; } } ShantenData.Close(); } break; } } Subtree.Close(); } break; case "agari": { int Player = X.GetIntAttribute("player"); HanCount[Player] = X.GetIntAttribute("han"); FuCount[Player] = X.GetIntAttribute("fu"); Cost[Player] = X.GetIntAttribute("cost"); XmlLoad Subtree = X.GetSubtree(); while (Subtree.Read()) { switch (Subtree.ElementName) { case "yakulist": { int Count = Subtree.GetIntAttribute("count"); XmlLoad YakuList = Subtree.GetSubtree(); while (YakuList.Read()) { switch (YakuList.ElementName) { case "yaku": Yaku Y = new Yaku(); Y.Cost = YakuList.GetIntAttribute("cost"); Y.Index = YakuList.GetIntAttribute("index"); Yaku[Player].Add(Y); break; } } YakuList.Close(); } break; case "waitings": { int Count = Subtree.GetIntAttribute("count"); XmlLoad WaitList = Subtree.GetSubtree(); while (WaitList.Read()) { switch (WaitList.ElementName) { case "waiting": WinWaiting[Player].Add(WaitList.GetIntAttribute("value")); break; } } WaitList.Close(); } break; } } Subtree.Close(); } break; case "dora": { int Count = X.GetIntAttribute("count"); Dora.Clear(); XmlLoad Doras = X.GetSubtree(); while (Doras.Read()) { switch (Doras.ElementName) { case "dora": Dora.Add(Doras.GetIntAttribute("pointer")); break; } } Doras.Close(); } break; case "uradora": { int Count = X.GetIntAttribute("count"); UraDora.Clear(); XmlLoad Doras = X.GetSubtree(); while (Doras.Read()) { switch (Doras.ElementName) { case "dora": UraDora.Add(Doras.GetIntAttribute("pointer")); break; } } Doras.Close(); } break; } } }
public void ReadXml(XmlLoad X) { if (!X.Read()) return; switch (X.ElementName) { case "drawtile": Type = StepType.STEP_DRAWTILE; Player = X.GetIntAttribute("player"); Tile = X.GetIntAttribute("tile"); break; case "discardtile": Type = StepType.STEP_DISCARDTILE; Player = X.GetIntAttribute("player"); Tile = X.GetIntAttribute("tile"); Shanten = X.GetIntAttribute("shanten"); { int F = X.GetIntAttribute("furiten"); Furiten = (F == 1); } break; case "drawdeadtile": Type = StepType.STEP_DRAWDEADTILE; Player = X.GetIntAttribute("player"); Tile = X.GetIntAttribute("tile"); break; case "naki": Type = StepType.STEP_NAKI; Player = X.GetIntAttribute("player"); break; case "riichi1": Type = StepType.STEP_RIICHI; Player = X.GetIntAttribute("player"); break; case "riichi2": Type = StepType.STEP_RIICHI1000; Player = X.GetIntAttribute("player"); break; case "tsumo": Type = StepType.STEP_TSUMO; Player = X.GetIntAttribute("player"); break; case "ron": Type = StepType.STEP_RON; Player = X.GetIntAttribute("player"); FromWho = X.GetIntAttribute("from"); break; case "draw": Type = StepType.STEP_DRAW; Reason = X.GetIntAttribute("reason"); break; case "newdora": Type = StepType.STEP_NEWDORA; Tile = X.GetIntAttribute("tile"); break; case "disconnect": Type = StepType.STEP_DISCONNECT; Player = X.GetIntAttribute("player"); break; case "connect": Type = StepType.STEP_CONNECT; Player = X.GetIntAttribute("player"); break; } { XmlLoad Subtree = X.GetSubtree(); while (Subtree.Read()) { switch (Subtree.ElementName) { case "waiting": { List<int> W = new List<int>(); XmlLoad TileTypes = Subtree.GetSubtree(); while(TileTypes.Read()) { switch (TileTypes.ElementName) { case "tiletype": W.Add(TileTypes.GetIntAttribute("value")); break; } } TileTypes.Close(); if (W.Count > 0) Waiting = W.ToArray(); } break; case "danger": { List<int> D = new List<int>(); XmlLoad Tiles = Subtree.GetSubtree(); while (Tiles.Read()) { switch (Tiles.ElementName) { case "tile": D.Add(Tiles.GetIntAttribute("value")); break; } } Tiles.Close(); if (D.Count > 0) Danger = D.ToArray(); } break; case "nakidata": { NakiData = new Naki(); NakiData.ReadXml(Subtree); } break; } } Subtree.Close(); } }
public bool LoadXml(string Hash) { string FileName = "replay/" + Hash + ".xml"; XmlLoad X = new XmlLoad(); if (!X.Load(FileName)) return false; while (X.Read()) { switch (X.ElementName) { case "hash": this.Hash = X.GetAttribute("value"); break; case "playercount": PlayerCount = X.GetIntAttribute("value"); break; case "lobby": Lobby = X.GetIntAttribute("value"); break; case "lobbytype": LobbyType = (LobbyType)X.GetIntAttribute("value"); break; case "balance": Balance = X.ReadIntArray(); break; case "result": Result = X.ReadIntArray(); break; case "place": Place = X.ReadIntArray(); break; case "playerlist": { int Count = 4; XmlLoad Subtree = X.GetSubtree(); for (int j = 0; j < Count; j++) { Players[j] = new Player(); Players[j].ReadXml(Subtree); } Subtree.Close(); } break; case "roundlist": { int Count = X.GetIntAttribute("count"); XmlLoad Subtree = X.GetSubtree(); for (int j = 0; j < Count; j++) { if (!Subtree.Read()) break; switch (Subtree.ElementName) { case "round": string FName = Subtree.GetAttribute("filename"); int Index = Subtree.GetIntAttribute("index"); Round R = new Round(); Rounds.Add(R); RoundFiles.Add(FName); XmlLoad RoundData = Subtree.GetSubtree(); while (RoundData.Read()) { switch (Subtree.ElementName) { case "round": R.CurrentRound = RoundData.GetIntAttribute("index"); break; case "renchan": R.RenchanStick = RoundData.GetIntAttribute("index"); break; case "result": R.StringResult = RoundData.GetAttribute("value"); break; case "balancebefore": R.BalanceBefore = RoundData.ReadIntArray(); break; case "balanceafter": R.BalanceAfter = RoundData.ReadIntArray(); break; case "pay": R.Pay = RoundData.ReadIntArray(); break; case "han": R.HanCount = RoundData.ReadIntArray(); break; case "fu": R.FuCount = RoundData.ReadIntArray(); break; case "cost": R.Cost = RoundData.ReadIntArray(); break; case "winner": R.Winner = RoundData.ReadBoolArray(); break; case "loser": R.Loser = RoundData.ReadBoolArray(); break; case "openedsets": R.OpenedSets = RoundData.ReadIntArray(); break; case "riichi": R.Riichi = RoundData.ReadIntArray(); break; case "dealer": R.Dealer = RoundData.ReadBoolArray(); break; } } RoundData.Close(); // try to load more data R.Load(FName); break; } } Subtree.Close(); } break; } } Date = GetDateTimeFromHash(Hash); return true; }
public void ReadXml(XmlLoad X) { if (!X.Read()) return; switch (X.ElementName) { case "tiles": { int Count = X.GetIntAttribute("count"); int Index = 0; XmlLoad Subtree = X.GetSubtree(); for (int i = 0; i < Count; i++) { if (!Subtree.Read()) break; switch (Subtree.ElementName) { case "tile": Tiles[Index] = Subtree.GetIntAttribute("value"); Index++; break; } } Subtree.Close(); } break; case "naki": { int Count = X.GetIntAttribute("count"); XmlLoad Subtree = X.GetSubtree(); for (int i = 0; i < Count; i++) { Naki N = new Naki(); N.ReadXml(X); Naki.Add(N); } Subtree.Close(); } break; } }