Skip to content
This repository was archived by the owner on Apr 8, 2022. It is now read-only.

Commit ffa32df

Browse files
committed
Added UI
1 parent eddc9a9 commit ffa32df

File tree

15 files changed

+309
-3
lines changed

15 files changed

+309
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/.idea
22
/Tappy/bin
3-
/Tappy/obj
3+
/Tappy/obj
4+
/Tappy-UI/bin
5+
/Tappy-UI/obj
6+
/.vs

Tappy-UI/App.axaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:local="using:Tappy_UI"
4+
x:Class="Tappy_UI.App">
5+
<Application.DataTemplates>
6+
<local:ViewLocator/>
7+
</Application.DataTemplates>
8+
9+
<Application.Styles>
10+
<FluentTheme Mode="Dark"/>
11+
</Application.Styles>
12+
</Application>

Tappy-UI/App.axaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Markup.Xaml;
4+
using Tappy_UI.ViewModels;
5+
using Tappy_UI.Views;
6+
7+
namespace Tappy_UI
8+
{
9+
public class App : Application
10+
{
11+
public override void Initialize()
12+
{
13+
AvaloniaXamlLoader.Load(this);
14+
}
15+
16+
public override void OnFrameworkInitializationCompleted()
17+
{
18+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
19+
{
20+
desktop.MainWindow = new MainWindow
21+
{
22+
DataContext = new MainWindowViewModel(),
23+
};
24+
}
25+
26+
base.OnFrameworkInitializationCompleted();
27+
}
28+
}
29+
}

Tappy-UI/Assets/avalonia-logo.ico

172 KB
Binary file not shown.

Tappy-UI/Program.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.ReactiveUI;
4+
using System;
5+
6+
namespace Tappy_UI
7+
{
8+
class Program
9+
{
10+
// Initialization code. Don't use any Avalonia, third-party APIs or any
11+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
12+
// yet and stuff might break.
13+
public static void Main(string[] args) => BuildAvaloniaApp()
14+
.StartWithClassicDesktopLifetime(args);
15+
16+
// Avalonia configuration, don't remove; also used by visual designer.
17+
public static AppBuilder BuildAvaloniaApp()
18+
=> AppBuilder.Configure<App>()
19+
.UsePlatformDetect()
20+
.LogToTrace()
21+
.UseReactiveUI();
22+
}
23+
}

Tappy-UI/Tappy-UI.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Folder Include="Models\" />
9+
<AvaloniaResource Include="Assets\**" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Avalonia" Version="0.10.0" />
13+
<PackageReference Include="Avalonia.Desktop" Version="0.10.0" />
14+
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0" />
15+
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0" />
16+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
17+
</ItemGroup>
18+
</Project>

Tappy-UI/ViewLocator.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Controls.Templates;
3+
using System;
4+
using Tappy_UI.ViewModels;
5+
6+
namespace Tappy_UI
7+
{
8+
public class ViewLocator : IDataTemplate
9+
{
10+
public bool SupportsRecycling => false;
11+
12+
public IControl Build(object data)
13+
{
14+
var name = data.GetType().FullName!.Replace("ViewModel", "View");
15+
var type = Type.GetType(name);
16+
17+
if (type != null)
18+
{
19+
return (Control)Activator.CreateInstance(type)!;
20+
}
21+
else
22+
{
23+
return new TextBlock { Text = "Not Found: " + name };
24+
}
25+
}
26+
27+
public bool Match(object data)
28+
{
29+
return data is ViewModelBase;
30+
}
31+
}
32+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
using System.Linq;
6+
using Newtonsoft.Json;
7+
namespace Tappy_UI.ViewModels
8+
{
9+
public class MainWindowViewModel : ViewModelBase
10+
{
11+
public string Greeting => "Welcome to Avalonia!";
12+
13+
public void ButtonClicked() {
14+
Random random = new Random();
15+
Console.WriteLine("Tappy | Tappable Loot Table Generation System");
16+
17+
/* Load Data Files */
18+
Console.WriteLine("Loading data files");
19+
Directory.CreateDirectory("./inputdata");
20+
string[] files = Directory.GetFiles("./inputdata", "*.json");
21+
Directory.CreateDirectory("./outputdata");
22+
foreach (string filePath in files)
23+
{
24+
Utils.TableData tableData = JsonConvert.DeserializeObject<Utils.TableData>(File.ReadAllText(filePath));
25+
Console.WriteLine("Processing Tappable Data for tappable type " + tableData.tappableID);
26+
Utils.TappableLootTable resultLootTable = new Utils.TappableLootTable();
27+
resultLootTable.possibleDropSets ??= new List<List<string>>();
28+
resultLootTable.tappableID = tableData.tappableID;
29+
//we generate 100 dropTables (no, not Bobby Tables drop tables)
30+
for (int i = 0; i < 100; i++)
31+
{
32+
List<string> rewards = new List<string>();
33+
//how many do we want
34+
int numRewards = random.Next(tableData.minItemsPerTap, tableData.maxItemsPerTap);
35+
Console.WriteLine("Set " + i + " Will have " + numRewards + " rewards.");
36+
for (int i2 = 0; i2 < numRewards; i2++)
37+
{
38+
while (true)
39+
{
40+
//we get a random item from the table
41+
int randIndex = random.Next(0, tableData.percentages.Count);
42+
var targetItem = tableData.percentages.ElementAt(randIndex);
43+
//try and add it based on percentage
44+
int roll = random.Next(0, 100);
45+
Console.WriteLine("Got role of " + roll + " for item with percentage " + targetItem.Value + " Target item: " + targetItem.Key);
46+
if (targetItem.Value <= roll || targetItem.Value == 100)
47+
{
48+
Console.WriteLine("Added item to rewards");
49+
rewards.Add(targetItem.Key);
50+
break;
51+
}
52+
}
53+
}
54+
//Add our rewards to the main loot table
55+
resultLootTable.possibleDropSets.Add(rewards);
56+
}
57+
//Now we save it
58+
string table = JsonConvert.SerializeObject(resultLootTable);
59+
// Console.WriteLine(table);
60+
File.WriteAllText("./outputdata/" + resultLootTable.tappableID.Split(":")[1] + ".json", table);
61+
}
62+
Console.WriteLine("Done! ");
63+
}
64+
}
65+
}

Tappy-UI/ViewModels/Utils.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Tappy_UI
6+
{
7+
public class Utils{
8+
public class TableData
9+
{
10+
public string tappableID { get; set; }
11+
public int maxItemsPerTap { get; set; }
12+
public int minItemsPerTap { get; set; }
13+
public Dictionary<string, int> percentages { get; set; }
14+
}
15+
16+
public class TappableLootTable
17+
{
18+
public string tappableID { get; set; }
19+
public List<List<string>> possibleDropSets { get; set; }
20+
}
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using ReactiveUI;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Tappy_UI.ViewModels
7+
{
8+
public class ViewModelBase : ReactiveObject
9+
{
10+
}
11+
}

0 commit comments

Comments
 (0)