Skip to content

Commit

Permalink
1.2.0.0 - Update for FFXIV 7.0 Dawntrail
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter2actual committed Jul 9, 2024
1 parent 441ba97 commit 2460a24
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 96 deletions.
14 changes: 10 additions & 4 deletions DalamudMinesweeper.Tests/DalamudMinesweeper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions DalamudMinesweeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Author": "hunter2_",
"Name": "Minesweeper",
"InternalName": "DalamudMinesweeper",
"AssemblyVersion": "1.1.0.4",
"AssemblyVersion": "1.2.0.0",
"Description": "Logic puzzle in which you find and flag hidden mines.\n\nLeft click to uncover a square, right click to place a flag.\nThe game ends when all mines are flagged and all safe squares have been uncovered.\nClick the smiley face to start a new game.",
"ApplicableVersion": "any",
"Tags": [
Expand All @@ -18,9 +18,9 @@
"LoadPriority": 0,
"Punchline": "Classic puzzle game.",
"AcceptsFeedback": true,
"DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.4/latest.zip",
"DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.4/latest.zip",
"DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip",
"DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip",
"IconUrl": "https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/images/icon.png",
"Changelog": "Add expert mode"
"Changelog": "Update for FFXIV 7.0"
}
]
6 changes: 2 additions & 4 deletions DalamudMinesweeper/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public class Configuration : IPluginConfiguration
public int NoGuessTimeoutMs { get; set; } = 1500;
public bool RevealShortcut { get; set; } = false;
public bool FlagShortcut { get; set; } = false;

public Scores Scores { get; set; } = new Scores([]);

// the below exist just to make saving less cumbersome
[NonSerialized]
private DalamudPluginInterface? _pluginInterface;
private IDalamudPluginInterface? _pluginInterface;

public void Initialize(DalamudPluginInterface pluginInterface)
public void Initialize(IDalamudPluginInterface pluginInterface)
{
_pluginInterface = pluginInterface;
}
Expand Down
4 changes: 2 additions & 2 deletions DalamudMinesweeper/DalamudMinesweeper.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
<Import Project="Dalamud.Plugin.Bootstrap.targets" />

<PropertyGroup>
<Version>1.1.0.4</Version>
<Version>1.2.0.0</Version>
<Description>A logic puzzle featuring hidden mines.</Description>
<PackageProjectUrl>https://github.com/hunter2actual/DalamudMinesweeper</PackageProjectUrl>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
34 changes: 19 additions & 15 deletions DalamudMinesweeper/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
using Dalamud.Game.Command;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using DalamudMinesweeper.Windows;
using Dalamud.IoC;

namespace DalamudMinesweeper;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public sealed class Service
{
[PluginService] public static IDalamudPluginInterface PluginInterface { get; set; }
[PluginService] public static ITextureProvider TextureProvider { get; set; }
[PluginService] public static ICommandManager CommandManager { get; set; }
}

public sealed class Plugin : IDalamudPlugin
{
private const string CommandName = "/minesweeper";

public DalamudPluginInterface PluginInterface { get; init; }
public Configuration Configuration { get; init; }
public WindowSystem WindowSystem = new("Minesweeper");
private ConfigWindow _configWindow { get; init; }
private ScoresWindow _scoresWindow { get; init; }
private MainWindow _mainWindow { get; init; }
private ICommandManager _commandManager { get; init; }

public Plugin(
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
[RequiredVersion("1.0")] ICommandManager commandManager)
IDalamudPluginInterface pluginInterface)
{
PluginInterface = pluginInterface;
_commandManager = commandManager;
pluginInterface.Create<Service>();

Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
Configuration.Initialize(PluginInterface);
Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
Configuration.Initialize(pluginInterface);

_configWindow = new ConfigWindow(this);
_scoresWindow = new ScoresWindow(this);
_mainWindow = new MainWindow(this, Configuration);
_mainWindow = new MainWindow(this, Configuration, Service.TextureProvider);

WindowSystem.AddWindow(_configWindow);
WindowSystem.AddWindow(_scoresWindow);
WindowSystem.AddWindow(_mainWindow);

_commandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
Service.CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
{
HelpMessage = "Open the Minesweeper window"
});

PluginInterface.UiBuilder.Draw += DrawUI;
PluginInterface.UiBuilder.OpenMainUi += DrawMainUI;
PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
pluginInterface.UiBuilder.Draw += DrawUI;
pluginInterface.UiBuilder.OpenMainUi += DrawMainUI;
pluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
}

public void Dispose()
Expand All @@ -54,7 +58,7 @@ public void Dispose()
_configWindow.Dispose();
_mainWindow.Dispose();

_commandManager.RemoveHandler(CommandName);
Service.CommandManager.RemoveHandler(CommandName);
}

private void OnCommand(string command, string args)
Expand Down
49 changes: 23 additions & 26 deletions DalamudMinesweeper/Sprites/NumberSprites.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
using Dalamud.Plugin;
using Dalamud.Interface.Internal;
using System.IO;
using System;
using ImGuiNET;
using System.Numerics;
using System.Collections.Generic;
using Dalamud.Interface.Textures;
using System;

namespace DalamudMinesweeper.Sprites;

public class NumberSprites : IDisposable
public class NumberSprites
{
private DalamudPluginInterface _pluginInterface { get; set; }
private IDalamudTextureWrap[] Sheets { get; init; }
private IDalamudPluginInterface _pluginInterface { get; set; }
private ISharedImmediateTexture[] Sheets { get; set; } = Array.Empty<ISharedImmediateTexture>();
private record SpriteData(Vector2 topLeftCoord, Vector2 sizePx);
private readonly Dictionary<char, SpriteData> _spriteDict;
private bool _loaded = false;

public NumberSprites(DalamudPluginInterface pluginInterface)
public NumberSprites(IDalamudPluginInterface pluginInterface)
{
_pluginInterface = pluginInterface;

Sheets =
[
LoadImage("numbers_1x.png"),
LoadImage("numbers_2x.png"),
LoadImage("numbers_3x.png"),
LoadImage("numbers_4x.png"),
LoadImage("numbers_5x.png"),
];

var numberSpriteSize = new Vector2(13, 23);

_spriteDict = new Dictionary<char, SpriteData>
Expand All @@ -54,7 +46,20 @@ public void DrawNumber(ImDrawListPtr drawList, char digit, Vector2 cursorPos, in

private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos, int zoom)
{
var sheet = Sheets[zoom - 1];
if (!_loaded)
{
Sheets =
[
LoadImage("numbers_1x.png"),
LoadImage("numbers_2x.png"),
LoadImage("numbers_3x.png"),
LoadImage("numbers_4x.png"),
LoadImage("numbers_5x.png"),
];
_loaded = true;
}

var sheet = Sheets[zoom - 1].GetWrapOrDefault();

var uvMin = sprite.topLeftCoord * zoom / sheet.Size;
var uvMax = (sprite.topLeftCoord + sprite.sizePx) * zoom / sheet.Size;
Expand All @@ -67,17 +72,9 @@ private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos,
uvMax);
}

public void Dispose()
{
foreach (var sheet in Sheets)
{
sheet.Dispose();
}
}

private IDalamudTextureWrap LoadImage(string path)
private ISharedImmediateTexture LoadImage(string path)
{
var fullPath = Path.Combine(_pluginInterface.AssemblyLocation.Directory?.FullName!, path);
return _pluginInterface.UiBuilder.LoadImage(fullPath);
return Service.TextureProvider.GetFromFile(fullPath);
}
}
51 changes: 24 additions & 27 deletions DalamudMinesweeper/Sprites/TileSprites.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
using Dalamud.Plugin;
using Dalamud.Interface.Internal;
using System.IO;
using System;
using ImGuiNET;
using System.Numerics;
using System.Collections.Generic;
using DalamudMinesweeper.Game;
using Dalamud.Interface.Textures;
using System;

namespace DalamudMinesweeper.Sprites;

public class TileSprites : IDisposable
public class TileSprites
{
private DalamudPluginInterface _pluginInterface { get; set; }
private IDalamudTextureWrap[] Sheets { get; init; }
private IDalamudPluginInterface _pluginInterface { get; set; }
private ISharedImmediateTexture[] Sheets { get; set; } = Array.Empty<ISharedImmediateTexture>();
private record SpriteData(Vector2 topLeftCoord, Vector2 sizePx);
private readonly Dictionary<string, SpriteData> _spriteDict;
private bool _loaded = false;

public TileSprites(DalamudPluginInterface pluginInterface)
public TileSprites(IDalamudPluginInterface pluginInterface)
{
_pluginInterface = pluginInterface;

Sheets =
[
LoadImage("spritesheet_1x.png"),
LoadImage("spritesheet_2x.png"),
LoadImage("spritesheet_3x.png"),
LoadImage("spritesheet_4x.png"),
LoadImage("spritesheet_5x.png"),
];
_pluginInterface = pluginInterface;

_spriteDict = new Dictionary<string, SpriteData>
{
Expand Down Expand Up @@ -63,7 +55,20 @@ public void DrawSmiley(ImDrawListPtr drawList, string smileyName, Vector2 cursor

private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos, int zoom)
{
var sheet = Sheets[zoom - 1];
if (!_loaded)
{
Sheets =
[
LoadImage("spritesheet_1x.png"),
LoadImage("spritesheet_2x.png"),
LoadImage("spritesheet_3x.png"),
LoadImage("spritesheet_4x.png"),
LoadImage("spritesheet_5x.png"),
];
_loaded = true;
}

var sheet = Sheets[zoom - 1].GetWrapOrDefault();

var uvMin = sprite.topLeftCoord * zoom / sheet.Size;
var uvMax = (sprite.topLeftCoord + sprite.sizePx) * zoom / sheet.Size;
Expand Down Expand Up @@ -99,17 +104,9 @@ private static string CellToSpriteName(Cell cell)
};
}

public void Dispose()
{
foreach (var sheet in Sheets)
{
sheet.Dispose();
}
}

private IDalamudTextureWrap LoadImage(string path)
private ISharedImmediateTexture LoadImage(string path)
{
var fullPath = Path.Combine(_pluginInterface.AssemblyLocation.Directory?.FullName!, path);
return _pluginInterface.UiBuilder.LoadImage(fullPath);
return Service.TextureProvider.GetFromFile(fullPath);
}
}
15 changes: 6 additions & 9 deletions DalamudMinesweeper/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using DalamudMinesweeper.Sweepers;
using DalamudMinesweeper.Sprites;
using ImGuiNET;
using Dalamud.Plugin.Services;

namespace DalamudMinesweeper.Windows;

Expand Down Expand Up @@ -35,7 +36,7 @@ public class MainWindow : Window, IDisposable
private Footer _footer;
private Background _background;

public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweeper",
public MainWindow(Plugin plugin, Configuration configuration, ITextureProvider textureProvider) : base("Minesweeper",
ImGuiWindowFlags.NoScrollbar
| ImGuiWindowFlags.NoScrollWithMouse
| ImGuiWindowFlags.NoResize
Expand All @@ -48,8 +49,8 @@ public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweepe
};

_configuration = configuration;
_tileSprites = new TileSprites(plugin.PluginInterface);
_numberSprites = new NumberSprites(plugin.PluginInterface);
_tileSprites = new TileSprites(Service.PluginInterface);
_numberSprites = new NumberSprites(Service.PluginInterface);
_gridSquareSizePxVec2 = new Vector2(0, 0);

_sweeper = new Sweeper();
Expand All @@ -60,12 +61,6 @@ public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweepe
_background = new Background(_game, _configuration, _borderWidthPx);
}

public void Dispose()
{
_tileSprites.Dispose();
_numberSprites.Dispose();
}

public override void Draw()
{
// Calculate element sizes
Expand Down Expand Up @@ -154,4 +149,6 @@ private void RecordScore()
_canSaveScore = false;
}
}

public void Dispose() { }
}
6 changes: 3 additions & 3 deletions DalamudMinesweeper/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.12, )",
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
"requested": "[2.1.13, )",
"resolved": "2.1.13",
"contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# DalamudMinesweeper

Dalamud plugin for FFXIV, now available in the main Dalamud repository!
For dev builds, install by adding `https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/DalamudMinesweeper.json` to your plugin sources.
Dalamud plugin for FFXIV.

How to play:
- Left click to uncover a square, right click to place a flag.
Expand Down

0 comments on commit 2460a24

Please sign in to comment.