1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +01:00

Compare commits

..

6 commits

28 changed files with 130 additions and 82 deletions

View file

@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.3.0",
"version": "2.2.0",
"commands": [
"dotnet-cake"
]
}
}
}
}

View file

@ -20,6 +20,7 @@ Improvements
- Allow using external gesture handling alongside InputHandler through ExternalGestureHandling
- Discard old data when updating a StaticSpriteBatch
- **Drastically improved StaticSpriteBatch batching performance**
- Multi-target net452, making MLEM compatible with MonoGame for consoles
Fixes
- Fixed TokenizedString handling trailing spaces incorrectly in the last line of non-left aligned text
@ -36,6 +37,7 @@ Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly
- Close other dropdowns when opening a dropdown
- Generified UiMarkdownParser by adding abstract UiParser
- Multi-target net452, making MLEM compatible with MonoGame for consoles
Fixes
- Fixed parents of elements that prevent spill not being notified properly
@ -51,10 +53,19 @@ Additions
Improvements
- Allow data texture atlas pivots and offsets to be negative
- Made RuntimeTexturePacker restore texture region name and pivot when packing
- Multi-target net452, making MLEM compatible with MonoGame for consoles
Fixes
- Fixed data texture atlases not allowing most characters in their region names
## MLEM.Extended
Improvements
- Multi-target net452, making MLEM compatible with MonoGame for consoles
## MLEM.Startup
Improvements
- Multi-target net452, making MLEM compatible with MonoGame for consoles
## 6.0.0
### MLEM

View file

@ -7,6 +7,7 @@
<AssemblyName>MLEM Desktop Demos</AssemblyName>
<RootNamespace>Demos.DesktopGL</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
<!-- We still use the MG content builder for ease of compatibility between the MG and FNA demo projects -->
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
</PropertyGroup>

View file

@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Demos</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
</PropertyGroup>
<ItemGroup>

6
FNA.Settings.props Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
</ItemGroup>
</Project>

@ -1 +1 @@
Subproject commit 38849f3ac2887c14b8fa1c69c17468032e5233e1
Subproject commit 6e6fc608bee0d4e7b2944f7c686ca0d28896e195

View file

@ -12,6 +12,8 @@ namespace MLEM.Data.Json {
[DataContract]
public class JsonTypeSafeGenericDataHolder : IGenericDataHolder {
private static readonly string[] EmptyStrings = new string[0];
[DataMember(EmitDefaultValue = false)]
private Dictionary<string, JsonTypeSafeWrapper> data;
@ -35,9 +37,9 @@ namespace MLEM.Data.Json {
}
/// <inheritdoc />
public IReadOnlyCollection<string> GetDataKeys() {
public IEnumerable<string> GetDataKeys() {
if (this.data == null)
return Array.Empty<string>();
return JsonTypeSafeGenericDataHolder.EmptyStrings;
return this.data.Keys;
}

View file

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RootNamespace>MLEM.Data</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>NU1701</NoWarn>
<NoWarn>NU1701;MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -33,7 +33,8 @@
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\FNA\FNA.Core.csproj">
<ProjectReference Include="..\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<NoWarn>NU1701</NoWarn>

View file

@ -5,6 +5,7 @@
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RootNamespace>MLEM.Extended</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>NU1702;MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -22,10 +23,10 @@
<ItemGroup>
<ProjectReference Include="..\MLEM\MLEM.FNA.csproj" />
<ProjectReference Include="..\FontStashSharp\src\XNA\FontStashSharp.FNA.Core.csproj">
<ProjectReference Include="..\FontStashSharp\src\XNA\FontStashSharp.FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\FNA\FNA.Core.csproj">
<ProjectReference Include="..\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>

View file

@ -16,9 +16,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.FNA", "Tests\Tests.FN
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Extended.FNA", "MLEM.Extended\MLEM.Extended.FNA.csproj", "{A5B22930-DF4B-4A62-93ED-A6549F7B666B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA.Core", "FNA\FNA.Core.csproj", "{06459F72-CEAA-4B45-B2B1-708FC28D04F8}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA", "FNA\FNA.csproj", "{35253CE1-C864-4CD3-8249-4D1319748E8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FontStashSharp.FNA.Core", "FontStashSharp\src\XNA\FontStashSharp.FNA.Core.csproj", "{0B410591-3AED-4C82-A07A-516FF493709B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FontStashSharp.FNA", "FontStashSharp\src\XNA\FontStashSharp.FNA.csproj", "{39249E92-EBF2-4951-A086-AB4951C3CCE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA.Core", "FNA\FNA.Core.csproj", "{458FFA5E-A1C4-4B23-A5D8-259385FEECED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -58,13 +60,17 @@ Global
{A5B22930-DF4B-4A62-93ED-A6549F7B666B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5B22930-DF4B-4A62-93ED-A6549F7B666B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5B22930-DF4B-4A62-93ED-A6549F7B666B}.Release|Any CPU.Build.0 = Release|Any CPU
{06459F72-CEAA-4B45-B2B1-708FC28D04F8}.Debug|Any CPU.ActiveCfg = Debug|x64
{06459F72-CEAA-4B45-B2B1-708FC28D04F8}.Debug|Any CPU.Build.0 = Debug|x64
{06459F72-CEAA-4B45-B2B1-708FC28D04F8}.Release|Any CPU.ActiveCfg = Release|x64
{06459F72-CEAA-4B45-B2B1-708FC28D04F8}.Release|Any CPU.Build.0 = Release|x64
{0B410591-3AED-4C82-A07A-516FF493709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B410591-3AED-4C82-A07A-516FF493709B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B410591-3AED-4C82-A07A-516FF493709B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B410591-3AED-4C82-A07A-516FF493709B}.Release|Any CPU.Build.0 = Release|Any CPU
{35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.Build.0 = Release|Any CPU
{39249E92-EBF2-4951-A086-AB4951C3CCE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39249E92-EBF2-4951-A086-AB4951C3CCE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39249E92-EBF2-4951-A086-AB4951C3CCE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39249E92-EBF2-4951-A086-AB4951C3CCE1}.Release|Any CPU.Build.0 = Release|Any CPU
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Debug|Any CPU.ActiveCfg = Debug|x64
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Debug|Any CPU.Build.0 = Debug|x64
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Release|Any CPU.ActiveCfg = Release|x64
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Release|Any CPU.Build.0 = Release|x64
EndGlobalSection
EndGlobal

View file

@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RootNamespace>MLEM.Startup</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -21,11 +22,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coroutine" Version="2.1.3" />
<PackageReference Include="Coroutine" Version="2.1.4" />
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.FNA.csproj" />
<ProjectReference Include="..\MLEM\MLEM.FNA.csproj" />
<ProjectReference Include="..\FNA\FNA.Core.csproj">
<ProjectReference Include="..\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
@ -19,7 +19,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coroutine" Version="2.1.3" />
<PackageReference Include="Coroutine" Version="2.1.4" />
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" />
<ProjectReference Include="..\MLEM\MLEM.csproj" />

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>

View file

@ -6,7 +6,9 @@ using MLEM.Input;
using MLEM.Misc;
using MLEM.Textures;
using MLEM.Ui.Style;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using TextCopy;
#endif
namespace MLEM.Ui.Elements {
/// <summary>
@ -143,7 +145,11 @@ namespace MLEM.Ui.Elements {
/// <param name="text">The text that the text field should contain by default</param>
/// <param name="multiline">Whether the text field should support multi-line editing</param>
public TextField(Anchor anchor, Vector2 size, Rule rule = null, GenericFont font = null, string text = null, bool multiline = false) : base(anchor, size) {
this.textInput = new TextInput(null, Vector2.Zero, 1, null, ClipboardService.SetText, ClipboardService.GetText) {
this.textInput = new TextInput(null, Vector2.Zero, 1
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
, null, ClipboardService.SetText, ClipboardService.GetText
#endif
) {
OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s),
InputRule = (i, s) => this.InputRule.Invoke(this, s)
};

View file

@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RootNamespace>MLEM.Ui</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -20,10 +21,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TextCopy" Version="6.1.0" />
<PackageReference Include="TextCopy" Version="6.1.0" Condition="'$(TargetFramework)'!='net452'" />
<ProjectReference Include="..\MLEM\MLEM.FNA.csproj" />
<ProjectReference Include="..\FNA\FNA.Core.csproj">
<ProjectReference Include="..\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
@ -18,7 +18,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TextCopy" Version="6.1.0" />
<PackageReference Include="TextCopy" Version="6.1.0" Condition="'$(TargetFramework)'!='net452'" />
<ProjectReference Include="..\MLEM\MLEM.csproj" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Formatting;
@ -10,6 +9,12 @@ using MLEM.Textures;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using System.Net.Http;
#else
using System.Net;
#endif
namespace MLEM.Ui.Parsers {
/// <summary>
/// A base class for parsing various types of formatted strings into a set of MLEM.Ui elements with styling for each individual <see cref="ElementType"/>.
@ -148,15 +153,16 @@ namespace MLEM.Ui.Parsers {
try {
Texture2D tex;
if (path.StartsWith("http")) {
using (var client = new HttpClient()) {
using (var src = await client.GetStreamAsync(path)) {
using (var memory = new MemoryStream()) {
// download the full stream before passing it to texture
await src.CopyToAsync(memory);
tex = Texture2D.FromStream(this.GraphicsDevice, memory);
}
}
}
byte[] src;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using (var client = new HttpClient())
src = await client.GetByteArrayAsync(path);
#else
using (var client = new WebClient())
src = await client.DownloadDataTaskAsync(path);
#endif
using (var memory = new MemoryStream(src))
tex = Texture2D.FromStream(this.GraphicsDevice, memory);
} else {
using (var stream = Path.IsPathRooted(path) ? File.OpenRead(path) : TitleContainer.OpenStream(path))
tex = Texture2D.FromStream(this.GraphicsDevice, stream);

View file

@ -367,7 +367,7 @@ namespace MLEM.Ui {
protected virtual Element GetTabNextElement(bool backward) {
if (this.ActiveRoot == null)
return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Concat(Enumerable.Repeat(this.ActiveRoot.Element, 1))
// we can't add these checks to GetChildren because it ignores false grandchildren
.Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup);
if (this.SelectedElement?.Root != this.ActiveRoot) {
@ -402,7 +402,7 @@ namespace MLEM.Ui {
protected virtual Element GetGamepadNextElement(Direction2 direction) {
if (this.ActiveRoot == null)
return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Concat(Enumerable.Repeat(this.ActiveRoot.Element, 1))
// we can't add these checks to GetChildren because it ignores false grandchildren
.Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup);
if (this.SelectedElement?.Root != this.ActiveRoot) {

View file

@ -18,8 +18,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Data", "MLEM.Data\MLEM
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Templates", "MLEM.Templates\MLEM.Templates.csproj", "{C2A2CFED-C9E8-4675-BD66-EFC3DB210977}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demos.Android", "Demos.Android\Demos.Android.csproj", "{410C0262-131C-4D0E-910D-D01B4F7143E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{53D52C3F-67FB-4F32-A794-EAB140BBFC11}"
EndProject
Global
@ -64,10 +62,6 @@ Global
{C2A2CFED-C9E8-4675-BD66-EFC3DB210977}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2A2CFED-C9E8-4675-BD66-EFC3DB210977}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2A2CFED-C9E8-4675-BD66-EFC3DB210977}.Release|Any CPU.Build.0 = Release|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.Build.0 = Release|Any CPU
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Release|Any CPU.ActiveCfg = Release|Any CPU

View file

@ -25,7 +25,7 @@ namespace MLEM.Extensions {
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<IEnumerable<T>> things) {
var combos = Enumerable.Repeat(Enumerable.Empty<T>(), 1);
foreach (var t in things)
combos = combos.SelectMany(c => t.Select(c.Append));
combos = combos.SelectMany(c => t.Select(o => c.Concat(Enumerable.Repeat(o, 1))));
return combos;
}
@ -47,7 +47,7 @@ namespace MLEM.Extensions {
public static IEnumerable<IEnumerable<int>> IndexCombinations<T>(this IEnumerable<IEnumerable<T>> things) {
var combos = Enumerable.Repeat(Enumerable.Empty<int>(), 1);
foreach (var t in things)
combos = combos.SelectMany(c => t.Select((o, i) => c.Append(i)));
combos = combos.SelectMany(c => t.Select((o, i) => c.Concat(Enumerable.Repeat(i, 1))));
return combos;
}

View file

@ -20,6 +20,8 @@ namespace MLEM.Input {
#else
private static readonly int MaximumGamePadCount = GamePad.MaximumGamePadCount;
#endif
private static readonly TouchLocation[] EmptyTouchLocations = new TouchLocation[0];
private static readonly GenericInput[] EmptyGenericInputs = new GenericInput[0];
/// <summary>
/// Contains all of the gestures that have finished during the last update call.
@ -83,20 +85,20 @@ namespace MLEM.Input {
/// An array of all <see cref="Keys"/>, <see cref="Buttons"/> and <see cref="MouseButton"/> values that are currently down.
/// Additionally, <see cref="TryGetDownTime"/> or <see cref="GetDownTime"/> can be used to determine the amount of time that a given input has been down for.
/// </summary>
public GenericInput[] InputsDown { get; private set; } = Array.Empty<GenericInput>();
public GenericInput[] InputsDown { get; private set; } = InputHandler.EmptyGenericInputs;
/// <summary>
/// An array of all <see cref="Keys"/>, <see cref="Buttons"/> and <see cref="MouseButton"/> that are currently considered pressed.
/// An input is considered pressed if it was up in the last update, and is up in the current one.
/// </summary>
public GenericInput[] InputsPressed { get; private set; } = Array.Empty<GenericInput>();
public GenericInput[] InputsPressed { get; private set; } = InputHandler.EmptyGenericInputs;
/// <summary>
/// Contains the touch state from the last update call
/// </summary>
public TouchCollection LastTouchState { get; private set; } = new TouchCollection(Array.Empty<TouchLocation>());
public TouchCollection LastTouchState { get; private set; } = new TouchCollection(InputHandler.EmptyTouchLocations);
/// <summary>
/// Contains the current touch state
/// </summary>
public TouchCollection TouchState { get; private set; } = new TouchCollection(Array.Empty<TouchLocation>());
public TouchCollection TouchState { get; private set; } = new TouchCollection(InputHandler.EmptyTouchLocations);
/// <summary>
/// Contains the <see cref="LastTouchState"/>, but with the <see cref="GraphicsDevice.Viewport"/> taken into account.
/// </summary>
@ -281,7 +283,7 @@ namespace MLEM.Input {
this.LastTouchState = this.TouchState;
this.LastViewportTouchState = this.ViewportTouchState;
this.TouchState = active ? TouchPanel.GetState() : new TouchCollection(Array.Empty<TouchLocation>());
this.TouchState = active ? TouchPanel.GetState() : new TouchCollection(InputHandler.EmptyTouchLocations);
if (this.TouchState.Count > 0 && this.ViewportOffset != Point.Zero) {
this.ViewportTouchState = new List<TouchLocation>();
foreach (var touch in this.TouchState) {
@ -302,8 +304,8 @@ namespace MLEM.Input {
}
if (this.inputsDownAccum.Count <= 0 && this.inputsDown.Count <= 0) {
this.InputsPressed = Array.Empty<GenericInput>();
this.InputsDown = Array.Empty<GenericInput>();
this.InputsPressed = InputHandler.EmptyGenericInputs;
this.InputsDown = InputHandler.EmptyGenericInputs;
} else {
// handle pressed inputs
var pressed = new List<GenericInput>();

View file

@ -13,8 +13,10 @@ namespace MLEM.Input {
[DataContract]
public class Keybind : IComparable<Keybind>, IComparable {
private static readonly Combination[] EmptyCombinations = new Combination[0];
[DataMember]
private Combination[] combinations = Array.Empty<Combination>();
private Combination[] combinations = Keybind.EmptyCombinations;
/// <summary>
/// Creates a new keybind and adds the given key and modifiers using <see cref="Add(MLEM.Input.GenericInput,MLEM.Input.GenericInput[])"/>
@ -42,7 +44,7 @@ namespace MLEM.Input {
/// <param name="modifiers">The modifier keys that have to be held down.</param>
/// <returns>This keybind, for chaining</returns>
public Keybind Add(GenericInput key, params GenericInput[] modifiers) {
this.combinations = this.combinations.Append(new Combination(key, modifiers)).ToArray();
this.combinations = this.combinations.Concat(Enumerable.Repeat(new Combination(key, modifiers), 1)).ToArray();
return this;
}
@ -61,7 +63,7 @@ namespace MLEM.Input {
/// <param name="modifiers">The modifier keys that have to be held down.</param>
/// <returns>This keybind, for chaining.</returns>
public Keybind Insert(int index, GenericInput key, params GenericInput[] modifiers) {
this.combinations = this.combinations.Take(index).Append(new Combination(key, modifiers)).Concat(this.combinations.Skip(index)).ToArray();
this.combinations = this.combinations.Take(index).Concat(Enumerable.Repeat(new Combination(key, modifiers), 1)).Concat(this.combinations.Skip(index)).ToArray();
return this;
}
@ -77,7 +79,7 @@ namespace MLEM.Input {
/// </summary>
/// <returns>This keybind, for chaining</returns>
public Keybind Clear() {
this.combinations = Array.Empty<Combination>();
this.combinations = Keybind.EmptyCombinations;
return this;
}
@ -349,7 +351,7 @@ namespace MLEM.Input {
/// <param name="inputName">The function to use for determining the display name of a <see cref="GenericInput"/>. If this is null, the generic input's default <see cref="GenericInput.ToString"/> method is used.</param>
/// <returns>A human-readable string representing this combination</returns>
public string ToString(string joiner, Func<GenericInput, string> inputName = null) {
return string.Join(joiner, this.Modifiers.Append(this.Key).Select(i => inputName?.Invoke(i) ?? i.ToString()));
return string.Join(joiner, this.Modifiers.Concat(Enumerable.Repeat(this.Key, 1)).Select(i => inputName?.Invoke(i) ?? i.ToString()));
}
/// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.</summary>

View file

@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<RootNamespace>MLEM</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -20,9 +21,11 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.Core.csproj">
<ProjectReference Include="..\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="'$(TargetFramework)'=='net452'" />
</ItemGroup>
<ItemGroup>

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
@ -21,6 +21,8 @@
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="'$(TargetFramework)'=='net452'" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,8 @@ namespace MLEM.Misc {
[DataContract]
public class GenericDataHolder : IGenericDataHolder {
private static readonly string[] EmptyStrings = new string[0];
[DataMember(EmitDefaultValue = false)]
private Dictionary<string, object> data;
@ -34,9 +36,9 @@ namespace MLEM.Misc {
}
/// <inheritdoc />
public IReadOnlyCollection<string> GetDataKeys() {
public IEnumerable<string> GetDataKeys() {
if (this.data == null)
return Array.Empty<string>();
return GenericDataHolder.EmptyStrings;
return this.data.Keys;
}
@ -67,7 +69,7 @@ namespace MLEM.Misc {
/// Returns all of the generic data that this object stores.
/// </summary>
/// <returns>The generic data on this object</returns>
IReadOnlyCollection<string> GetDataKeys();
IEnumerable<string> GetDataKeys();
}
}

View file

@ -4,6 +4,7 @@
<VSTestLogger>nunit</VSTestLogger>
<RootNamespace>Tests</RootNamespace>
<DefineConstants>$(DefineConstants);FNA</DefineConstants>
<NoWarn>MSB3270</NoWarn>
</PropertyGroup>
<ItemGroup>

View file

@ -8,7 +8,8 @@ var branch = Argument("branch", "main");
var config = Argument("configuration", "Release");
Task("Prepare").Does(() => {
DotNetCoreRestore("MLEM.sln");
DotNetRestore("MLEM.sln");
DotNetRestore("MLEM.FNA.sln");
if (branch != "release") {
var buildNum = EnvironmentVariable("BUILD_NUMBER");
@ -20,32 +21,30 @@ Task("Prepare").Does(() => {
});
Task("Build").IsDependentOn("Prepare").Does(() =>{
var settings = new DotNetCoreBuildSettings {
var settings = new DotNetBuildSettings {
Configuration = config,
ArgumentCustomization = args => args.Append($"/p:Version={version}")
};
foreach (var project in GetFiles("**/MLEM*.csproj"))
DotNetCoreBuild(project.FullPath, settings);
DotNetCoreBuild("Demos/Demos.csproj", settings);
DotNetCoreBuild("Demos/Demos.FNA.csproj", settings);
DotNetBuild("MLEM.sln", settings);
DotNetBuild("MLEM.FNA.sln", settings);
});
Task("Test").IsDependentOn("Build").Does(() => {
var settings = new DotNetCoreTestSettings {
var settings = new DotNetTestSettings {
Configuration = config,
Collectors = {"XPlat Code Coverage"}
};
DotNetCoreTest("Tests/Tests.csproj", settings);
DotNetCoreTest("Tests/Tests.FNA.csproj", settings);
DotNetTest("MLEM.sln", settings);
DotNetTest("MLEM.FNA.sln", settings);
});
Task("Pack").IsDependentOn("Test").Does(() => {
var settings = new DotNetCorePackSettings {
var settings = new DotNetPackSettings {
Configuration = config,
ArgumentCustomization = args => args.Append($"/p:Version={version}")
};
foreach (var project in GetFiles("**/MLEM*.csproj"))
DotNetCorePack(project.FullPath, settings);
DotNetPack(project.FullPath, settings);
});
Task("Push").WithCriteria(branch == "main" || branch == "release").IsDependentOn("Pack").Does(() => {