Created
June 11, 2015 07:33
-
-
Save arun02139/5e27f8bcd21650a5dbdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
using System.Text; | |
using NUnit.Framework; | |
using System; | |
public static class PrettyPrintExtensions | |
{ | |
public static string PrettyPrint(this Mesh m) | |
{ | |
return string.Format("tris = {0}, vertexCount = {1}", m.triangles.Length, m.vertexCount); | |
} | |
public static string PrettyPrint(this Transform t) | |
{ | |
return string.Format("pos = {0}, rot = {1}", t.position.PrettyPrint(), t.rotation.PrettyPrint()); | |
} | |
public static string PrettyPrint(this UIBase ui) | |
{ | |
return string.Format("{0} ({1}): id = {2}", ui.GetType(), ui.name, ui.Id); | |
} | |
public static string PrettyPrint(this List<UIBase> uis) | |
{ | |
if(uis.Count < 1) | |
return "empty list"; | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0; i<uis.Count; i++) | |
{ | |
sb.Append(uis[i].PrettyPrint()).Append("\n"); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this IBattleElt elt) | |
{ | |
var battle = GameObject.FindGameObjectWithTag("Battle").GetComponent<Battle>(); | |
var unit = battle.Units.ById(elt.UnitId); | |
var unitName = unit.Name; | |
var actionName = ""; | |
if(unit.ActionId > 0) | |
actionName = " (" + SQLUtil.FindActionById(unit.ActionId).Name + ")"; | |
StringBuilder sb = new StringBuilder(); | |
sb.Append(string.Format("UnitId = {0}, {1}{2}, Agi = {3}, TP = {4} ", elt.UnitId, unitName, actionName, elt.Agi, elt.TP)); | |
return sb.ToString(); | |
} | |
// "pretty print" helper functions // | |
public static string PrettyPrint(this object[] args) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0, il=args.Length; i<il; i++) | |
{ | |
sb.Append(string.Format(" object[{0}] = {1}\n", i, args[i])); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this IList<Vector3> vecs) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0, il=vecs.Count; i<il; i++) | |
{ | |
sb.Append(string.Format(" Vector3[{0}] = {1}\n", i, vecs[i].PrettyPrint())); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this Vector3[] vecs) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0, il=vecs.Length; i<il; i++) | |
{ | |
sb.Append(string.Format(" Vector3[{0}] = {1}\n", i, vecs[i].PrettyPrint())); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this List<JSONStagingTile> json_staging_tiles) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0, il=json_staging_tiles.Count; i<il; i++) | |
{ | |
sb.Append(string.Format(" x: {0}\n z: {0}\n", json_staging_tiles[i].x, json_staging_tiles[i].z)); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this JSONFieldMetadata json_field_metadata) | |
{ | |
return string.Format("codename: {0}\nlength x: {1}\nlength z: {2}\nenemy tiles: {3}\nplayer tiles: {4}\n", | |
json_field_metadata.codename, json_field_metadata.length_x, json_field_metadata.length_z, | |
json_field_metadata.enemy_tiles.PrettyPrint(), json_field_metadata.player_tiles.PrettyPrint()); | |
} | |
public static string PrettyPrint(this Point spoint) | |
{ | |
return string.Format("{0},{1}", spoint.X, spoint.Z); | |
} | |
public static string PrettyPrint(this AStarBattleQuery query) | |
{ | |
return string.Format("start point: {0}, end point: {1}, jump = {2}, MOV = {3}", | |
query.Start.PrettyPrint(), query.End.PrettyPrint(), query.Jump, query.Move); | |
} | |
public static string PrettyPrint(this int[,] int_array) | |
{ | |
/// print one row at a time with a carriage-return ('\n') at the end | |
StringBuilder sb = new StringBuilder(); | |
int il = int_array.GetLength(0); | |
int jl = int_array.GetLength(1); | |
for(int i=0; i<il; i++) | |
{ | |
for(int j=0; j<jl; j++) | |
{ | |
sb.Append(int_array[i,j]).Append(" "); | |
if(j == jl - 1) | |
sb.Append("\n"); | |
} | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this int[] int_array) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0,il=int_array.Length; i<il; i++) | |
{ | |
sb.Append(int_array[i]).Append(","); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this List<int> int_list) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0,il=int_list.Count; i<il; i++) | |
{ | |
sb.Append(int_list[i]).Append(","); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this Quaternion q) | |
{ | |
return string.Format("x:{0}, y:{1}, z:{2}, w:{3}", q.x, q.y, q.z, q.w); | |
} | |
public static string PrettyPrint(this Color c) | |
{ | |
return string.Format("r:{0}, g:{1}, b:{2}, a:{3}", c.r, c.g, c.b, c.a); | |
} | |
public static string PrettyPrint(this SQLNode sql_node) | |
{ | |
return string.Format("SQLNode Info: Id = {0}, Name = {1}, UnlockRank = {2}, XPer = {3}, YPer = {4}", | |
sql_node.Id, sql_node.Name, sql_node.UnlockRank, sql_node.XPer, sql_node.YPer); | |
} | |
public static string PrettyPrint(this Ray ray) | |
{ | |
return string.Format("ray info: origin = {0}, direction = {0}, ", ray.origin.PrettyPrint(), ray.direction.PrettyPrint()); | |
} | |
public static string PrettyPrint(this Vector2 vec) | |
{ | |
return string.Format("{0},{1}", vec.x.ToString("#.##"), vec.y.ToString("#.##")); | |
} | |
public static string PrettyPrint(this Vector3 vec) | |
{ | |
return string.Format("{0},{1},{2}", vec.x.ToString("#.##"), vec.y.ToString("#.##"), vec.z.ToString("#.##")); | |
} | |
public static string PrettyPrint(this Tile tile, bool detailed = false) | |
{ | |
if(!detailed) | |
return string.Format("{0},{1}",tile.X, tile.Z); | |
else | |
return string.Format("{0},{1} (tile.UnitId = {2}, tile.TileType = {3})", tile.X, tile.Z, tile.UnitId, tile.TheTileType); | |
} | |
public static string PrettyPrint(this List<Target> targets, bool detailed = false) | |
{ | |
if(targets.Count == 0) | |
return "Empty List"; | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0, il=targets.Count; i<il; i++) | |
{ | |
sb.Append(targets[i].PrettyPrint(detailed) + "\n"); | |
if(i != il - 1) | |
sb.Append(" ,"); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this List<Tile> tiles, bool detailed = false) | |
{ | |
if(tiles.Count == 0) | |
return "Empty List"; | |
StringBuilder sb = new StringBuilder(); | |
for(int i=0,il=tiles.Count;i<il;i++) { | |
sb.Append(tiles[i].PrettyPrint(detailed) + "\n"); | |
if(i != il - 1) | |
sb.Append(" ,"); | |
} | |
return sb.ToString(); | |
} | |
public static string PrettyPrint(this IList<BattleElt> elementList) | |
{ | |
if(elementList.Count == 0) | |
return "Empty List"; | |
string s = ""; | |
for(int i=0,il=elementList.Count;i<il;i++) | |
{ | |
BattleElt elt = elementList[i]; | |
s += elt.PrettyPrint() + "\n"; | |
} | |
return s; | |
} | |
public static string PrettyPrint(this Tile[] tiles) | |
{ | |
string s = ""; | |
for(int i=0, il=tiles.Length; i<il; i++) | |
s += string.Format("Tile {0}: {1}", i, tiles[i].PrettyPrint()); | |
return s; | |
} | |
public static string PrettyPrint(this Unit[] units) | |
{ | |
string s = ""; | |
for(int i=0, il=units.Length; i<il; i++) | |
s += string.Format("Unit {0}: {1}", i, units[i].PrettyPrint(false)); | |
return s; | |
} | |
public static string PrettyPrint(this Target target, bool detailed = false) | |
{ | |
if(target.TargetingTiles) | |
return "[tile] " + ((Tile)target.Targ).PrettyPrint(detailed); | |
else | |
return "[unit] " + ((Unit)target.Targ).PrettyPrint(detailed); | |
} | |
// just prints name, location, bdindex and TP for now | |
public static string PrettyPrint(this Unit u, bool detailed) | |
{ | |
// example: "Hero"@1,1 (id:1) [TP=96, HP=0/20] | |
Assert.NotNull(u); | |
Assert.NotNull(u.Name); | |
if(!detailed) | |
return string.Format("{0}", u.Name); | |
else | |
return string.Format("\"{0}\"@{1},{2} ({3}), TP={4}, HP={5}/{6}]", u.Name, u.X, u.Z, u.UnitId, u.TP, u.HP, u.MaxAP); | |
} | |
// call pretty print on each unit in the list | |
public static string PrettyPrint(this List<Unit> unit_list) | |
{ | |
// example: "Hero" [bd=0, TP=96], "Villian" [bd=1, TP=0] | |
if(unit_list.Count == 0) | |
return "Empty List"; | |
string s = ""; | |
for(int i=0,il=unit_list.Count;i<il;i++) | |
{ | |
s += unit_list[i].PrettyPrint(false); | |
if(i != il-1) | |
s += ", "; | |
} | |
return s; | |
} | |
/* | |
// prints rosetta stone name, action id, and casting unit info for now | |
public static string PrettyPrint(this ChargingAction chargingAction) | |
{ | |
int unitId = chargingAction.UnitId; | |
var battle = GameObject.FindGameObjectWithTag("Battle").GetComponentInChildren<Battle>(); | |
Unit unit = battle.Units.ById(unitId); | |
Assert.Greater(chargingAction.ActionId, 0); | |
SQLAction action = SQLUtil.FindActionById(chargingAction.ActionId); | |
return string.Format("Unit Action {0} (id={1}, TP={2}, TurnsAhead={3}) being charged by {4} (TP={5})", | |
action.Name, chargingAction.ActionId, chargingAction.TP, | |
chargingAction.TurnsAhead, unit.Name, unit.TP); | |
} | |
*/ | |
// call pretty print on each unit action in the list | |
/* | |
public static string PrettyPrint(this List<ChargingAction> charging_action_list) | |
{ | |
// example: "VSlice" [#1] charged by "Hero" [bd=0, TP=96], "Fire3" [#62] charged by "Villian" [bd=1, TP=0], | |
if(charging_action_list.Count == 0) | |
return "Empty List"; | |
string s = ""; | |
for(int i=0,il=charging_action_list.Count;i<il;i++) | |
{ | |
s += charging_action_list[i].PrettyPrint(); | |
if(i != il-1) | |
s += ", "; | |
} | |
return s; | |
} | |
*/ | |
public static string PrettyPrint(this Dictionary<Type, UIFamily> uiPool) | |
{ | |
if(uiPool.Count < 1) | |
return "empty dictionary"; | |
StringBuilder sb = new StringBuilder(); | |
foreach(KeyValuePair<Type, UIFamily> kvp in uiPool) | |
{ | |
Type type = kvp.Key; | |
UIFamily family = kvp.Value; | |
NUnit.Framework.Assert.NotNull(family); // sanity-check | |
sb.Append(string.Format("Type: {0} (TotalCount = {1}, ActiveCount = {2})\n", type, family.TotalCount, family.ActiveCount)); | |
} | |
return sb.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment