Skip to content

Commit

Permalink
Release 2.5.0 (#211)
Browse files Browse the repository at this point in the history
- Re-desgin Farming tab UI (time setting works now)
- Remove TTWars from auto build system (you will need to compile it in local and  fix parser system yourself because of TTWars's UI changes) (why I (VINAGHOST) don't fix ? I don't play on TTWars and since no donations for that, i prefer on Official version)
  • Loading branch information
vinaghost authored Feb 4, 2023
1 parent 4f516f9 commit 96a43a1
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TTWARS]
server: [TRAVIAN_OFFICIAL]
runs-on: windows-2019
steps:
- name: Setup dotnet
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
needs: version
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TTWARS]
server: [TRAVIAN_OFFICIAL]
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -84,15 +84,14 @@ jobs:
- name: Archive release
run: |
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" ../; cd ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
- name: Create release
uses: ncipollo/release-action@v1
with:
name: TBS-${{needs.version.outputs.version}}
tag: ${{needs.version.outputs.version}}
commit: master
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip"
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
Expand Down Expand Up @@ -124,7 +123,7 @@ jobs:
needs: release
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TTWARS]
server: [TRAVIAN_OFFICIAL]
steps:
- name: Delete artifact
uses: geekyeggo/delete-artifact@v1
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
needs: version
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TTWARS]
server: [TRAVIAN_OFFICIAL]
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -83,7 +83,6 @@ jobs:
- name: Archive release
run: |
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" ../; cd ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
- name: Create release
uses: ncipollo/release-action@v1
Expand Down Expand Up @@ -122,7 +121,7 @@ jobs:
needs: release
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TTWARS]
server: [TRAVIAN_OFFICIAL]
steps:
- name: Delete artifact
uses: geekyeggo/delete-artifact@v1
Expand Down
1 change: 1 addition & 0 deletions MainCore/Services/Implementations/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private void Loop(int index)
else
{
var result = poliResult.Result;
if (result is null) result = poliResult.FinalHandledResult;
if (result.IsFailed)
{
task.Stage = TaskStage.Waiting;
Expand Down
2 changes: 2 additions & 0 deletions MainCore/Tasks/Update/UpdateInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentResults;
using MainCore.Enums;
using MainCore.Errors;
using MainCore.Models.Database;
using ModuleCore.Parser;
using Splat;
Expand All @@ -26,6 +27,7 @@ public UpdateInfo(int accountId, CancellationToken cancellationToken = default)

public override Result Execute()
{
if (CancellationToken.IsCancellationRequested) return Result.Fail(new Cancel());
UpdateAccountInfo();
UpdateVillageList();
UpdateHeroInfo();
Expand Down
5 changes: 0 additions & 5 deletions WPFUI/AppBoostrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using WPFUI.ViewModels.Tabs;
using WPFUI.ViewModels.Tabs.Villages;
using WPFUI.ViewModels.Uc.BuildView;
using WPFUI.ViewModels.Uc.FarmingView;
using WPFUI.ViewModels.Uc.MainView;

namespace WPFUI
Expand Down Expand Up @@ -73,10 +72,6 @@ public static IServiceCollection ConfigureUcViewModel(this IServiceCollection se
services.AddSingleton<MainButtonPanelViewModel>();
services.AddSingleton<AccountListViewModel>();

// farming view
services.AddSingleton<FarmListViewModel>();
services.AddSingleton<FarmContentViewModel>();

// build view
services.AddSingleton<BuildingListViewModel>();
services.AddSingleton<CurrentBuildingListViewModel>();
Expand Down
174 changes: 170 additions & 4 deletions WPFUI/ViewModels/Tabs/FarmingViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
using MainCore.Tasks.Attack;
using DynamicData;
using DynamicData.Kernel;
using MainCore.Tasks.Attack;
using MainCore.Tasks.Update;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows;
using WPFUI.Models;
using WPFUI.ViewModels.Abstract;

namespace WPFUI.ViewModels.Tabs
{
public class FarmingViewModel : AccountTabBaseViewModel
{
public ReactiveCommand<Unit, Unit> StartCommand { get; }
public ReactiveCommand<Unit, Unit> StopCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
public ReactiveCommand<ListBoxItem, Unit> LoadCommand { get; }
public ReactiveCommand<Unit, Unit> ActiveCommand { get; }
public ReactiveCommand<Unit, Unit> RefreshCommand { get; }

public FarmingViewModel()
{
StartCommand = ReactiveCommand.CreateFromTask(StartTask);
StopCommand = ReactiveCommand.CreateFromTask(StopTask);

SaveCommand = ReactiveCommand.CreateFromTask(SaveData);
LoadCommand = ReactiveCommand.Create<ListBoxItem>(LoadFarm);

ActiveCommand = ReactiveCommand.CreateFromTask(ActiveTask, this.WhenAnyValue(vm => vm.CurrentFarm).Select(x => x is not null));
RefreshCommand = ReactiveCommand.CreateFromTask(RefreshTask);

this.WhenAnyValue(vm => vm.CurrentFarm).BindTo(_selectorViewModel, vm => vm.Farm);
this.WhenAnyValue(vm => vm.CurrentFarm).InvokeCommand(LoadCommand);
_eventManager.FarmListUpdate += OnFarmListUpdate;
}

private async Task StartTask()
Expand Down Expand Up @@ -61,11 +86,152 @@ await Task.Run(() =>
MessageBox.Show("Removed send farm task from queue");
}

protected override void Init(int id)
public async Task SaveData()
{
if (CurrentFarm is null) return;
_waitingWindow.Show("Saving ...");
await Task.Run(() =>
{
using var context = _contextFactory.CreateDbContext();
var settings = context.AccountsSettings.Find(_selectorViewModel.Account.Id);
settings.FarmIntervalMin = Interval - DiffInterval;
if (settings.FarmIntervalMin < 0) settings.FarmIntervalMin = 0;
settings.FarmIntervalMax = Interval + DiffInterval;
context.Update(settings);
context.SaveChanges();
});
_waitingWindow.Close();
MessageBox.Show("Saved");
}

public ReactiveCommand<Unit, Unit> StartCommand { get; }
public ReactiveCommand<Unit, Unit> StopCommand { get; }
public void LoadFarm(ListBoxItem farm)
{
if (farm is null)
{
ContentButton = "=====================";
}
else
{
using var context = _contextFactory.CreateDbContext();
var setting = context.FarmsSettings.Find(farm.Id);
ContentButton = setting.IsActive ? "Deactive" : "Active";
}
}

public async Task ActiveTask()
{
if (CurrentFarm is null) return;
_waitingWindow.Show("Processing ...");
var active = true;
await Task.Run(() =>
{
using var context = _contextFactory.CreateDbContext();
var setting = context.FarmsSettings.Find(CurrentFarm.Id);
setting.IsActive = !setting.IsActive;
active = setting.IsActive;
context.Update(setting);
context.SaveChanges();
});
_waitingWindow.Close();
MessageBox.Show("Done");
CurrentFarm.Color = active ? Color.ForestGreen.ToMediaColor() : Color.Red.ToMediaColor();
ContentButton = active ? "Deactive" : "Active";
}

private Task RefreshTask()
{
var accountId = _selectorViewModel.Account.Id;
var tasks = _taskManager.GetList(accountId).OfType<UpdateFarmList>();
if (!tasks.Any())
{
_taskManager.Add(accountId, new UpdateFarmList(accountId));
}
else
{
var updateFarmList = tasks.First();
updateFarmList.ExecuteAt = DateTime.Now;
_taskManager.Update(accountId);
}
return Task.CompletedTask;
}

private void OnFarmListUpdate(int accountId)
{
if (!IsActive) return;
if (AccountId != accountId) return;

LoadData(accountId);
}

private void LoadData(int id)
{
using var context = _contextFactory.CreateDbContext();
var farms = context.Farms
.Where(x => x.AccountId == id)
.AsList()
.Select(farm =>
{
var farmSetting = context.FarmsSettings.Find(farm.Id);
var color = farmSetting.IsActive ? Color.ForestGreen.ToMediaColor() : Color.Red.ToMediaColor();
return new ListBoxItem(farm.Id, farm.Name, color);
}).ToList();

var settings = context.AccountsSettings.Find(_selectorViewModel.Account.Id);

RxApp.MainThreadScheduler.Schedule(() =>
{
FarmList.Clear();
FarmList.AddRange(farms);
if (farms.Any())
{
CurrentFarm = FarmList[0];
}
else
{
CurrentFarm = null;
}

Interval = (settings.FarmIntervalMax + settings.FarmIntervalMin) / 2;
DiffInterval = (settings.FarmIntervalMax - settings.FarmIntervalMin) / 2;
});
}

protected override void Init(int accountId)
{
LoadData(accountId);
}

private int _interval;

public int Interval
{
get => _interval;
set => this.RaiseAndSetIfChanged(ref _interval, value);
}

private int _diffInterval;

public int DiffInterval
{
get => _diffInterval;
set => this.RaiseAndSetIfChanged(ref _diffInterval, value);
}

private string _contentButton;

public string ContentButton
{
get => _contentButton;
set => this.RaiseAndSetIfChanged(ref _contentButton, value);
}

public ObservableCollection<ListBoxItem> FarmList { get; } = new();
private ListBoxItem _currentFarm;

public ListBoxItem CurrentFarm
{
get => _currentFarm;
set => this.RaiseAndSetIfChanged(ref _currentFarm, value);
}
}
}
Loading

0 comments on commit 96a43a1

Please sign in to comment.