Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starfixes #233

Merged
merged 13 commits into from
Sep 22, 2017
Merged

Starfixes #233

merged 13 commits into from
Sep 22, 2017

Conversation

Sigma88
Copy link
Contributor

@Sigma88 Sigma88 commented Sep 22, 2017

some fixes for stars in the RnD

@Sigma88
Copy link
Contributor Author

Sigma88 commented Sep 22, 2017

this could be considered a bug fix, but I will let you merge it @StollD because I added something that might be considered a new feature:

killing star rotation in the RnD

if you want we could add a parameter like Properties/RDRotation (true by default for all bodies except for stars) so that the list of planets for which the rotation is killed can be edited by the user

@@ -40,6 +40,18 @@ namespace Kopernicus
/// </summary>
public class RnDFixer : MonoBehaviour
{
List<RDPlanetListItemContainer> stars = new List<RDPlanetListItemContainer>();
Copy link
Member

Choose a reason for hiding this comment

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

Please add an explicit private and move the initialization to Start()

void LateUpdate()
{
// Block the orientation of all stars
for (int i = 0; i < stars?.Count(); i++)
Copy link
Member

Choose a reason for hiding this comment

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

stars is never null so you can remove the ? (I am suprised that this compiles, since you are comparing an int to null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an int cannot be lower than a null so it returns false

I had an issue once where a null list was breaking my code, since then I've always used ? to make sure that even if I have a null the .Count() method doesn't trigger a nullref

is there a downside to using the ? ?

Copy link
Member

Choose a reason for hiding this comment

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

It is extra code that gets executed every frame and that isn't neccessary.

// Block the orientation of all stars
for (int i = 0; i < stars?.Count(); i++)
{
RDPlanetListItemContainer star = stars.ElementAt(i);
Copy link
Member

Choose a reason for hiding this comment

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

stars[i] - No need to use Linq and waste memory.

@@ -50,8 +50,8 @@ static StarComponent()
void Start()
{
// Find the celestial body we are attached to
celestialBody = PSystemManager.Instance.localBodies.First(body => body.scaledBody == gameObject);
Logger.Default.Log("StarLightSwitcher.Start() => " + celestialBody.bodyName);
celestialBody = PSystemManager.Instance.localBodies.FirstOrDefault(body => body.scaledBody == gameObject);
Copy link
Member

Choose a reason for hiding this comment

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

While I agree that this shouldn't throw the message it currently throws, it should throw something. Maybe something like this

if (celestialBody == null)
    throw new InvalidOperationException("The StarComponent isn't attached to the ScaledSpace object of a body.");

Copy link
Contributor Author

@Sigma88 Sigma88 Sep 22, 2017

Choose a reason for hiding this comment

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

the problem is that in the RnD all stars have a StarComponent

I don't think they should throw an error everytime you enter the RnD

Copy link
Member

Choose a reason for hiding this comment

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

Ok, then leave it that way

@Sigma88
Copy link
Contributor Author

Sigma88 commented Sep 22, 2017

ok, I think I've addressed everything

you are still using .ElementAt in the RnDFixer.cs
do you want me to change that as well?

[ParserTarget("RDVisibility")]
public EnumParser<RDVisibility> hiddenRD
Copy link
Member

Choose a reason for hiding this comment

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

You can just add two ParserTargets to one property ;)

@StollD
Copy link
Member

StollD commented Sep 22, 2017

Yes, that would be cool

@StollD StollD merged commit c773061 into master Sep 22, 2017
@Sigma88 Sigma88 deleted the starfixes branch September 22, 2017 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants