Skip to content

Commit

Permalink
Handle pilot
Browse files Browse the repository at this point in the history
  • Loading branch information
Tall-Paul committed Oct 31, 2013
1 parent 22f653d commit 3f68963
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 49 deletions.
11 changes: 8 additions & 3 deletions SpaceEditor/Character.cs
Expand Up @@ -27,19 +27,24 @@ public void loadFromXML(XmlNode node, string parent)
base.loadFromXML(node);
Console.WriteLine("loading character");
this.parent = parent;
Console.WriteLine("set parent");
this.displayType = "Character";
this.actualType = "Character";
Console.WriteLine("set types");
CharacterModel = node.SelectSingleNode("CharacterModel").InnerText;
Console.WriteLine("got model");
Inventory = node.SelectSingleNode("Inventory").InnerXml;
Console.WriteLine(Inventory);
Console.WriteLine("got inventory");
Battery = node.SelectSingleNode("Battery").InnerXml;
Console.WriteLine("got battery");
LightEnabled = node.SelectSingleNode("LightEnabled").InnerText;
Console.WriteLine("got light");
JetpackMode = node.SelectSingleNode("JetpackMode").InnerText;
Console.WriteLine("got jetpackmode");
//UsingLadder = node.SelectSingleNode("UsingLadder").Attributes.GetNamedItem("xsi:nil").Value;
HeadAngle.loadFromXML(node.SelectSingleNode("HeadAngle"));
LinearVelocity.loadFromXML(node.SelectSingleNode("LinearVelocity"));
AutoenableJetPackDelay = node.SelectSingleNode("AutoenableJetpackDelay").InnerText;
this.actualType = "Character";
AutoenableJetPackDelay = node.SelectSingleNode("AutoenableJetpackDelay").InnerText;
Console.WriteLine("Character Loaded");
}

Expand Down
15 changes: 14 additions & 1 deletion SpaceEditor/CubeBlock.cs
Expand Up @@ -15,15 +15,24 @@ class CubeBlock : EntityBase
public coord Min = new coord();
public coord Max = new coord();
public coord Orientation = new coord();
public bool hasPilot = false;
public Character Pilot = null;

public void loadFromXML(XmlNode node)
{
base.loadFromXML(node);
this.SubTypeName = node.SelectSingleNode("SubtypeName").InnerText;
Console.WriteLine("loaded " + this.SubTypeName);
//Console.WriteLine("loaded " + this.SubTypeName);
this.Min.loadFromXML(node.SelectSingleNode("Min"));
this.Max.loadFromXML(node.SelectSingleNode("Max"));
this.Orientation.loadFromXML(node.SelectSingleNode("Orientation"));
XmlNode myPilot = node.SelectSingleNode("Pilot");
if (myPilot != null)
{
hasPilot = true;
Pilot = new Character();
Pilot.loadFromXML(myPilot,this.EntityId);
}
}

public string getXML()
Expand All @@ -38,6 +47,10 @@ public string getXML()
xml += this.Min.getXML("Min");
xml += this.Max.getXML("Max");
xml += this.Orientation.getXML("Orientation");
if (this.hasPilot == true)
{
xml += this.Pilot.getXML();
}
xml += "</MyObjectBuilder_CubeBlock>\r\n";
return xml;
}
Expand Down
97 changes: 96 additions & 1 deletion SpaceEditor/CubeGrid.cs
Expand Up @@ -6,6 +6,7 @@
using System.Xml;
using System.Windows.Forms;
using System.IO;
using System.Drawing;

namespace SpaceEditor
{
Expand All @@ -17,6 +18,9 @@ class CubeGrid : EntityBase
public String IsStatic = "false";
public coord LinearVelocity = new coord();
public coord AngularVelocity = new coord();
public bool hasPilot = false;
public Character Pilot = null;


public void loadFromXML(XmlNode node)
{
Expand All @@ -28,7 +32,15 @@ public void loadFromXML(XmlNode node)
CubeBlock new_block = new CubeBlock();
new_block.loadFromXML(block);
if (new_block.SubTypeName == "LargeBlockCockpit" || new_block.SubTypeName == "SmallBlockCockpit")
{
this.cockpit = new_block;
if (new_block.hasPilot == true)
{
this.hasPilot = true;
new_block.Pilot.parent = this.EntityId;
Pilot = new_block.Pilot;
}
}
CubeBlocks.Add(new_block);
}
IsStatic = node.SelectSingleNode("IsStatic").InnerText;
Expand All @@ -41,8 +53,91 @@ public void loadFromXML(XmlNode node)
this.displayType = "Large Ship";
if (this.GridSizeEnum == "Small")
this.displayType = "Small Ship";
if (this.hasPilot == true)
{
this.displayType = "[*] " + this.displayType;
}
this.actualType = "Ship";
//not sure what happens with stations, need to check
Console.WriteLine("Loaded "+displayType+" with "+CubeBlocks.Count +" blocks");
}

/*
* not working yet
*
*/
public Bitmap getThumbnail(){
float biggest_x = 0;
float smallest_x = 0;
float biggest_y = 0;
float smallest_y = 0;
int offset_x = 0;
int offset_y = 0;
foreach (CubeBlock cb in CubeBlocks)
{
float x = (float)cb.PositionAndOrientation.position.Y;
float y = (float)cb.PositionAndOrientation.position.Z;
if (x > biggest_x)
biggest_x = x;
if (x < smallest_x)
smallest_x = x;
if (y > biggest_y)
biggest_y = y;
if (y < smallest_y)
smallest_y = y;
}
Console.WriteLine("Original X Range: " + smallest_x + ":" + biggest_x);
Console.WriteLine("Original Y Range: " + smallest_y + ":" + biggest_y);
offset_x = (int)(0-smallest_x);
offset_y = (int)(0-smallest_y);

smallest_x = 0;
smallest_y = 0;
float scale = 1;
if (this.GridSizeEnum == "Large")
scale = (float)2.5;
biggest_x = ((biggest_x + offset_x) / scale)+1;
biggest_y = ((biggest_y + offset_y) / scale)+1;
offset_x = (int)(offset_x / scale);
offset_y = (int)(offset_y / scale);
Console.WriteLine(offset_x);
Console.WriteLine(offset_y);
Console.WriteLine("Offset and scaled X Range: " + smallest_x + ":" + (int)biggest_x);
Console.WriteLine("Offset and scaled Y Range: " + smallest_y + ":" + (int)biggest_y);
Bitmap thumbnail = new Bitmap((int)biggest_x, (int)biggest_y);
foreach (CubeBlock cb in CubeBlocks)
{
int x = 0;
int y = 0;
//if ((float)cb.PositionAndOrientation.position.X > 0)
x = (int)((float)cb.PositionAndOrientation.position.Y / scale) + offset_x;
//else
// x = 0;
//x = (int)((float)-cb.PositionAndOrientation.position.X / scale) + offset_x;
//if ((float)cb.PositionAndOrientation.position.Y > 0)
y = (int)((float)cb.PositionAndOrientation.position.Z / scale) + offset_y;
//else
//y = (int)((float)-cb.PositionAndOrientation.position.Y / scale) + offset_y;
//y = 0;
try
{
thumbnail.SetPixel(x, y, Color.Black);
}
catch (ArgumentOutOfRangeException)
{
Console.WriteLine("X: " + x + " Y: " + y);
}

}
float ratio = biggest_x / 500;
int fullsize_x = 500;
int fullsize_y = (int)(biggest_y / ratio);
Bitmap fullsize = new Bitmap(fullsize_x, fullsize_y);
using (Graphics g = Graphics.FromImage((Image)fullsize))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(thumbnail, 0, 0, fullsize_x, fullsize_y);
}
return fullsize;
}

public TreeNode getTreeNode()
Expand Down
113 changes: 70 additions & 43 deletions SpaceEditor/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f68963

Please sign in to comment.