Пример #1
0
		public void SetCustomBool(Nb2dJsonImage item, String propertyName, bool val)
		{
			m_imagesWithCustomProperties.Add(item);
			GetCustomPropertiesForItem(item, true).m_customPropertyMap_bool.Add(propertyName, val);
		}
Пример #2
0
		public String GetImageName(Nb2dJsonImage image)
		{
			if (m_imageToNameMap.ContainsKey(image))
				return m_imageToNameMap[image];
			return null;
		}
Пример #3
0
		public void SetCustomVector(Nb2dJsonImage item, String propertyName, Vector2 val)
		{
			m_imagesWithCustomProperties.Add(item);
			GetCustomPropertiesForItem(item, true).m_customPropertyMap_vec2.Add(propertyName, val);
		}
Пример #4
0
		JObject B2n(Nb2dJsonImage image)
		{
			JObject imageValue = new JObject();
			
			if (null != image.Body)
				imageValue["body"] = lookupBodyIndex(image.Body);
			else
				imageValue["body"] = -1;
			
			if (null != image.Name)
				imageValue["name"] = image.Name;
			if (null != image.File)
				imageValue["file"] = image.File;
			
			VecToJson("center", image.Center, imageValue);
			FloatToJson("angle", image.Angle, imageValue);
			FloatToJson("scale", image.Scale, imageValue);
			if (image.Flip)
				imageValue["flip"] = true;
			FloatToJson("opacity", image.Opacity, imageValue);
			imageValue["filter"] = image.Filter;
			FloatToJson("renderOrder", image.RenderOrder, imageValue);
			
			bool defaultColorTint = true;
			for (int i = 0; i < 4; i++)
			{
				if (image.ColorTint[i] != 255)
				{
					defaultColorTint = false;
					break;
				}
			}
			
			if (!defaultColorTint)
			{
				JArray array = (JArray)imageValue["colorTint"];
				for (int i = 0; i < 4; i++)
					array[i] = image.ColorTint[i];
			}
			
			// image->updateCorners();
			for (int i = 0; i < 4; i++)
				VecToJson("corners", image.Corners[i], imageValue, i);
			
			// image->updateUVs();
			for (int i = 0; i < 2 * image.NumPoints; i++)
			{
				VecToJson("glVertexPointer", image.Points[i], imageValue, i);
				VecToJson("glTexCoordPointer", image.UvCoords[i], imageValue, i);
			}
			for (int i = 0; i < image.NumIndices; i++)
				VecToJson("glDrawElements", image.Indices[i], imageValue, i);
			
			JArray customPropertyValue = WriteCustomPropertiesToJson(image);
			if (customPropertyValue.Count > 0)
				imageValue["customProperties"] = customPropertyValue;
			
			return imageValue;
		}
Пример #5
0
		public void SetCustomFloat(Nb2dJsonImage item, String propertyName, float val)
		{
			m_imagesWithCustomProperties.Add(item);
			GetCustomPropertiesForItem(item, true).m_customPropertyMap_float.Add(propertyName, (float)val);
		}
Пример #6
0
		public void SetCustomInt(Nb2dJsonImage item, String propertyName, int val)
		{
			m_imagesWithCustomProperties.Add(item);
			GetCustomPropertiesForItem(item, true).m_customPropertyMap_int.Add(propertyName, val);
		}
Пример #7
0
		protected void readCustomPropertiesFromJson(Nb2dJsonImage item, JObject value)
		{
			if (null == item)
				return;
			
			if (value["customProperties"] != null)
				return;
			
			int i = 0;
			JArray propValues = (JArray)value["customProperties"];
			if (null != propValues)
			{
				int numPropValues = propValues.Count;
				for (i = 0; i < numPropValues; i++)
				{
					JObject propValue = (JObject)propValues[i];
					string propertyName = propValue["name"].ToString();
					if (propValue["int"] != null)
						SetCustomInt(item, propertyName, (int)propValue["int"]);
					if (propValue["float"] != null)
						SetCustomFloat(item, propertyName, (float)propValue["float"]);
					if (propValue["string"] != null)
						SetCustomString(item, propertyName, propValue["string"].ToString());
					if (propValue["vec2"] != null)
						SetCustomVector(item, propertyName, this.jsonToVec("vec2", propValue));
					if (propValue["bool"] != null)
						SetCustomBool(item, propertyName, (bool)propValue["bool"]);
				}
			}
		}
Пример #8
0
		public void SetImageName(Nb2dJsonImage image, String name)
		{
			m_imageToNameMap.Add(image, name);
		}
Пример #9
0
		Nb2dJsonImage j2b2dJsonImage(JObject imageValue)
		{
			Nb2dJsonImage img = new Nb2dJsonImage();
			
			int bodyIndex = imageValue["body"] == null ? -1 : (int)imageValue["body"];
			if (-1 != bodyIndex)
				img.Body = lookupBodyFromIndex(bodyIndex);
			
			String imageName = imageValue["name"] == null ? "" : imageValue["name"].ToString();
			if (imageName != "")
			{
				img.Name = imageName;
				SetImageName(img, imageName);
			}
			
			String fileName = imageValue["file"] == null ? "" : imageValue["file"].ToString();
			if (fileName != "")
				img.File = fileName;
			
			img.Center = jsonToVec("center", imageValue);
			img.Angle = jsonToFloat("angle", imageValue);
			img.Scale = jsonToFloat("scale", imageValue);
			img.Opacity = jsonToFloat("opacity", imageValue);
			img.RenderOrder = jsonToFloat("renderOrder", imageValue);
			
			JArray colorTintArray = (JArray)imageValue["colorTint"];
			if (null != colorTintArray)
			{
				for (int i = 0; i < 4; i++)
				{
					img.ColorTint[i] = (int)colorTintArray[i];
				}
			}
			
			img.Flip = imageValue["flip"] == null ? false : (bool)imageValue["flip"];
			
			img.Filter = imageValue["filter"] == null ? 1 : (int)imageValue["filter"];
			
			img.Corners = new Vector2[4];
			for (int i = 0; i < 4; i++)
				img.Corners[i] = jsonToVec("corners", imageValue, i);
			
			JArray vertexPointerArray = (JArray)imageValue["glVertexPointer"];
			JArray texCoordArray = (JArray)imageValue["glVertexPointer"];
			if (null != vertexPointerArray && null != texCoordArray && vertexPointerArray.Count == texCoordArray.Count)
			{
				int numFloats = vertexPointerArray.Count;
				img.NumPoints = numFloats / 2;
				img.Points = new float[numFloats];
				img.UvCoords = new float[numFloats];
				for (int i = 0; i < numFloats; i++)
				{
					img.Points[i] = jsonToFloat("glVertexPointer", imageValue, i);
					img.UvCoords[i] = jsonToFloat("glTexCoordPointer", imageValue, i);
				}
			}
			
			JArray drawElementsArray = (JArray)imageValue["glDrawElements"];
			if (null != drawElementsArray)
			{
				img.NumIndices = drawElementsArray.Count;
				img.Indices = new short[img.NumIndices];
				for (int i = 0; i < img.NumIndices; i++)
					img.Indices[i] = (short)drawElementsArray[i];
			}
			
			return img;
		}