PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/src/away3d/tools/serialize/TraceSerializer.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 157 lines | 106 code | 16 blank | 35 comment | 10 complexity | 7792345a23c6784feba6f1f24e021cce MD5 | raw file
  1package away3d.tools.serialize
  2{
  3	import away3d.arcane;
  4	import away3d.core.math.Quaternion;
  5	
  6	import flash.geom.Vector3D;
  7	
  8	use namespace arcane;
  9	
 10	/**
 11	 * TraceSerializer is a concrete Serializer that will output its results to trace().  It has user settable tabSize and separator vars.
 12	 *
 13	 * @see away3d.tools.serialize.Serialize
 14	 */
 15	public class TraceSerializer extends SerializerBase
 16	{
 17		private var _indent:uint = 0;
 18		public var separator:String = ": ";
 19		public var tabSize:uint = 2;
 20		
 21		/**
 22		 * Creates a new TraceSerializer object.
 23		 */
 24		public function TraceSerializer()
 25		{
 26			super();
 27		}
 28		
 29		/**
 30		 * @inheritDoc
 31		 */
 32		public override function beginObject(className:String, instanceName:String):void
 33		{
 34			writeString(className, instanceName);
 35			_indent += tabSize;
 36		}
 37		
 38		/**
 39		 * @inheritDoc
 40		 */
 41		public override function writeInt(name:String, value:int):void
 42		{
 43			var outputString:String = _indentString();
 44			outputString += name;
 45			outputString += separator;
 46			outputString += value;
 47			trace(outputString);
 48		}
 49		
 50		/**
 51		 * @inheritDoc
 52		 */
 53		public override function writeUint(name:String, value:uint):void
 54		{
 55			var outputString:String = _indentString();
 56			outputString += name;
 57			outputString += separator;
 58			outputString += value;
 59			trace(outputString);
 60		}
 61		
 62		/**
 63		 * @inheritDoc
 64		 */
 65		public override function writeBoolean(name:String, value:Boolean):void
 66		{
 67			var outputString:String = _indentString();
 68			outputString += name;
 69			outputString += separator;
 70			outputString += value;
 71			trace(outputString);
 72		}
 73		
 74		/**
 75		 * @inheritDoc
 76		 */
 77		public override function writeString(name:String, value:String):void
 78		{
 79			var outputString:String = _indentString();
 80			outputString += name;
 81			if (value) {
 82				outputString += separator;
 83				outputString += value;
 84			}
 85			trace(outputString);
 86		}
 87		
 88		/**
 89		 * @inheritDoc
 90		 */
 91		public override function writeVector3D(name:String, value:Vector3D):void
 92		{
 93			var outputString:String = _indentString();
 94			outputString += name;
 95			if (value) {
 96				outputString += separator;
 97				outputString += value;
 98			}
 99			trace(outputString);
100		}
101		
102		/**
103		 * @inheritDoc
104		 */
105		public override function writeTransform(name:String, value:Vector.<Number>):void
106		{
107			var outputString:String = _indentString();
108			outputString += name;
109			if (value) {
110				outputString += separator;
111				
112				var matrixIndent:uint = outputString.length;
113				
114				for (var i:uint = 0; i < value.length; i++) {
115					outputString += value[i];
116					if ((i < (value.length - 1)) && (((i + 1)%4) == 0)) {
117						outputString += "\n";
118						for (var j:uint = 0; j < matrixIndent; j++)
119							outputString += " ";
120					} else
121						outputString += " ";
122				}
123			}
124			trace(outputString);
125		}
126		
127		/**
128		 * @inheritDoc
129		 */
130		public override function writeQuaternion(name:String, value:Quaternion):void
131		{
132			var outputString:String = _indentString();
133			outputString += name;
134			if (value) {
135				outputString += separator;
136				outputString += value;
137			}
138			trace(outputString);
139		}
140		
141		/**
142		 * @inheritDoc
143		 */
144		public override function endObject():void
145		{
146			_indent -= tabSize;
147		}
148		
149		private function _indentString():String
150		{
151			var indentString:String = "";
152			for (var i:uint = 0; i < _indent; i++)
153				indentString += " ";
154			return indentString;
155		}
156	}
157}