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

Reintroduce include statements #1028

Merged
merged 5 commits into from
Sep 2, 2022
Merged

Reintroduce include statements #1028

merged 5 commits into from
Sep 2, 2022

Conversation

applenick
Copy link
Member

@applenick applenick commented Jul 9, 2022

Reintroduce include statements

Include statements are back 🎉

This PR reintroduces include statements, which allow for global XML files to be loaded and re-used across different maps. Our new implementation is slightly different from the version used on OCN, but should allow for a very user-friendly and familiar experience.

Example

Let's showcase this awesome feature with a simple example, say you're operating a blitz tournament and want every map to have standardized values. Normally you would be able to achieve this by modifying each individual map to ensure they all have the same values set.

With map includes, it's as simple as first defining your map include file:

<!-- blitz.xml, located under includes/blitz.xml -->
<map>
    <blitz>
        <lives>5</lives>
    </blitz>
</map>  

PGM will automatically infer the include id based on the file name, in this case blitz.xml -> blitz

Then to include the blitz file, you just have to reference it using the following statement.

<!-- map.xml -->
<map>
  ...
  <include id="blitz"/>
  ...
</map>

The benefit is now you'll be able to modify values in a single location and have all maps which reference the include be provided with the same values. Think of all the cool possibilities this feature will unlock 🤯

Quick Facts

  • Include statements are stored under a configurable directory (Defined in config.yml at map.includes).
  • Any number of include files can be loaded by PGM.
  • Multiple include statements per map are supported.
  • Include files must be unique in name, if more than one of the same name are loaded only the first will be stored.
  • The legacy <include src="file.xml"/> from OCN is NOT supported, but will not prevent the map from loading. Instead a small warning will be shown in the console encouraging server operators to upgrade.

Any and all feedback is welcome! As always, these changes have been heavily tested and work as intended 👍

Signed-off-by: applenick [email protected]

@applenick applenick added the reintroduce Reintroduces a feature that was removed label Jul 9, 2022
@applenick applenick requested a review from Electroid as a code owner July 9, 2022 18:23
@applenick applenick added the feature New feature or request label Jul 9, 2022
@alexsosnovsky
Copy link
Contributor

Oh wow, this is unexpected and awesome!

@applenick
Copy link
Member Author

applenick commented Jul 9, 2022

@RuedigerLP suggested adding back the global.xml file too, not something I originally considered when implementing this. Though would likely only take a few lines of code to make it functional.

@Electroid is that something you would like me to add into this PR or perhaps at a later date?

I went ahead and implemented it as per @Pablete1234's suggestion.

Copy link
Member

@Pablete1234 Pablete1234 left a comment

Choose a reason for hiding this comment

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

When i suggested it originally i expected you to just save the root element, not switch it to Document , and then just return root.cloneContent() on getContent method. But i think it's fine either way.

@KingOfSquares
Copy link
Contributor

Will this properly trigger an XML update without a server restart if a map has an include and the include is changed? Looking at SystemMapSourceFactory it looks like it currently only checks for modifications in the map.xml file.

@applenick
Copy link
Member Author

Will this properly trigger an XML update without a server restart if a map has an include and the include is changed? Looking at SystemMapSourceFactory it looks like it currently only checks for modifications in the map.xml file.

Great observation. At the moment there's no way to automatically detect when changes occur in the include files, the MapIncludeProcessor#reload is called alongside PGM's config reload (/pgm). Although this will reload the includes manually, maps which have already had their context loaded in will not have the updated XML due to this line here.

A potential solution for the map context issue would be to have MapSource store a list of includes per map (added on load) and combine some logic so MapSource#checkForUpdates will also check the status of all includes too.

As for checking if XML updates will auto-trigger if the include is modified without running the reload command, unsure of the best solution. If anyone has any suggestions let me know!

@KingOfSquares
Copy link
Contributor

Will this properly trigger an XML update without a server restart if a map has an include and the include is changed? Looking at SystemMapSourceFactory it looks like it currently only checks for modifications in the map.xml file.

Great observation. At the moment there's no way to automatically detect when changes occur in the include files, the MapIncludeProcessor#reload is called alongside PGM's config reload (/pgm). Although this will reload the includes manually, maps which have already had their context loaded in will not have the updated XML due to this line here.

A potential solution for the map context issue would be to have MapSource store a list of includes per map (added on load) and combine some logic so MapSource#checkForUpdates will also check the status of all includes too.

As for checking if XML updates will auto-trigger if the include is modified without running the reload command, unsure of the best solution. If anyone has any suggestions let me know!

What about doing a quick search through the map.xml in SystemMapSourceFactory#getDocument for the include keyword? That could store the found ids and store references to the respective include files as well(which could check for modification similar to how its done on the main document) as you described

@KingOfSquares
Copy link
Contributor

Also, does errors work when the error is from an include? I can imagine it would show as an element in the map.xml

@Pablete1234 Pablete1234 mentioned this pull request Jul 16, 2022
20 tasks
@applenick
Copy link
Member Author

What about doing a quick search through the map.xml in SystemMapSourceFactory#getDocument for the include keyword? That could store the found ids and store references to the respective include files as well(which could check for modification similar to how its done on the main document) as you described

I'm not sure parsing the document in that method is the best place for this, but thanks for the suggestion! I've got another idea I'll try though, will see if I can get a commit pushed today/tomorrow 👍

Also, does errors work when the error is from an include? I can imagine it would show as an element in the map.xml

Excellent question! I've not tested that, but I assume it would show the error as part of the map which should be fine. I'll have to check how OCN handled this to compare.

@applenick
Copy link
Member Author

Sorry forgot to check this PR for a few days, just went through and made Pablo's most recent suggestions along with a rebase. Thanks again! I'm not sure what else can be improved upon for this, but always open to suggestions 👍

@Pablete1234 Pablete1234 added the ready PR is ready to merge label Sep 1, 2022
@Electroid Electroid merged commit e65c23b into PGMDev:dev Sep 2, 2022
Samuel-Roach pushed a commit to Samuel-Roach/PGM that referenced this pull request Sep 3, 2022
Signed-off-by: applenick <[email protected]>
Signed-off-by: Samuel Roach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request ready PR is ready to merge reintroduce Reintroduces a feature that was removed
Development

Successfully merging this pull request may close these issues.

5 participants