private void OnSave() { using (var timer = new Profile.TaskTimer("Save piece tray")) { var names = new List <string>(); var rotations = new List <float[]>(); foreach (Transform child in transform) { names.Add(child.name.Replace("(Clone)", "")); rotations.Add ( new float[] { child.rotation.x, child.rotation.y, child.rotation.z, child.rotation.w } ); } Pool.Dispatch ( new SaveReply ( names.ToArray(), rotations.ToArray() ) ); } }
private void Save() { using (var timer = new Profile.TaskTimer("Save UI mode")) { using (var writer = new StreamWriter(Path())) { writer.WriteLine(is_right); } Logger.Log ("Wrote UI mode to disk: {0}", is_right ? "right" : "left"); } }
private void Save(Write w) { is_showing = w.Show; SetGuide(); using (var timer = new Profile.TaskTimer("Save guide option")) { using (var writer = new StreamWriter(Path())) { writer.WriteLine(is_showing); } Logger.Log ("Wrote guide option to disk: {0}", is_showing ? "show" : "hide"); } }
private void DoRead() { using (var timer = new Profile.TaskTimer("Load guide option")) { if (File.Exists(Path())) { using (var reader = new StreamReader(Path())) { is_showing = Boolean.Parse(reader.ReadLine()); } Logger.Log ("Read guide option: {0}", is_showing ? "show" : "hide"); } } }
private void DoRead() { using (var timer = new Profile.TaskTimer("Load UI mode")) { if (File.Exists(Path())) { using (var reader = new StreamReader(Path())) { is_right = Boolean.Parse(reader.ReadLine()); } SetMode(is_right); Logger.Log ("Read UI mode: {0}", is_right ? "right" : "left"); } } }
public static List <List <List <int?> > > GetRotations(string data) { using (var timer = new Profile.TaskTimer("Build neighbour rotations")) { var ret = new List <List <List <int?> > >(); var first = Parse(data); ret.Add(first); while (ret.Count < 6) { ret.Add(Rotate(ret[ret.Count - 1])); } return(ret); } }
private IEnumerator FindPlacementAsync() { using (var timer = new Profile.TaskTimer("Active tile request")) { active.Clear(); /* TODO: Only do this once, not per piece. */ Pool.Dispatch(new ActiveTileRequest(gameObject)); yield return(Notification.Async.WaitForReplies <ActiveTileRequest> (n => n.Requestor == gameObject)); } if (active.Count == 0) { Logger.Log("Board is full...?"); Pool.Dispatch(new EndGame.CheckFailed()); yield break; } var filled = max_tiles - active.Count; if (filled < threshold) { Logger.Log("End game not possible yet"); Pool.Dispatch(new EndGame.CheckPassed()); yield break; } using (var timer = new Profile.TaskTimer("Neighbour walk")) { int rotation_index = 0; foreach (var rotation in neighbour_rotations) { Logger.LogFormat("Trying rotation {0} for root {1}", rotation_index++, gameObject.name); foreach (var act in active) { var valid = Walk(rotation, 0, act); if (valid) { Logger.Log("Found valid position for piece"); Pool.Dispatch(new EndGame.CheckPassed()); yield break; } } } } Logger.Log("No piece found"); Pool.Dispatch(new EndGame.CheckFailed()); }
private void OnLoad(LoadRow wr) { if (wr.Number != number) { return; } using (var timer = new Profile.TaskTimer("Load row")) { var i = 0; for (var cur = GetComponent <Board.Tile>(); cur != null; cur = cur.right, ++i) { Assert.Invariant(i < wr.Tiles.Length, "Not enough tiles while loading"); if (wr.Tiles[i].Name == "") { continue; } cur.block = new GameObject().AddComponent <Board.Block>(); cur.block.piece_id = wr.Tiles[i].PieceIdentifier; cur.block.transform.position = cur.transform.position; cur.block.transform.localScale = new Vector3 ( wr.Tiles[i].Scale[0], wr.Tiles[i].Scale[1], wr.Tiles[i].Scale[2] ); cur.block.transform.rotation = new Quaternion ( wr.Tiles[i].Rotation[0], wr.Tiles[i].Rotation[1], wr.Tiles[i].Rotation[2], wr.Tiles[i].Rotation[3] ); cur.block.gameObject.AddComponent <Image>(); cur.block.transform.SetParent(canvas.transform); cur.block.GetComponent <Image>() .sprite = Resources.Load <Sprite>(wr.Tiles[i].SpriteName); cur.block.GetComponent <Image>().SetNativeSize(); cur.block.name = wr.Tiles[i].Name; } } }
private void DoWrite(Write whs) { using (var timer = new Profile.TaskTimer("Write high scores")) { using (var writer = new StreamWriter(Path())) { writer.WriteLine(whs.Score); var old_max = all_time ?? 0; var max = Math.Max(old_max, whs.Score); if (max > old_max) { Logger.Log("New high score ({0} > {1})", max, old_max); } writer.WriteLine(max); } Logger.LogFormat("Wrote high scores to disk"); } }
private void OnSave() { using (var timer = new Profile.TaskTimer("Save row")) { var states = new List <TileInfo>(); for (var cur = GetComponent <Board.Tile>(); cur != null; cur = cur.right) { if (cur.block != null) { states.Add ( new TileInfo ( cur.block.name, cur.block.GetComponent <Image>().sprite.name, new float[] { cur.block.transform.localScale.x, cur.block.transform.localScale.y, cur.block.transform.localScale.z }, new float[] { cur.block.transform.rotation.x, cur.block.transform.rotation.y, cur.block.transform.rotation.z, cur.block.transform.rotation.w }, (cur.block.piece != null) ? cur.block.piece.GetComponent <Board.PieceIdentifier>().ID : "" ) ); } else { states.Add(new TileInfo("", "", null, null, "")); } } Pool.Dispatch(new SaveRowReply(number, states.ToArray())); } }
private void Write() { var filled = row_replies.Count(x => x != null); Assert.Invariant(filled == row_replies.Count, "Cannot write incomplete data"); using (var timer = new Profile.TaskTimer("Write save game")) { data_to_save.rows = row_replies.ToArray(); data_to_save.pieces = piece_replies.ToArray(); var bf = new BinaryFormatter(); using (var file = File.Open(Path(), FileMode.OpenOrCreate)) { bf.Serialize(file, data_to_save); } } Logger.Log("Game saved"); data_to_save = null; }
private void DoRead() { using (var timer = new Profile.TaskTimer("Read high scores")) { if ((last == null || all_time == null) && File.Exists(Path())) { using (var reader = new StreamReader(Path())) { last = Int32.Parse(reader.ReadLine()); all_time = Int32.Parse(reader.ReadLine()); } } var ret = new ReadReply(); ret.Last = last ?? 0; ret.Best = all_time ?? 0; Logger.LogFormat("Read scores; last: {0} best: {1}", last, all_time); Pool.Dispatch(ret); } }
private void OnLoadPiece(Load l) { using (var timer = new Profile.TaskTimer("Load piece")) { /* TODO: Copied from Row loading */ var obj = new GameObject().AddComponent <Piece>(); obj.gameObject.AddComponent <CanvasGroup>().blocksRaycasts = false; obj.gameObject.AddComponent <PieceIdentifier>().ID = l.Item.ID; obj.transform.position = new Vector3 ( l.Item.Position[0], l.Item.Position[1], l.Item.Position[2] ); obj.transform.localScale = new Vector3 ( l.Item.Scale[0], l.Item.Scale[1], l.Item.Scale[2] ); obj.transform.rotation = new Quaternion ( l.Item.Rotation[0], l.Item.Rotation[1], l.Item.Rotation[2], l.Item.Rotation[3] ); obj.gameObject.AddComponent <Image>(); obj.transform.SetParent(canvas.transform); obj.GetComponent <Image>() .sprite = Resources.Load <Sprite>(l.Item.Name); obj.GetComponent <Image>().SetNativeSize(); Pool.Dispatch(new Loaded(l.Item.ID, obj)); } }
private void Load() { Assert.Invariant(File.Exists(Path()), "Trying to load non-existent save"); using (var timer = new Profile.TaskTimer("Read saved game")) { Data data = null; var bf = new BinaryFormatter(); using (var file = File.Open(Path(), FileMode.Open)) { data = (Data)bf.Deserialize(file); } var load_score = new Board.LoadScore(); load_score.Score = data.score; Pool.Dispatch(load_score); Pool.Dispatch ( new Board.PieceTray.Load ( data.piece_tray.Names, data.piece_tray.Rotations ) ); foreach (var row in data.rows) { Pool.Dispatch(new LoadRow(row.Number, row.Tiles)); } foreach (var piece in data.pieces) { Pool.Dispatch(new Board.PieceLoader.Load(piece)); } } }
private void OnLoad(Load l) { Assert.Invariant(l.Names.Length == l.Rotations.Length, "Different amount of names and rotations"); using (var timer = new Profile.TaskTimer("Load piece tray")) { for (int i = 0; i < l.Names.Length; ++i) { var prefab = Resources.Load("piece_tray/" + l.Names[i]); Assert.Invariant(prefab != null, "Invalid prefab for name " + l.Names[i]); var obj = Instantiate(prefab) as GameObject; obj.transform.rotation = new Quaternion ( l.Rotations[i][0], l.Rotations[i][1], l.Rotations[i][2], l.Rotations[i][3] ); obj.transform.SetParent(transform); } } }