From 208ccd579c1edc213da1d9ee41ed1b058ffcfe04 Mon Sep 17 00:00:00 2001 From: Steven Liekens Date: Sat, 19 Oct 2024 13:20:26 +0000 Subject: [PATCH] Simplify the package readme --- .markdownlint.json | 1 + GW2SDK/PACKAGE.md | 83 ++++++++++--------- gw2sdk.sln | 24 ++++-- .../GameLinkProgram.csproj} | 5 +- .../Program.cs} | 24 ++++-- .../{ => GameLinkProgram}/packages.lock.json | 0 samples/PackageReadme/Gw2ClientProgram.cs | 49 ----------- .../Gw2ClientProgram/Gw2ClientProgram.csproj | 14 ++++ .../PackageReadme/Gw2ClientProgram/Program.cs | 38 +++++++++ .../Gw2ClientProgram/packages.lock.json | 25 ++++++ .../PackageReadme/packages.lock.json | 38 --------- 11 files changed, 155 insertions(+), 146 deletions(-) rename samples/PackageReadme/{PackageReadme.csproj => GameLinkProgram/GameLinkProgram.csproj} (73%) rename samples/PackageReadme/{GameLinkProgram.cs => GameLinkProgram/Program.cs} (82%) rename samples/PackageReadme/{ => GameLinkProgram}/packages.lock.json (100%) delete mode 100644 samples/PackageReadme/Gw2ClientProgram.cs create mode 100644 samples/PackageReadme/Gw2ClientProgram/Gw2ClientProgram.csproj create mode 100644 samples/PackageReadme/Gw2ClientProgram/Program.cs create mode 100644 samples/PackageReadme/Gw2ClientProgram/packages.lock.json delete mode 100644 samples/PackageReadme/PackageReadme/packages.lock.json diff --git a/.markdownlint.json b/.markdownlint.json index c9c454c09..a53e1098c 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -1,4 +1,5 @@ { + "first-line-h1": false, "no-inline-html": { "allowed_elements": [ "details", diff --git a/GW2SDK/PACKAGE.md b/GW2SDK/PACKAGE.md index 89d7b59a8..8ef122a0e 100644 --- a/GW2SDK/PACKAGE.md +++ b/GW2SDK/PACKAGE.md @@ -1,6 +1,9 @@ ## About -GW2SDK provides classes for interacting with the Guild Wars 2 API and game client. This package enables you to fetch information about the game, the player's account, PvP seasons, WvW matches and the in-game economy. It also provides realtime information from the game client such as the player's current character and the current map. +GW2SDK provides classes for interacting with the Guild Wars 2 API and game client. +This package enables you to fetch information about the game, the player's account, +PvP seasons, WvW matches and the in-game economy. It also provides realtime information +from the game client such as the player's current character and the current map. ## Key features @@ -9,17 +12,19 @@ GW2SDK provides classes for interacting with the Guild Wars 2 API and game clien ## How to use -You can use the `Gw2Client` for many different purposes, such as fetching the current prices of all tradable items in the game, or the `GameLink` to receive realtime information from the game client. Below are some examples of how to use the `Gw2Client` and `GameLink` to fetch information about the game and the player's account. +API access using `Gw2Client`: ``` csharp using System; using System.Net.Http; using System.Threading.Tasks; using GuildWars2; +using GuildWars2.Commerce.Prices; +using GuildWars2.Items; -namespace PackageReadme; +namespace PackageReadme.Gw2ClientProgram; -internal class Gw2ClientProgram +internal class Program { public static async Task Main(string[] args) { @@ -27,54 +32,43 @@ internal class Gw2ClientProgram using var httpClient = new HttpClient(); var gw2 = new Gw2Client(httpClient); - // Print a table header - PrintTableHeader(); - // Fetch the current prices of all items await foreach (var itemPrice in gw2.Commerce.GetItemPricesBulk().ValueOnly()) { - // The item price contains the item's ID, which can be used to fetch the item's name + // The item price contains the item's ID, which can be used to fetch + // the item's name var item = await gw2.Items.GetItemById(itemPrice.Id).ValueOnly(); // Print the item's name and its current highest buyer and lowest seller - PrintTableRow(item.Name, itemPrice.BestBid, itemPrice.BestAsk); - } - - void PrintTableHeader() - { - /* - ================================================================================================================================================================ - | Item | Highest buyer | Lowest seller | - ================================================================================================================================================================ - */ - Console.WriteLine(new string('=', 160)); - Console.WriteLine($"| {"Item",-50} | {"Highest buyer",-50} | {"Lowest seller",-50} |"); - Console.WriteLine(new string('=', 160)); + PrintItem(item, itemPrice); } + } - void PrintTableRow(string item, Coin highestBuyer, Coin lowestSeller) - { - /* - | | | | - */ - Console.WriteLine($"| {item,-50} | {highestBuyer,-50} | {lowestSeller,-50} |"); - } + private static void PrintItem(Item item, ItemPrice price) + { + Console.WriteLine($"{"Item",-15}: {item.Name}"); + Console.WriteLine($"{"Highest buyer",-15}: {price.BestBid}"); + Console.WriteLine($"{"Lowest seller",-15}: {price.BestAsk}"); + Console.WriteLine($"{"Bid-ask spread",-15}: {price.BidAskSpread}"); + Console.WriteLine(); } } + ``` -The `GameLink` can be used to receive realtime information from the game client. Below is an example of how to use the `GameLink` to receive information about the player's current character and the current map. +Game client access using `GameLink`: + +(This example also requires the System.Reactive package to be installed.) ``` csharp using System; -using System.Linq; using System.Net.Http; using System.Threading.Tasks; using GuildWars2; -namespace PackageReadme; +namespace PackageReadme.GameLinkProgram; -internal class GameLinkProgram +internal class Program { public static async Task Main(string[] args) { @@ -84,16 +78,19 @@ internal class GameLinkProgram return; } - Console.WriteLine("GameLink is starting! (Ensure the game is running and that you are loaded into a map.)"); + Console.WriteLine("GameLink is starting! (Ensure the game is running" + + " and that you are loaded into a map.)"); - // Pre-fetch all maps from the API, they are used to display the player's current map + // Pre-fetch all maps from the API, they are used to display the player's + // current map using var http = new HttpClient(); var gw2 = new Gw2Client(http); var maps = await gw2.Exploration.GetMapSummaries() .AsDictionary(map => map.Id) .ValueOnly(); - // Choose an interval to indicate how often you want to receive fresh data from the game + // Choose an interval to indicate how often you want to receive fresh data + // from the game // For example, at most once every second // Default: no limit, every change in the game state will be available immediately var refreshInterval = TimeSpan.FromSeconds(1); @@ -105,13 +102,16 @@ internal class GameLinkProgram var subscription = gameLink.Subscribe( tick => { - // Each 'tick' contains information about the player's character and actions, among other things + // Each 'tick' contains information about the player's character + // and actions, among other things var player = tick.GetIdentity(); - // The identity can be missing due to JSON errors, always check for null + // The identity can be missing due to JSON errors, always check + // for null if (player != null) { - // Use the player's map ID to find the map name in the pre-fetched list of maps + // Use the player's map ID to find the map name in the + // pre-fetched list of maps var map = maps[player.MapId]; // Print the player's name and current map @@ -132,6 +132,7 @@ internal class GameLinkProgram gameLink.Dispose(); } } + ``` ## Additional documentation @@ -141,5 +142,7 @@ internal class GameLinkProgram ## Feedback & contributing -GW2SDK is released as open source under the MIT license. You are welcome to create an issue if you find something is missing or broken, or a discussion for other feedback, questions or ideas. -Check out the GitHub [page](https://github.com/sliekens/gw2sdk) to find more ways to contribute. +GW2SDK is released as open source under the MIT license. You are welcome to create +an issue if you find something is missing or broken, or a discussion for other +feedback, questions or ideas. Check out the GitHub [page](https://github.com/sliekens/gw2sdk) +to find more ways to contribute. diff --git a/gw2sdk.sln b/gw2sdk.sln index 163edf38a..bb3256258 100644 --- a/gw2sdk.sln +++ b/gw2sdk.sln @@ -27,10 +27,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PollyUsage", "samples\Polly EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Translations", "samples\Translations\Translations.csproj", "{40937B58-1FFE-4B5B-A918-09F2DDEA2BF1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageReadme", "samples\PackageReadme\PackageReadme.csproj", "{69FC5CC8-8365-4AB1-A379-5BC7E0796207}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GW2SDK.Profiling", "GW2SDK.Profiling\GW2SDK.Profiling.csproj", "{787D05A8-12E5-4124-90A2-FD30F6418900}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PackageReadme", "PackageReadme", "{43B82868-E1D7-4B37-834B-0A7E2C64E8EC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameLinkProgram", "samples\PackageReadme\GameLinkProgram\GameLinkProgram.csproj", "{32143300-94DA-4DBE-A5AC-FAAC81429608}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gw2ClientProgram", "samples\PackageReadme\Gw2ClientProgram\Gw2ClientProgram.csproj", "{637E73C7-324B-4D60-89EB-CE36C1F56BC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,14 +85,18 @@ Global {40937B58-1FFE-4B5B-A918-09F2DDEA2BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU {40937B58-1FFE-4B5B-A918-09F2DDEA2BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU {40937B58-1FFE-4B5B-A918-09F2DDEA2BF1}.Release|Any CPU.Build.0 = Release|Any CPU - {69FC5CC8-8365-4AB1-A379-5BC7E0796207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69FC5CC8-8365-4AB1-A379-5BC7E0796207}.Debug|Any CPU.Build.0 = Debug|Any CPU - {69FC5CC8-8365-4AB1-A379-5BC7E0796207}.Release|Any CPU.ActiveCfg = Release|Any CPU - {69FC5CC8-8365-4AB1-A379-5BC7E0796207}.Release|Any CPU.Build.0 = Release|Any CPU {787D05A8-12E5-4124-90A2-FD30F6418900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {787D05A8-12E5-4124-90A2-FD30F6418900}.Debug|Any CPU.Build.0 = Debug|Any CPU {787D05A8-12E5-4124-90A2-FD30F6418900}.Release|Any CPU.ActiveCfg = Release|Any CPU {787D05A8-12E5-4124-90A2-FD30F6418900}.Release|Any CPU.Build.0 = Release|Any CPU + {32143300-94DA-4DBE-A5AC-FAAC81429608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32143300-94DA-4DBE-A5AC-FAAC81429608}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32143300-94DA-4DBE-A5AC-FAAC81429608}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32143300-94DA-4DBE-A5AC-FAAC81429608}.Release|Any CPU.Build.0 = Release|Any CPU + {637E73C7-324B-4D60-89EB-CE36C1F56BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {637E73C7-324B-4D60-89EB-CE36C1F56BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {637E73C7-324B-4D60-89EB-CE36C1F56BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {637E73C7-324B-4D60-89EB-CE36C1F56BC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -102,7 +110,9 @@ Global {F63A66C7-5520-4265-9F28-64DCCD1A6AA8} = {816817BB-0465-4D44-89A6-6CB64A1FF589} {0BA80C1D-40A9-4B20-9558-82C0AA58BC1F} = {816817BB-0465-4D44-89A6-6CB64A1FF589} {40937B58-1FFE-4B5B-A918-09F2DDEA2BF1} = {816817BB-0465-4D44-89A6-6CB64A1FF589} - {69FC5CC8-8365-4AB1-A379-5BC7E0796207} = {816817BB-0465-4D44-89A6-6CB64A1FF589} + {43B82868-E1D7-4B37-834B-0A7E2C64E8EC} = {816817BB-0465-4D44-89A6-6CB64A1FF589} + {32143300-94DA-4DBE-A5AC-FAAC81429608} = {43B82868-E1D7-4B37-834B-0A7E2C64E8EC} + {637E73C7-324B-4D60-89EB-CE36C1F56BC8} = {43B82868-E1D7-4B37-834B-0A7E2C64E8EC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {30CA8636-682D-4E26-943C-45133727C406} diff --git a/samples/PackageReadme/PackageReadme.csproj b/samples/PackageReadme/GameLinkProgram/GameLinkProgram.csproj similarity index 73% rename from samples/PackageReadme/PackageReadme.csproj rename to samples/PackageReadme/GameLinkProgram/GameLinkProgram.csproj index 80df5aaf8..ea2281e74 100644 --- a/samples/PackageReadme/PackageReadme.csproj +++ b/samples/PackageReadme/GameLinkProgram/GameLinkProgram.csproj @@ -5,15 +5,14 @@ net8.0 disable enable - PackageReadme.GameLinkProgram - + - + diff --git a/samples/PackageReadme/GameLinkProgram.cs b/samples/PackageReadme/GameLinkProgram/Program.cs similarity index 82% rename from samples/PackageReadme/GameLinkProgram.cs rename to samples/PackageReadme/GameLinkProgram/Program.cs index babf6f738..da7e59637 100644 --- a/samples/PackageReadme/GameLinkProgram.cs +++ b/samples/PackageReadme/GameLinkProgram/Program.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; using GuildWars2; -namespace PackageReadme; +namespace PackageReadme.GameLinkProgram; -internal class GameLinkProgram +internal class Program { public static async Task Main(string[] args) { @@ -15,16 +15,19 @@ public static async Task Main(string[] args) return; } - Console.WriteLine("GameLink is starting! (Ensure the game is running and that you are loaded into a map.)"); + Console.WriteLine("GameLink is starting! (Ensure the game is running" + + " and that you are loaded into a map.)"); - // Pre-fetch all maps from the API, they are used to display the player's current map + // Pre-fetch all maps from the API, they are used to display the player's + // current map using var http = new HttpClient(); var gw2 = new Gw2Client(http); var maps = await gw2.Exploration.GetMapSummaries() - .AsDictionary(static map => map.Id) + .AsDictionary(map => map.Id) .ValueOnly(); - // Choose an interval to indicate how often you want to receive fresh data from the game + // Choose an interval to indicate how often you want to receive fresh data + // from the game // For example, at most once every second // Default: no limit, every change in the game state will be available immediately var refreshInterval = TimeSpan.FromSeconds(1); @@ -36,13 +39,16 @@ public static async Task Main(string[] args) var subscription = gameLink.Subscribe( tick => { - // Each 'tick' contains information about the player's character and actions, among other things + // Each 'tick' contains information about the player's character + // and actions, among other things var player = tick.GetIdentity(); - // The identity can be missing due to JSON errors, always check for null + // The identity can be missing due to JSON errors, always check + // for null if (player != null) { - // Use the player's map ID to find the map name in the pre-fetched list of maps + // Use the player's map ID to find the map name in the + // pre-fetched list of maps var map = maps[player.MapId]; // Print the player's name and current map diff --git a/samples/PackageReadme/packages.lock.json b/samples/PackageReadme/GameLinkProgram/packages.lock.json similarity index 100% rename from samples/PackageReadme/packages.lock.json rename to samples/PackageReadme/GameLinkProgram/packages.lock.json diff --git a/samples/PackageReadme/Gw2ClientProgram.cs b/samples/PackageReadme/Gw2ClientProgram.cs deleted file mode 100644 index a11ee1da0..000000000 --- a/samples/PackageReadme/Gw2ClientProgram.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using GuildWars2; - -namespace PackageReadme; - -internal class Gw2ClientProgram -{ - public static async Task Main(string[] args) - { - // Create an instance of the Gw2Client, which depends on HttpClient - using var httpClient = new HttpClient(); - var gw2 = new Gw2Client(httpClient); - - // Print a table header - PrintTableHeader(); - - // Fetch the current prices of all items - await foreach (var itemPrice in gw2.Commerce.GetItemPricesBulk().ValueOnly()) - { - // The item price contains the item's ID, which can be used to fetch the item's name - var item = await gw2.Items.GetItemById(itemPrice.Id).ValueOnly(); - - // Print the item's name and its current highest buyer and lowest seller - PrintTableRow(item.Name, itemPrice.BestBid, itemPrice.BestAsk); - } - - void PrintTableHeader() - { - /* - ================================================================================================================================================================ - | Item | Highest buyer | Lowest seller | - ================================================================================================================================================================ - */ - Console.WriteLine(new string('=', 160)); - Console.WriteLine($"| {"Item",-50} | {"Highest buyer",-50} | {"Lowest seller",-50} |"); - Console.WriteLine(new string('=', 160)); - } - - void PrintTableRow(string item, Coin highestBuyer, Coin lowestSeller) - { - /* - | | | | - */ - Console.WriteLine($"| {item,-50} | {highestBuyer,-50} | {lowestSeller,-50} |"); - } - } -} diff --git a/samples/PackageReadme/Gw2ClientProgram/Gw2ClientProgram.csproj b/samples/PackageReadme/Gw2ClientProgram/Gw2ClientProgram.csproj new file mode 100644 index 000000000..07a8f91c7 --- /dev/null +++ b/samples/PackageReadme/Gw2ClientProgram/Gw2ClientProgram.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + disable + enable + + + + + + + diff --git a/samples/PackageReadme/Gw2ClientProgram/Program.cs b/samples/PackageReadme/Gw2ClientProgram/Program.cs new file mode 100644 index 000000000..d208fdc06 --- /dev/null +++ b/samples/PackageReadme/Gw2ClientProgram/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using GuildWars2; +using GuildWars2.Commerce.Prices; +using GuildWars2.Items; + +namespace PackageReadme.Gw2ClientProgram; + +internal class Program +{ + public static async Task Main(string[] args) + { + // Create an instance of the Gw2Client, which depends on HttpClient + using var httpClient = new HttpClient(); + var gw2 = new Gw2Client(httpClient); + + // Fetch the current prices of all items + await foreach (var itemPrice in gw2.Commerce.GetItemPricesBulk().ValueOnly()) + { + // The item price contains the item's ID, which can be used to fetch + // the item's name + var item = await gw2.Items.GetItemById(itemPrice.Id).ValueOnly(); + + // Print the item's name and its current highest buyer and lowest seller + PrintItem(item, itemPrice); + } + } + + private static void PrintItem(Item item, ItemPrice price) + { + Console.WriteLine($"{"Item",-15}: {item.Name}"); + Console.WriteLine($"{"Highest buyer",-15}: {price.BestBid}"); + Console.WriteLine($"{"Lowest seller",-15}: {price.BestAsk}"); + Console.WriteLine($"{"Bid-ask spread",-15}: {price.BidAskSpread}"); + Console.WriteLine(); + } +} diff --git a/samples/PackageReadme/Gw2ClientProgram/packages.lock.json b/samples/PackageReadme/Gw2ClientProgram/packages.lock.json new file mode 100644 index 000000000..991bc58cc --- /dev/null +++ b/samples/PackageReadme/Gw2ClientProgram/packages.lock.json @@ -0,0 +1,25 @@ +{ + "version": 2, + "dependencies": { + "net8.0": { + "Microsoft.Build.CopyOnWrite": { + "type": "Direct", + "requested": "[1.0.322, )", + "resolved": "1.0.322", + "contentHash": "Er5Ku4HJNDdRJD6qmV/Zposwvikvof37h6cFHNZ0Vmz1g+esSLKXd79g6fdJpfoNuOzl8w/q6vSpD3M3zihmAQ==" + }, + "gw2sdk": { + "type": "Project", + "dependencies": { + "System.Text.Json": "[8.0.5, )" + } + }, + "System.Text.Json": { + "type": "CentralTransitive", + "requested": "[8.0.5, )", + "resolved": "8.0.5", + "contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg==" + } + } + } +} \ No newline at end of file diff --git a/samples/PackageReadme/PackageReadme/packages.lock.json b/samples/PackageReadme/PackageReadme/packages.lock.json deleted file mode 100644 index b2abf2aff..000000000 --- a/samples/PackageReadme/PackageReadme/packages.lock.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "version": 1, - "dependencies": { - "net8.0": { - "System.Reactive": { - "type": "Direct", - "requested": "[6.0.0, )", - "resolved": "6.0.0", - "contentHash": "31kfaW4ZupZzPsI5PVe77VhnvFF55qgma7KZr/E0iFTs6fmdhhG8j0mgEx620iLTey1EynOkEfnyTjtNEpJzGw==" - }, - "Microsoft.NET.ILLink.Tasks": { - "type": "Transitive", - "resolved": "8.0.1", - "contentHash": "ADdJXuKNjwZDfBmybMnpvwd5CK3gp92WkWqqeQhW4W+q4MO3Qaa9QyW2DcFLAvCDMcCWxT5hRXqGdv13oon7nA==" - }, - "System.Text.Encodings.Web": { - "type": "Transitive", - "resolved": "8.0.0", - "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==" - }, - "System.Text.Json": { - "type": "Transitive", - "resolved": "8.0.1", - "contentHash": "7AWk2za1hSEJBppe/Lg+uDcam2TrDqwIKa9XcPssSwyjC2xa39EKEGul3CO5RWNF+hMuZG4zlBDrvhBdDTg4lg==", - "dependencies": { - "System.Text.Encodings.Web": "8.0.0" - } - }, - "gw2sdk": { - "type": "Project", - "dependencies": { - "Microsoft.NET.ILLink.Tasks": "[8.0.1, )", - "System.Text.Json": "[8.0.1, )" - } - } - } - } -} \ No newline at end of file