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

Disabled All Campaign Behaviors #640

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

garrettluskey
Copy link
Contributor

@garrettluskey garrettluskey commented Jun 17, 2023

PR Checklist

Please check if your PR fulfills the following requirements:
Tests and comments are not needed as these will be removed in the future

N/A All new classes have class-level documentation comments, if there are any at all
N/A Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation update
  • Other... Please describe:

What is the current behaviour?

Any campaign functionality currently makes is harder to incrementally develop.

What is the new behaviour?

Resolves #639

The removes all campaign behaviors functionality to make incremental development easier.

Other information

@garrettluskey garrettluskey self-assigned this Jun 17, 2023
@masesk
Copy link
Contributor

masesk commented Jun 18, 2023

I think this approach needs to be looked over.
It seems like MB uses CampaignEvents every time for all events. In fact, you are always catching the RegisterEvents() method.
Why not just undo those?
And if you want to get some behavior added later, just call the RegisterEvents() method on that behavior.
Saves you from adding a file for each patch.

Here is how to undo all the work by RegisterEvents()

        public override void OnAfterGameInitializationFinished(Game game, object initializerObject)
        {

            CampaignGameStarter campaignGameStarter = initializerObject as CampaignGameStarter;
            foreach (object b in campaignGameStarter.CampaignBehaviors.ToMBList())
            {
                InformationManager.DisplayMessage(new InformationMessage("Here"));

                var property = typeof(CampaignEvents).GetProperty("Instance", BindingFlags.NonPublic
                    | BindingFlags.Static);
                var instance = property.GetValue(null);
                MethodInfo methodInfo = instance.GetType()
                               .GetMethod("RemoveListeners", BindingFlags.Public | BindingFlags.Instance);
                methodInfo.Invoke(instance, new object[] { b });
            }
            

        }

@garrettluskey
Copy link
Contributor Author

I think this approach needs to be looked over. It seems like MB uses CampaignEvents every time for all events. In fact, you are always catching the RegisterEvents() method. Why not just undo those? And if you want to get some behavior added later, just call the RegisterEvents() method on that behavior. Saves you from adding a file for each patch.

Here is how to undo all the work by RegisterEvents()

        public override void OnAfterGameInitializationFinished(Game game, object initializerObject)
        {

            CampaignGameStarter campaignGameStarter = initializerObject as CampaignGameStarter;
            foreach (object b in campaignGameStarter.CampaignBehaviors.ToMBList())
            {
                InformationManager.DisplayMessage(new InformationMessage("Here"));

                var property = typeof(CampaignEvents).GetProperty("Instance", BindingFlags.NonPublic
                    | BindingFlags.Static);
                var instance = property.GetValue(null);
                MethodInfo methodInfo = instance.GetType()
                               .GetMethod("RemoveListeners", BindingFlags.Public | BindingFlags.Instance);
                methodInfo.Invoke(instance, new object[] { b });
            }
            

        }

These patches are meant to be removed during the sync development of a given section. It sections the work nicely

@masesk
Copy link
Contributor

masesk commented Jun 18, 2023

I think this approach needs to be looked over. It seems like MB uses CampaignEvents every time for all events. In fact, you are always catching the RegisterEvents() method. Why not just undo those? And if you want to get some behavior added later, just call the RegisterEvents() method on that behavior. Saves you from adding a file for each patch.
Here is how to undo all the work by RegisterEvents()

        public override void OnAfterGameInitializationFinished(Game game, object initializerObject)
        {

            CampaignGameStarter campaignGameStarter = initializerObject as CampaignGameStarter;
            foreach (object b in campaignGameStarter.CampaignBehaviors.ToMBList())
            {
                InformationManager.DisplayMessage(new InformationMessage("Here"));

                var property = typeof(CampaignEvents).GetProperty("Instance", BindingFlags.NonPublic
                    | BindingFlags.Static);
                var instance = property.GetValue(null);
                MethodInfo methodInfo = instance.GetType()
                               .GetMethod("RemoveListeners", BindingFlags.Public | BindingFlags.Instance);
                methodInfo.Invoke(instance, new object[] { b });
            }
            

        }

These patches are meant to be removed during the sync development of a given section. It sections the work nicely

Not sure what you mean by the patches will be removed.
If the idea is to have a different event for a specific behavior (say trigger a network call for an event), you can simply add that to the CampaignEvents and pass your behavior (custom or otherwise) to it.

@garrettluskey garrettluskey merged commit d691474 into development Jun 19, 2023
1 check passed
@garrettluskey garrettluskey deleted the disable-campaign-behaviors branch June 19, 2023 18:09
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.

Disable All Campaign Behaviors
2 participants