Skip to content

Commit

Permalink
Merge pull request #23 from DMagic1/development
Browse files Browse the repository at this point in the history
ORS Resource Fixes
  • Loading branch information
WaveFunctionP authored and WaveFunctionP committed Aug 23, 2014
2 parents fa8ac26 + 66ebd04 commit 3722464
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
27 changes: 19 additions & 8 deletions OpenResourceSystem/ORSPlanetaryResourceMapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,28 @@ public static void loadPlanetaryResourceData(int body) {
body_resource_maps.Clear();
body_abudnance_angles.Clear();
map_body = -1;
current_body = -1;
current_body = body;
foreach (UrlDir.UrlConfig config in configs) {
ConfigNode planetary_resource_config_node = config.config;
if (planetary_resource_config_node.GetValue("celestialBodyName") == celestial_body_name && planetary_resource_config_node != null) {
Debug.Log("[ORS] Loading Planetary Resource Data for " + celestial_body_name);
Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"), false);
if (map == null) {
continue;
}
string resource_gui_name = planetary_resource_config_node.GetValue("name");
string resource_gui_name = planetary_resource_config_node.GetValue("name");
if (body_resource_maps.ContainsKey(resource_gui_name))
continue;
Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"), false);
try
{
map.GetPixel(1, 1);
}
catch (UnityException e)
{
Debug.Log("Stop Doing Dumb Things With Your Map Textures: " + e);
continue;
}
if (map == null)
{
continue;
}
ORSPlanetaryResourceInfo resource_info = new ORSPlanetaryResourceInfo(resource_gui_name, map, body);
if (planetary_resource_config_node.HasValue("resourceName")) {
string resource_name = planetary_resource_config_node.GetValue("resourceName");
Expand All @@ -69,7 +81,7 @@ public static void loadPlanetaryResourceData(int body) {
string tex_path = planetary_resource_config_node.GetValue("displayTexture");
resource_info.setDisplayTexture(tex_path);
} else {
string tex_path = planetary_resource_config_node.GetValue("Interstellar/resource_point");
string tex_path = planetary_resource_config_node.GetValue("WarpPlugin/resource_point");
resource_info.setDisplayTexture(tex_path);
}
if (planetary_resource_config_node.HasValue("displayThreshold")) {
Expand Down Expand Up @@ -97,7 +109,6 @@ public static void loadPlanetaryResourceData(int body) {
Debug.Log("[ORS] " + abundance_points_list.Count + " high value " + resource_gui_name + " locations detected");
}
}
current_body = body;
}

protected static double getPixelAbundanceValue(int pix_x, int pix_y, ORSPlanetaryResourceInfo resource_info) {
Expand Down
25 changes: 19 additions & 6 deletions OpenResourceSystem/ORSResourceScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ORSResourceScanner : PartModule {
public string Ab;

protected double abundance = 0;
private ORSPlanetaryResourceInfo resourceInfo = null;

[KSPEvent(guiActive = true, guiName = "Display Hotspots", active = true)]
public void DisplayResource() {
Expand All @@ -32,17 +33,29 @@ public override void OnStart(PartModule.StartState state) {
}

public override void OnUpdate() {
ORSPlanetaryResourceMapData.updatePlanetaryResourceMap();
if (resourceInfo == null)
if (ORSPlanetaryResourceMapData.body_resource_maps.ContainsKey(resourceName))
resourceInfo = ORSPlanetaryResourceMapData.body_resource_maps[resourceName];
Events["DisplayResource"].active = Events["DisplayResource"].guiActive = !ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
Events["DisplayResource"].guiName = "Display " + resourceName + " hotspots";
Events["HideResource"].active = Events["HideResource"].guiActive = ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
Events["HideResource"].guiName = "Hide " + resourceName + " hotspots";
Fields["Ab"].guiName = resourceName + " abundance";
if (abundance > 0.001) {
Ab = (abundance * 100.0).ToString("0.00") + "%";
} else {
Ab = (abundance * 1000000.0).ToString("0.0") + "ppm";
}
ORSPlanetaryResourceMapData.updatePlanetaryResourceMap();
if (resourceInfo != null)
{
if (resourceInfo.getResourceScale() == 1)
{
Ab = (abundance * 100.0).ToString("0.00") + "%";
}
else
{
Ab = (abundance * 1000000.0).ToString("0.0") + "ppm";
}
}
else
Ab = "Broken:(";

}

public override void OnFixedUpdate() {
Expand Down

5 comments on commit 3722464

@DMagic1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I shouldn't enter changes manually...

https://github.com/WaveFunctionP/KSPInterstellar/blob/development/OpenResourceSystem/ORSPlanetaryResourceMapData.cs#L9

needs to be made internal or public, otherwise it will default to private and won't be readable by the scanner module.

@confusingbits
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very experienced, but wouldn't it be a good idea to leave it private and instead provide a public function to return the data? one that can be overridden?

edit: I'm an idiot. static removes the possibility of conflicting data right?

@DMagic1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a bad idea. Something like

public bool Body_Resource_Map (string resourceName)
{
      return body_resource_maps.ContainsKey(resourceName);
}

it eliminates the possibility of anyone breaking something from outside. You might also want a function for returning the ORSPlanetaryResourceInfo value too.

@confusingbits
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I may try something like that. I have a hard time wrapping my head around instancing and access stuff.

@DMagic1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they should probably be static methods, too. So it's just:

  somebool = ORSPlanetaryResourceMapData.Body_Resource_Map(resourceName);

Please sign in to comment.