private void addButton_Click(object sender, EventArgs e) { try { string name = nameText.Text; string type = typeCombo.Text; byte[] value = { }; if (type == "string") { value = mapInterface.getStringBuffer(valText.Text); } else if (type == "image") { value = mapInterface.getBitmapBytes(uploadedImage); } else if (type == "int") { value = mapInterface.getIntBuffer(Int32.Parse(valText.Text)); } else if (type == "double") { value = mapInterface.getDoubleBuffer(valText.Text); } else if (type == "float") { value = mapInterface.getFloatBuffer(float.Parse(valText.Text)); } else if (type == "boolean") { value = mapInterface.getBoolBuffer(bool.Parse(valText.Text)); } else { MessageBox.Show("Invalid type"); return; } if (name == "") { MessageBox.Show("Enter a name"); return; } if (value.Count() <= 0) { MessageBox.Show("No value"); return; } objTemplate.AddProperty(name, type, value); updatePropertyList(); ClearPropertiesUI(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void NewMap(string path) { ObjectTemplate globalObject = new ObjectTemplate("Global"); globalObject.SetDefaultImage(); Property gravity = new Property("Gravity", "float", new byte[] { }); gravity.SetFloat(0.0f); Property background = new Property("Background", "image", new byte[] { }); Bitmap defBg = new Bitmap(200, 200); FillBitmap(defBg); background.SetImage(defBg); globalObject.AddProperty(gravity); globalObject.AddProperty(background); this.AddObjectTemplate(globalObject); this.Save(path); }
public void Load() { try { Clear(); Byte[] mainBuffer = File.ReadAllBytes(this.path); int counter = 0; //Number of objects int numObjs = traverseToInt(mainBuffer, ref counter); for (int i = 0; i < numObjs; i++) { //Object name string objName = traverseToString(mainBuffer, ref counter, 20); ObjectTemplate curTemplate = new ObjectTemplate(objName); //Visible curTemplate.visibility = traverseToBool(mainBuffer, ref counter); //Soft curTemplate.isSoft = traverseToBool(mainBuffer, ref counter); //Number of properties int numProps = traverseToInt(mainBuffer, ref counter); for (int j = 0; j < numProps; j++) { //Property name string propertyName = traverseToString(mainBuffer, ref counter, 20); //Property type string propertyType = traverseToString(mainBuffer, ref counter, 20); //Property size int size = traverseToInt(mainBuffer, ref counter); //Property value byte[] value = traverseToByte(mainBuffer, ref counter, size); curTemplate.AddProperty(propertyName, propertyType, value); } //Number of images int numImages = traverseToInt(mainBuffer, ref counter); for (int k = 0; k < numImages; k++) { int numSteps = traverseToInt(mainBuffer, ref counter); for (int p = 0; p < numSteps; p++) { //Image name string imageName = traverseToString(mainBuffer, ref counter, 20); //Image size int imageSize = traverseToInt(mainBuffer, ref counter); //Image value Bitmap image = traverseToBitmap(mainBuffer, ref counter, imageSize); //# of Collision Vectors int nVect = traverseToInt(mainBuffer, ref counter); List <Line> vectors = new List <Line>(); for (int m = 0; m < nVect; m++) { int x1 = traverseToInt(mainBuffer, ref counter); int y1 = traverseToInt(mainBuffer, ref counter); int x2 = traverseToInt(mainBuffer, ref counter); int y2 = traverseToInt(mainBuffer, ref counter); Line line = new Line(x1, y1, x2, y2); vectors.Add(line); } curTemplate.AddImage(imageName, image, vectors); } } objectTemplates.Add(objName, curTemplate); } //Instance count int numInst = traverseToInt(mainBuffer, ref counter); for (int i = 0; i < numInst; i++) { //Instance name string instName = traverseToString(mainBuffer, ref counter, 20); ObjectInstance instance = new ObjectInstance(objectTemplates[instName]); //X instance.x = traverseToFloat(mainBuffer, ref counter); //Y instance.y = traverseToFloat(mainBuffer, ref counter); foreach (Property curProperty in instance.instance.properties.Values) { //Size int propSize = traverseToInt(mainBuffer, ref counter); //Value curProperty.value = traverseToByte(mainBuffer, ref counter, propSize); instance.instance.AddProperty(curProperty.name, curProperty.type, curProperty.value); } objectInstances.Add(instance); } //Wall Instance count int numWallInst = traverseToInt(mainBuffer, ref counter); for (int i = 0; i < numWallInst; i++) { //Instance name string instName = traverseToString(mainBuffer, ref counter, 20); ObjectWall instance = new ObjectWall(objectTemplates[instName]); //X instance.x = traverseToFloat(mainBuffer, ref counter); //Y instance.y = traverseToFloat(mainBuffer, ref counter); //W instance.w = traverseToFloat(mainBuffer, ref counter); //H instance.w = traverseToFloat(mainBuffer, ref counter); foreach (Property curProperty in instance.instance.properties.Values) { //Size int propSize = traverseToInt(mainBuffer, ref counter); //Value curProperty.value = traverseToByte(mainBuffer, ref counter, propSize); instance.instance.AddProperty(curProperty.name, curProperty.type, curProperty.value); } objectInstances.Add(instance); } } catch (Exception ex) { Console.WriteLine("Warrning: Not all error file loaded"); } }