Jump to content
LaunchBox Community Forums

Recommended Posts

Posted

Is there a way to add a Platform to more than one Platform Categories, where some of it is nested.

For example, adding the Platform Bandai Handheld (LCD) to [MESS] and [Handhelds (LCD)] Platform Category where [Handhelds (LCD)] is nested under [MESS]
 

- MESS
    - Handhelds (LCD)

 

Initially I thought the Platform.Category support multiple values via semicolon `;`, but turned out it doesn't and LB will just literally add it instead.

 

Code snippet

                        ...
						IDataManager dataManager = PluginHelper.DataManager;
						IPlatform finalGameTargetPlatform = ...
						...
						// Only add Platform Category if settings is enabled
                        if (IsAddPlatformCategory)
                        {
                            // Set the platform's Category property for MULTIPLE categories ---
							// matchingSystemConfig is a model that holds a list of Platform Categories for a Platform
                            if (matchingSystemConfig != null && matchingSystemConfig.PlatformCategory != null && matchingSystemConfig.PlatformCategory.Any())
                            {
                                // First, ensure all parent categories exist in LaunchBox.
                                // If they don't, create them.
                                IPlatformCategory[] allPlatformCategories = dataManager.GetAllPlatformCategories();
                                var existingCategoryNames = allPlatformCategories.Select(c => c.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);

                                foreach (var categoryName in matchingSystemConfig.PlatformCategory)
                                {
                                    if (!existingCategoryNames.Contains(categoryName))
                                    {
                                        dataManager.AddNewPlatformCategory(categoryName);
                                        // Add to our temporary HashSet to avoid re-checking in the same run
                                        existingCategoryNames.Add(categoryName);
                                        MessageBox.Show($"Platform Category '{categoryName}' did not exist in LaunchBox and has been created.", "Platform Category Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }

                                    finalGameTargetPlatform.Category = categoryName;
                                    MessageBox.Show($"Platform '{finalGameTargetPlatform.Name}' assigned to Categories: '{finalGameTargetPlatform.Category}'", "Category Assignment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    dataManager.Save(true);
                                }

                                // Now, set the Category property of the platform.
                                // LaunchBox uses a semicolon-separated string to represent MULTIPLE categories.
                                // finalGameTargetPlatform.Category = string.Join(";", matchingSystemConfig.PlatformCategory);
                                // Example: "MESS (TV Games);MESS (TEST)"

                                //MessageBox.Show($"Platform '{finalGameTargetPlatform.Name}' assigned to Categories: '{finalGameTargetPlatform.Category}'", "Category Assignment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

 

Posted

In app you'd just check the check box for everyone parent you want. In the plugin you have to add a parent relationship to every model you want it applied. I'd have to look at remember what the interface is called.

Posted

Thanks @C-Beats for looking into this! I thought it could be `DataManager.GetAllParents()`, but found the list is empty. 

                                foreach (var categoryName in matchingSystemConfig.PlatformCategory)
                                {
                                    if (!existingCategoryNames.Contains(categoryName))
                                    {
                                        dataManager.AddNewPlatformCategory(categoryName);
                                        existingCategoryNames.Add(categoryName); // Add to our in-memory list
                                        MessageBox.Show($"Platform Category '{categoryName}' did not exist and has been created.", "Category Created", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                        PluginHelper.DataManager.Save(true); // persist it just in case it's not updated
                                    }
                                }

                                IParent[] allParentRelationships = dataManager.GetAllParents();
                                foreach (var parent in allParentRelationships)
                                {
                                    MessageBox.Show($"IParent parent.PlatformName={parent.PlatformName}, parent.ParentPlatformName={parent.ParentPlatformName}, parent.ParentPlatformCategoryName={parent.ParentPlatformCategoryName}", "Parent Assignment", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                }


Inspecting `Parents.xml` and I can see all the Parents for each new Platform that I created. However calling `dataManager.GetAllParents();` doesn't seem to retrieve those entries.

<?xml version="1.0" standalone="yes"?>
<LaunchBox>
  <Parent>
    <PlatformName>Takara Tomy TV Game</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>JoyPalette TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Epoch TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Tomy Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Nintendo Game and Watch</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Takara e-kara</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>RADICA Play TV</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Hasbro TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Milton Bradley Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Parker Brothers Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Tronica Handhelds (LCD)</PlatformName>
  </Parent>

 

Posted
59 minutes ago, dsync89 said:

Thanks @C-Beats for looking into this! I thought it could be `DataManager.GetAllParents()`, but found the list is empty. 

                                foreach (var categoryName in matchingSystemConfig.PlatformCategory)
                                {
                                    if (!existingCategoryNames.Contains(categoryName))
                                    {
                                        dataManager.AddNewPlatformCategory(categoryName);
                                        existingCategoryNames.Add(categoryName); // Add to our in-memory list
                                        MessageBox.Show($"Platform Category '{categoryName}' did not exist and has been created.", "Category Created", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                        PluginHelper.DataManager.Save(true); // persist it just in case it's not updated
                                    }
                                }

                                IParent[] allParentRelationships = dataManager.GetAllParents();
                                foreach (var parent in allParentRelationships)
                                {
                                    MessageBox.Show($"IParent parent.PlatformName={parent.PlatformName}, parent.ParentPlatformName={parent.ParentPlatformName}, parent.ParentPlatformCategoryName={parent.ParentPlatformCategoryName}", "Parent Assignment", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                }


Inspecting `Parents.xml` and I can see all the Parents for each new Platform that I created. However calling `dataManager.GetAllParents();` doesn't seem to retrieve those entries.

<?xml version="1.0" standalone="yes"?>
<LaunchBox>
  <Parent>
    <PlatformName>Takara Tomy TV Game</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>JoyPalette TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Epoch TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Tomy Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Nintendo Game and Watch</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Takara e-kara</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>RADICA Play TV</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Hasbro TV Games</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Milton Bradley Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Parker Brothers Handhelds (LCD)</PlatformName>
  </Parent>
  <Parent>
    <PlatformName>Tronica Handhelds (LCD)</PlatformName>
  </Parent>

 

Yeah you had the right call but if that's what your file looks like you don't have any parent relationships. Need both a parent and a child identifier for valid parent relationships. You data file only shows the parent in each. I thought we had a way to manipulate parents via plugin code but not seeing the call to do so.

Posted

Yea I couldn't find any references to add the parent relationship too. Intuitively one would have thought it would be something like IPlatform.AddParent(). Hope it's just something that I missed, I'm certainly sure there are ways to do it. IPlatform does seems to have a Category but I'm not sure if it's relevant. Tried to put a semicolon in that field thinking that it could be the delimiter, but no luck there.

Posted
31 minutes ago, dsync89 said:

Yea I couldn't find any references to add the parent relationship too. Intuitively one would have thought it would be something like IPlatform.AddParent(). Hope it's just something that I missed, I'm certainly sure there are ways to do it. IPlatform does seems to have a Category but I'm not sure if it's relevant. Tried to put a semicolon in that field thinking that it could be the delimiter, but no luck there.

Yeah, I feel pretty confident that isn't going to work anywhere. My plugin I use on my own personal build does this so let me check how I hooked it up. I admit I may have use some undocumented stuff to make it happen so I wouldn't get my hopes up too much just yet.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...