Skip to content

Commit

Permalink
risolto il bug che se si cancella il mazzo il programma non si avvia più
Browse files Browse the repository at this point in the history
risolto il bug che se si cambia livello quando bisogna vedere le cate giocate dopo nin è più òpossibile giocare
  • Loading branch information
GiulianoSpaghetti committed Feb 5, 2024
1 parent 94fe1ff commit 9e8cc3e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
19 changes: 15 additions & 4 deletions CBriscola.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using System;

namespace CBriscola.Avalonia
{
public partial class App : Application
{
public static string separator="\\";
public static string SistemaOperativo="Windows";
public static string path = "C:\\Program Files\\wxBriscola";
public static string SistemaOperativo;
public static string path;

public override void Initialize()
{
Expand All @@ -18,8 +18,19 @@ public override void Initialize()

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (OperatingSystem.IsWindows())
{
path = "C:\\Program Files\\wxBriscola";
SistemaOperativo = Environment.OSVersion.ToString();
}
else if (OperatingSystem.IsLinux())
{
SistemaOperativo = "GNU/Linux";
path = "/usr/share/wxBriscola";
}

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
}

Expand Down
12 changes: 6 additions & 6 deletions CBriscola.Avalonia/CBriscola.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand All @@ -20,12 +20,12 @@


<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.5" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.5" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.5" />
<PackageReference Include="Avalonia" Version="11.0.7" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.7" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.7" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.7" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.5" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.7" />
<PackageReference Include="DesktopNotifications" Version="1.3.1" />
<PackageReference Include="DesktopNotifications.Apple" Version="1.3.1" />
<PackageReference Include="DesktopNotifications.FreeDesktop" Version="1.3.1" />
Expand Down
14 changes: 12 additions & 2 deletions CBriscola.Avalonia/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<x:String x:Key="LivelloCambiato">Il Livello è cambiato</x:String>
<x:String x:Key="PartitaRiavviata">Comincerà una nuova partita</x:String>
<x:String x:Key="EffettuaSecondaPartita">Vuoi effettuare la seconda partita</x:String>
<x:String x:Key="MazzoNonTrovatoTitolo">Impossibile trovare il mazzo personalizzato</x:String>
<x:String x:Key="MazzoNonTrovatoTesto">Impossibile trovare il mazzo personalizzato, probabilmente è stato cancellato. Verrà caricato il mazzo Napoletano.</x:String>
</ResourceDictionary>
<ResourceDictionary x:Key="en">
<x:String x:Key="PuntiDiPrefisso">&#160;</x:String>
Expand Down Expand Up @@ -100,7 +102,9 @@
<x:String x:Key="Livello">CPU Level</x:String>
<x:String x:Key="LivelloCambiato">The level has changed</x:String>
<x:String x:Key="PartitaRiavviata">A new game will start</x:String>
<x:String x:Key="EffettuaSecondaPartita">Do you want to play a second game</x:String>
<x:String x:Key="EffettuaSecondaPartita">do you want to play a second game</x:String>
<x:String x:Key="MazzoNonTrovatoTitolo">Cannot find custom deck</x:String>
<x:String x:Key="MazzoNonTrovatoTesto">The custom deck could not be found, it has probably been deleted. The Neapolitan deck will be loaded.</x:String>
</ResourceDictionary>
<ResourceDictionary x:Key="de">
<x:String x:Key="PuntiDiPrefisso">&#160;</x:String>
Expand Down Expand Up @@ -145,6 +149,8 @@
<x:String x:Key="LivelloCambiato">Level hat sich geändert</x:String>
<x:String x:Key="PartitaRiavviata">Ein neues Spiel beginnt</x:String>
<x:String x:Key="EffettuaSecondaPartita">Spielt er ein zweites Spiel</x:String>
<x:String x:Key="MazzoNonTrovatoTitolo">Benutzerdefiniertes Deck kann nicht gefunden werden</x:String>
<x:String x:Key="MazzoNonTrovatoTesto">Das benutzerdefinierte Deck konnte nicht gefunden werden, es wurde wahrscheinlich gelöscht. Das neapolitanische Deck wird geladen.</x:String>
</ResourceDictionary>
<ResourceDictionary x:Key="fr">
<x:String x:Key="PuntiDiPrefisso">Points de</x:String>
Expand Down Expand Up @@ -188,7 +194,9 @@
<x:String x:Key="Livello">niveau processeur</x:String>
<x:String x:Key="LivelloCambiato">Le niveau a changé</x:String>
<x:String x:Key="PartitaRiavviata">Un nouveau jeu va commencer</x:String>
<x:String x:Key="EffettuaSecondaPartita">Est-ce qu'il joue un deuxième jeu</x:String>
<x:String x:Key="EffettuaSecondaPartita">est-ce qu'il joue un deuxième jeu</x:String>
<x:String x:Key="MazzoNonTrovatoTitolo">Impossible de trouver un deck personnalisé</x:String>
<x:String x:Key="MazzoNonTrovatoTesto">Le deck personnalisé est introuvable, il a probablement été supprimé. Le jeu napolitain sera chargé.</x:String>
</ResourceDictionary>
<ResourceDictionary x:Key="es">
<x:String x:Key="PuntiDiPrefisso">Puntos de</x:String>
Expand Down Expand Up @@ -233,6 +241,8 @@
<x:String x:Key="LivelloCambiato">El nivel ha cambiado</x:String>
<x:String x:Key="PartitaRiavviata">Comenzará un nuevo juego</x:String>
<x:String x:Key="EffettuaSecondaPartita">¿Hace un segundo juego</x:String>
<x:String x:Key="MazzoNonTrovatoTitolo">No se puede encontrar el mazo personalizado</x:String>
<x:String x:Key="MazzoNonTrovatoTesto">No se pudo encontrar la plataforma personalizada, probablemente se haya eliminado. Se cargará la baraja napolitana.</x:String>
</ResourceDictionary>
</Window.Resources>
<Window.Content>
Expand Down
33 changes: 19 additions & 14 deletions CBriscola.Avalonia/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
using Avalonia.Controls.Shapes;
using DesktopNotifications;
using DesktopNotifications.FreeDesktop;
using DesktopNotifications.Windows;
using System.Runtime.InteropServices;
using DesktopNotifications.Apple;
using Avalonia.Controls.Notifications;
using INotificationManager = DesktopNotifications.INotificationManager;
using Notification= DesktopNotifications.Notification;

namespace CBriscola.Avalonia
{
Expand All @@ -47,10 +48,10 @@ private static INotificationManager CreateManager()
return new FreeDesktopNotificationManager();

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return new WindowsNotificationManager();
return new DesktopNotifications.Windows.WindowsNotificationManager(null);

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return new AppleNotificationManager();
return new DesktopNotifications.Apple.AppleNotificationManager();

throw new PlatformNotSupportedException();
}
Expand All @@ -66,9 +67,9 @@ public MainWindow()
m = new Mazzo(e);
o = LeggiOpzioni(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
m.SetNome(o.nomeMazzo);

Carta.Inizializza(m, 40, CartaHelperBriscola.GetIstanza(e), d);
if (o.nomeMazzo == "Napoletano")

if (o.nomeMazzo == "Napoletano")
{
asset = AssetLoader.Open(new Uri($"avares://{Assembly.GetEntryAssembly().GetName().Name}/Assets/retro_carte_pc.png"));
cartaCpu.Source = new Bitmap(asset);
Expand All @@ -77,7 +78,7 @@ public MainWindow()
else
try
{
cartaCpu.Source = new Bitmap($"{App.path}{App.separator}Mazzi{App.separator}{m.GetNome()}{App.separator}retro carte pc.png");
cartaCpu.Source = new Bitmap($"{System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.Combine(App.path,"Mazzi"),m.GetNome()))}retro carte pc.png");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -147,12 +148,13 @@ private Opzioni CaricaOpzioni()
private Opzioni LeggiOpzioni(String folder)
{
Opzioni o;
if (!Directory.Exists($"{folder}{App.separator}CBriscola.Avalonia"))
Directory.CreateDirectory($"{folder}{App.separator}CBriscola.Avalonia");
folder= System.IO.Path.Combine(folder,"CBriscola.Avalonia");
if (!System.IO.Path.Exists(folder))
Directory.CreateDirectory(folder);
StreamReader file;
try
{
file = new StreamReader($"{folder}{App.separator}CBriscola.Avalonia{App.separator}opzioni.json");
file = new StreamReader($"{System.IO.Path.Combine(folder, "opzioni.json")}");
}
catch (FileNotFoundException ex)
{
Expand All @@ -174,7 +176,8 @@ private Opzioni LeggiOpzioni(String folder)

private void SalvaOpzioni(String folder, Opzioni o)
{
StreamWriter w = new StreamWriter($"{folder}{App.separator}CBriscola.Avalonia{App.separator}opzioni.json");
folder= System.IO.Path.Combine(folder,"CBriscola.Avalonia");
StreamWriter w = new StreamWriter($"{System.IO.Path.Combine(folder, "opzioni.json")}");
w.Write(Newtonsoft.Json.JsonConvert.SerializeObject(o));
w.Close();
}
Expand Down Expand Up @@ -335,7 +338,7 @@ private void OnOpzioni_Click(object sender, RoutedEventArgs e)
cbLivello.SelectedIndex = helper.GetLivello() - 1;
ListBoxItem item;
String s1 = "";
string dirs = $"{App.path}{App.separator}Mazzi";
string dirs = System.IO.Path.Combine(App.path,"Mazzi");

try
{
Expand All @@ -347,7 +350,7 @@ private void OnOpzioni_Click(object sender, RoutedEventArgs e)
}
for (UInt16 i=0; i<path.Count; i++)
{
path[i] = path[i].Substring(path[i].LastIndexOf(App.separator) + 1);
path[i] = path[i].Substring(path[i].LastIndexOf(System.IO.Path.DirectorySeparatorChar)+1);

}
if (!path.Contains("Napoletano"))
Expand Down Expand Up @@ -394,6 +397,7 @@ private void NuovaPartita()

}
cpu = new Giocatore(helper, cpu.GetNome(), 3);
g = new Giocatore(new GiocatoreHelperUtente(), g.GetNome(), 3);
for (UInt16 i = 0; i < 3; i++)
{
g.AddCarta(m);
Expand Down Expand Up @@ -423,6 +427,7 @@ private void NuovaPartita()
Briscola.Source = briscola.GetImmagine();
Briscola.IsVisible = true;
primaUtente = !primaUtente;
btnGiocata.IsVisible=false;
if (primaUtente)
{
primo = g;
Expand Down Expand Up @@ -528,7 +533,7 @@ public void OnOk_Click(Object source, RoutedEventArgs evt)
if (m.GetNome() != "Napoletano")
try
{
cartaCpu.Source = new Bitmap($"{App.path}{App.separator}Mazzi{App.separator}{m.GetNome()}{App.separator}retro carte pc.png");
cartaCpu.Source = new Bitmap($"{System.IO.Path.Combine(System.IO.Path.Combine(App.path,m.GetNome()),"retro carte pc.png")}");
}
catch (System.IO.FileNotFoundException ex)
{
Expand Down
9 changes: 5 additions & 4 deletions CBriscola.Avalonia/carta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,30 @@ public Bitmap GetImmagine()
return img;
}

public static void CaricaImmagini(Mazzo m, ushort n, CartaHelperBriscola helper, ResourceDictionary d)
public static bool CaricaImmagini(Mazzo m, ushort n, CartaHelperBriscola helper, ResourceDictionary d)
{
String s = $"{App.path}{App.separator}Mazzi{App.separator}";
String s = $"{System.IO.Path.Combine(App.path, "Mazzi")}";
for (UInt16 i = 0; i < n; i++)
{
Stream asset;
if (m.GetNome() != "Napoletano")
try
{
carte[i].img = new Bitmap(s + m.GetNome() + App.separator + i + ".png");
carte[i].img = new Bitmap($"{System.IO.Path.Combine(Path.Combine(s, m.GetNome()))}{i}.png");
}
catch (Exception ex)
{
m.SetNome("Napoletano");
CaricaImmagini(m, n, helper, d);
return;
return false;
}
else
{
carte[i].img = new Bitmap(AssetLoader.Open(new Uri($"avares://{Assembly.GetEntryAssembly().GetName().Name}/Assets/{i}.png")));
}
carte[i].semeStr = helper.GetSemeStr(i, m.GetNome(), d);
}
return true;
}
}
}
12 changes: 6 additions & 6 deletions setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "CBriscola.Avalonia"
#define MyAppVersion "0.7.6"
#define MyAppVersion "0.7.7"
#define MyAppPublisher "Giulio Sorrentino"
#define MyAppURL "https://github.com/numerunix/cbriscola.avalonia"
#define MyAppExeName "CBriscola.Avalonia.exe"
Expand All @@ -20,11 +20,11 @@ AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf64}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=C:\Users\numer\source\repos\CBriscola.Avalonia\LICENSE.txt
LicenseFile=D:\source\CBriscola.Avalonia\LICENSE.txt
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\numer
OutputBaseFilename=cbriscola.avalonia-0.7.6-x64
OutputBaseFilename=cbriscola.avalonia-0.7.7-x64
Compression=lzma
SolidCompression=yes
WizardStyle=modern
Expand Down Expand Up @@ -62,9 +62,9 @@ Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Users\numer\source\repos\CBriscola.Avalonia\CBriscola.Avalonia\bin\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\numer\source\repos\CBriscola.Avalonia\CBriscola.Avalonia\bin\Release\net7.0-windows10.0.22621.0\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\numer\source\repos\CBriscola.Avalonia\opzioni.json"; DestDir: "{localappdata}\CBriscola.Avalonia"; Flags: ignoreversion
Source: "D:\source\CBriscola.Avalonia\CBriscola.Avalonia\bin\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\source\CBriscola.Avalonia\CBriscola.Avalonia\bin\Release\net8.0-windows10.0.22621.0\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\source\CBriscola.Avalonia\opzioni.json"; DestDir: "{localappdata}\CBriscola.Avalonia"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Expand Down

0 comments on commit 9e8cc3e

Please sign in to comment.