From da98b1cd742cf29882da718282e316359fcffa8e Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:48:56 +1100 Subject: [PATCH] WIP --- gaseous-server/Classes/FileSignature.cs | 15 +++++++++ gaseous-server/Classes/ImportGames.cs | 9 ++++++ gaseous-server/Classes/Metadata/Games.cs | 13 ++++++-- gaseous-server/Classes/MetadataManagement.cs | 31 +++++++++++++++++++ gaseous-server/Models/Signatures_Games.cs | 2 ++ .../Support/Database/MySQL/gaseous-1024.sql | 2 ++ gaseous-server/wwwroot/images/manual.svg | 6 ++++ gaseous-server/wwwroot/pages/game.js | 19 ++++++++++-- gaseous-server/wwwroot/styles/style.css | 11 +++++-- 9 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 gaseous-server/wwwroot/images/manual.svg diff --git a/gaseous-server/Classes/FileSignature.cs b/gaseous-server/Classes/FileSignature.cs index 826c8c0..e358340 100644 --- a/gaseous-server/Classes/FileSignature.cs +++ b/gaseous-server/Classes/FileSignature.cs @@ -388,6 +388,21 @@ namespace gaseous_server.Classes } } + // check attributes for a user manual link + if (HasheousResult.Attributes != null) + { + if (HasheousResult.Attributes.Count > 0) + { + foreach (HasheousClient.Models.AttributeItem attribute in HasheousResult.Attributes) + { + if (attribute.attributeName == HasheousClient.Models.AttributeItem.AttributeName.VIMMManualId) + { + signature.Game.UserManual = attribute.GetType().GetProperty("Link").GetValue(attribute).ToString(); + } + } + } + } + return signature; } } diff --git a/gaseous-server/Classes/ImportGames.cs b/gaseous-server/Classes/ImportGames.cs index 097eb2d..8b5b380 100644 --- a/gaseous-server/Classes/ImportGames.cs +++ b/gaseous-server/Classes/ImportGames.cs @@ -205,6 +205,15 @@ namespace gaseous_server.Classes // add/get the metadata map MetadataMap? map = MetadataManagement.NewMetadataMap((long)platform.Id, signature.Game.Name); + // add any metadata attributes that may be supplied as part of the signature + if (signature.Game.UserManual != null) + { + if (signature.Game.UserManual.Length > 0) + { + MetadataManagement.SetMetadataSupportData((long)map.Id, MetadataManagement.MetadataMapSupportDataTypes.UserManualLink, signature.Game.UserManual); + } + } + // populate map with the sources from the signature if they don't already exist bool reloadMap = false; foreach (MetadataSources source in Enum.GetValues(typeof(MetadataSources))) diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index 7f3b31d..6bc6683 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -239,6 +239,7 @@ SELECT DISTINCT view_Games_Roms.MetadataMapId, view_Games_Roms.GameId, view_Games_Roms.PlatformId, + view_Games_Roms.UserManualLink, Platform.`Name`, User_RecentPlayedRoms.UserId AS MostRecentUserId, User_RecentPlayedRoms.RomId AS MostRecentRomId, @@ -310,7 +311,7 @@ ORDER BY Platform.`Name`;"; } } - // if still no configuration, create a blank one + // if still no emulator configuration, create a blank one if (emulatorConfiguration == null) { emulatorConfiguration = new PlatformMapping.UserEmulatorConfiguration @@ -347,6 +348,12 @@ ORDER BY Platform.`Name`;"; } } + string? UserManualLink = null; + if (row["UserManualLink"] != DBNull.Value) + { + UserManualLink = string.IsNullOrEmpty((string?)row["UserManualLink"]) ? "" : (string)row["UserManualLink"]; + } + AvailablePlatformItem valuePair = new AvailablePlatformItem { Id = platform.Id, @@ -358,7 +365,8 @@ ORDER BY Platform.`Name`;"; LastPlayedRomName = LastPlayedRomName, FavouriteRomId = FavouriteRomId, FavouriteRomIsMediagroup = FavouriteRomIsMediagroup, - FavouriteRomName = FavouriteRomName + FavouriteRomName = FavouriteRomName, + UserManualLink = UserManualLink }; platforms.Add(valuePair); } @@ -403,6 +411,7 @@ ORDER BY Platform.`Name`;"; public long? FavouriteRomId { get; set; } public bool? FavouriteRomIsMediagroup { get; set; } public string? FavouriteRomName { get; set; } + public string? UserManualLink { get; set; } } public enum SearchType diff --git a/gaseous-server/Classes/MetadataManagement.cs b/gaseous-server/Classes/MetadataManagement.cs index 03a5561..78a1cc1 100644 --- a/gaseous-server/Classes/MetadataManagement.cs +++ b/gaseous-server/Classes/MetadataManagement.cs @@ -11,6 +11,11 @@ namespace gaseous_server.Classes { private static bool Processing = false; + public enum MetadataMapSupportDataTypes + { + UserManualLink + } + /// /// Creates a new metadata map, if one with the same platformId and name does not already exist. /// @@ -215,6 +220,32 @@ namespace gaseous_server.Classes return null; } + public static void SetMetadataSupportData(long metadataMapId, MetadataMapSupportDataTypes dataType, string data) + { + // verify the metadata map exists + MetadataMap? metadataMap = GetMetadataMap(metadataMapId); + if (metadataMap == null) + { + return; + } + + Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = ""; + Dictionary dbDict = new Dictionary() + { + { "@metadataMapId", metadataMapId }, + { "@data", data } + }; + + switch (dataType) + { + case MetadataMapSupportDataTypes.UserManualLink: + sql = "UPDATE MetadataMap SET UserManualLink = @data WHERE Id = @metadataMapId;"; + db.ExecuteCMD(sql, dbDict); + break; + } + } + /// /// Get the MetadataMapItem for the provided metadata source, and source id /// diff --git a/gaseous-server/Models/Signatures_Games.cs b/gaseous-server/Models/Signatures_Games.cs index 3215e91..9045c32 100644 --- a/gaseous-server/Models/Signatures_Games.cs +++ b/gaseous-server/Models/Signatures_Games.cs @@ -159,6 +159,8 @@ namespace gaseous_server.Models } + public string UserManual { get; set; } + [JsonIgnore] public int Score { diff --git a/gaseous-server/Support/Database/MySQL/gaseous-1024.sql b/gaseous-server/Support/Database/MySQL/gaseous-1024.sql index bbebf90..3001d2e 100644 --- a/gaseous-server/Support/Database/MySQL/gaseous-1024.sql +++ b/gaseous-server/Support/Database/MySQL/gaseous-1024.sql @@ -116,6 +116,7 @@ CREATE TABLE `MetadataMap` ( `Id` bigint(20) NOT NULL AUTO_INCREMENT, `PlatformId` bigint(20) NOT NULL, `SignatureGameName` varchar(255) NOT NULL, + `UserManualLink` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `idx_gamename` ( `SignatureGameName`, @@ -286,6 +287,7 @@ SELECT `view_MetadataMap`.`Id` AS `MetadataMapId`, `view_MetadataMap`.`MetadataSourceType` AS `GameIdType`, `view_MetadataMap`.`MetadataSourceId` AS `GameId`, + `view_MetadataMap`.`UserManualLink` AS `UserManualLink`, `Games_Roms`.`Name` AS `Name`, `Games_Roms`.`Size` AS `Size`, `Games_Roms`.`CRC` AS `CRC`, diff --git a/gaseous-server/wwwroot/images/manual.svg b/gaseous-server/wwwroot/images/manual.svg new file mode 100644 index 0000000..832d104 --- /dev/null +++ b/gaseous-server/wwwroot/images/manual.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/gaseous-server/wwwroot/pages/game.js b/gaseous-server/wwwroot/pages/game.js index ba61e8c..df51641 100644 --- a/gaseous-server/wwwroot/pages/game.js +++ b/gaseous-server/wwwroot/pages/game.js @@ -489,6 +489,16 @@ function LoadGamePlatforms() { let platformEditButtonContainer = document.createElement('div'); platformEditButtonContainer.className = 'platform_edit_button_container'; + // create user manual button + let userManualButton = document.createElement('div'); + userManualButton.className = 'platform_edit_button'; + userManualButton.innerHTML = ''; + userManualButton.addEventListener('click', (e) => { + e.stopPropagation(); + let guideUrl = window.open(result[i].userManualLink, '_blank'); + guideUrl.opener = null; + }); + // create platform state manager button let platformStateManagerButton = document.createElement('div'); if (showSaveState === true) { @@ -518,10 +528,15 @@ function LoadGamePlatforms() { platformNameContainer.appendChild(platformName); platformItem.appendChild(platformNameContainer); platformItem.appendChild(platformEditButtonContainer); - platformItem.appendChild(platformEditButton); + if (showSaveState === true) { - platformItem.appendChild(platformStateManagerButton); + platformEditButtonContainer.appendChild(platformStateManagerButton); } + if (result[i].userManualLink) { + platformEditButtonContainer.appendChild(userManualButton); + } + platformEditButtonContainer.appendChild(platformEditButton); + platformContainer.appendChild(platformItem); } }); diff --git a/gaseous-server/wwwroot/styles/style.css b/gaseous-server/wwwroot/styles/style.css index 2ed7e37..738fa53 100644 --- a/gaseous-server/wwwroot/styles/style.css +++ b/gaseous-server/wwwroot/styles/style.css @@ -2987,16 +2987,21 @@ button:not(.select2-selection__choice__remove):not(.select2-selection__clear):no } .platform_edit_button_container { - width: 90px; + /* width: 90px; */ flex-grow: 0; + text-align: right; + padding-right: 5px; } .platform_edit_button { - position: absolute; + /* position: absolute; right: 14px; - top: 14px; + top: 14px;*/ width: 20px; height: 20px; + display: inline-block; + margin-left: 10px; + background-color: var(--fancybutton-background); border-radius: var(--standard-radius); border-width: 1px;