Skip to content

Commit

Permalink
Liczne poprawki
Browse files Browse the repository at this point in the history
Polska wersja jeszcze wymaga zmian
  • Loading branch information
mateusz-kierepka-hl committed Dec 22, 2024
1 parent 590f3c1 commit c2d6a7d
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 193 deletions.
35 changes: 18 additions & 17 deletions ChatAAC/ChatAAC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@
<UseWPF>false</UseWPF>
<UseWindowsForms>false</UseWindowsForms>
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.4"/>
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.4"/>
<PackageReference Include="Avalonia.Desktop" Version="11.1.4"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.4"/>
<PackageReference Include="Avalonia.Svg" Version="11.1.0.1"/>
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0.1"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.4"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.4"/>
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.3" />
<PackageReference Include="Avalonia.Svg" Version="11.2.0.2" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.2.0.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.4"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0.4"/>
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.1.0.4"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.1" />
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.2.0.1" />
<PackageReference Include="BinToss.GroupBox.Avalonia" Version="1.0.0"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2"/>
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.10"/>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.24.1"/>
<PackageReference Include="OllamaSharp" Version="3.0.14"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.32.0" />
<PackageReference Include="OllamaSharp" Version="4.0.11" />
<PackageReference Include="ReactiveUI" Version="20.1.63"/>
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41"/>
<PackageReference Include="RestSharp" Version="112.1.0"/>
<PackageReference Include="SkiaSharp" Version="2.88.8"/>
<PackageReference Include="System.Net.Http.Json" Version="8.0.1"/>
<PackageReference Include="System.Speech" Version="8.0.0"/>
<PackageReference Include="SkiaSharp" Version="3.116.1" />
<PackageReference Include="System.Net.Http.Json" Version="9.0.0" />
<PackageReference Include="System.Speech" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
53 changes: 53 additions & 0 deletions ChatAAC/Converters/IdConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ChatAAC.Converters;


/// <summary>
/// Custom JSON converter for handling 'id' values. Converts the value to an integer.
/// </summary>
public class IdConverter : JsonConverter<int>
{
/// <summary>
/// Reads and converts the JSON data to an integer.
/// </summary>
/// <param name="reader">The Utf8JsonReader to read from.</param>
/// <param name="typeToConvert">The type to convert to. In this case, it's always int.</param>
/// <param name="options">The JsonSerializerOptions to use during deserialization.</param>
/// <returns>The converted integer value.</returns>
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// If the value is a number, return it as an int
if (reader.TokenType == JsonTokenType.Number)
{
return reader.GetInt32();
}
// If the value is a string, try to convert it to an integer
else if (reader.TokenType == JsonTokenType.String)
{
if (int.TryParse(reader.GetString(), out var result))
{
return result;
}
throw new JsonException($"Unable to convert string to int: {reader.GetString()}");
}
else
{
throw new JsonException($"Unexpected token {reader.TokenType} when parsing id.");
}
}

/// <summary>
/// Writes the integer value as JSON data.
/// </summary>
/// <param name="writer">The Utf8JsonWriter to write to.</param>
/// <param name="value">The integer value to write.</param>
/// <param name="options">The JsonSerializerOptions to use during serialization.</param>
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
// Write as an int
writer.WriteNumberValue(value);
}
}
99 changes: 99 additions & 0 deletions ChatAAC/Converters/OrderConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ChatAAC.Converters;

/// <summary>
/// Custom JSON converter for a 2D array of nullable integers.
/// This converter is used to serialize and deserialize the 'order' property in a grid.
/// </summary>
public class OrderConverter : JsonConverter<int?[][]>
{
/// <summary>
/// Reads and converts the JSON to a 2D array of nullable integers.
/// </summary>
/// <param name="reader">The Utf8JsonReader to read from.</param>
/// <param name="typeToConvert">The type to convert to.</param>
/// <param name="options">The JsonSerializerOptions to use.</param>
/// <returns>A 2D array of nullable integers.</returns>
public override int?[][] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// Ensure the token is a start array
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected start of array");
}

var result = new List<int?[]>();

// Read each row of the array
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
break;

if (reader.TokenType != JsonTokenType.StartArray)
throw new JsonException("Expected start of inner array");

var innerList = new List<int?>();

// Read values in the array
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
break;

if (reader.TokenType == JsonTokenType.Null)
{
innerList.Add(null);
}
else if (reader.TokenType == JsonTokenType.Number)
{
innerList.Add(reader.GetInt32());
}
else
{
throw new JsonException("Expected number or null");
}
}

result.Add(innerList.ToArray());
}

return result.ToArray();
}

/// <summary>
/// Writes a 2D array of nullable integers as JSON.
/// </summary>
/// <param name="writer">The Utf8JsonWriter to write to.</param>
/// <param name="value">The value to convert to JSON.</param>
/// <param name="options">The JsonSerializerOptions to use.</param>
public override void Write(Utf8JsonWriter writer, int?[][] value, JsonSerializerOptions options)
{
writer.WriteStartArray();

foreach (var innerArray in value)
{
writer.WriteStartArray();

foreach (var item in innerArray)
{
if (item.HasValue)
{
writer.WriteNumberValue(item.Value);
}
else
{
writer.WriteNullValue();
}
}

writer.WriteEndArray();
}

writer.WriteEndArray();
}
}
2 changes: 1 addition & 1 deletion ChatAAC/Converters/StringToBitmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class StringToBitmapConverter : IValueConverter
canvas.Clear(SKColors.Transparent);

var matrix = SKMatrix.CreateScale(scale, scale);
canvas.DrawPicture(svg.Picture, ref matrix);
canvas.DrawPicture(svg.Picture, in matrix);
canvas.Flush();

// Konwersja SKBitmap na Bitmapę Avalonii
Expand Down
38 changes: 25 additions & 13 deletions ChatAAC/Models/Obf/Button.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
using System.Text.Json.Serialization;
using ChatAAC.Converters;

namespace ChatAAC.Models.Obf;

// Class for Button
public class Button
namespace ChatAAC.Models.Obf
{
[JsonPropertyName("id")] public string Id { get; set; } = string.Empty;
// Klasa reprezentująca przycisk
public class Button
{
[JsonPropertyName("id")]
[JsonConverter(typeof(IdConverter))]
public int Id { get; set; }

[JsonPropertyName("label")] public string Label { get; set; } = string.Empty;
[JsonPropertyName("label")]
public string Label { get; set; } = string.Empty; // Upewniamy się, że label jest stringiem

[JsonPropertyName("image_id")] public string ImageId { get; set; } = string.Empty;
[JsonPropertyName("image_id")]
public string ImageId { get; set; } = string.Empty;

[JsonPropertyName("border_color")] public string BorderColor { get; set; } = string.Empty;
[JsonPropertyName("border_color")]
public string BorderColor { get; set; } = string.Empty;

[JsonPropertyName("background_color")] public string BackgroundColor { get; set; } = string.Empty;
[JsonPropertyName("background_color")]
public string BackgroundColor { get; set; } = string.Empty;

[JsonPropertyName("vocalization")] public string Vocalization { get; set; } = string.Empty;
[JsonPropertyName("vocalization")]
public string Vocalization { get; set; } = string.Empty;

[JsonPropertyName("load_board")] public LoadBoard? LoadBoard { get; set; }
[JsonPropertyName("load_board")]
public LoadBoard? LoadBoard { get; set; }

[JsonPropertyName("action")] public string Action { get; set; } = string.Empty;
[JsonPropertyName("action")]
public string Action { get; set; } = string.Empty;

[JsonIgnore] public Image? Image { get; set; }
[JsonIgnore]
public Image? Image { get; set; }
}
}
5 changes: 4 additions & 1 deletion ChatAAC/Models/Obf/Grid.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using ChatAAC.Converters;

namespace ChatAAC.Models.Obf;

Expand All @@ -9,5 +10,7 @@ public class Grid

[JsonPropertyName("columns")] public int Columns { get; set; }

[JsonPropertyName("order")] public string?[][] Order { get; set; } = [];
[JsonPropertyName("order")]
[JsonConverter(typeof(OrderConverter))]
public int?[][] Order { get; set; } = [];
}
6 changes: 3 additions & 3 deletions ChatAAC/Models/Obf/ObfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class ObfFile
[JsonPropertyName("description_html")] public string DescriptionHtml { get; set; } = string.Empty;

[JsonPropertyName("grid")] public Grid? Grid { get; set; }
[JsonPropertyName("buttons")] public List<Button> Buttons { get; set; } = new();
[JsonPropertyName("images")] public List<Image> Images { get; set; } = new();
[JsonPropertyName("buttons")] public List<Button> Buttons { get; set; } = [];
[JsonPropertyName("images")] public List<Image> Images { get; set; } = [];

[JsonPropertyName("sounds")] public List<Sound> Sounds { get; set; } = new();
[JsonPropertyName("sounds")] public List<Sound> Sounds { get; set; } = [];

[JsonPropertyName("default_layout")] public string DefaultLayout { get; set; } = string.Empty;

Expand Down
Loading

0 comments on commit c2d6a7d

Please sign in to comment.