Skip to content

Commit

Permalink
Remove legacy code (old package format editing) from SIQuester
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Mar 10, 2024
1 parent fc570f5 commit bd75e4b
Show file tree
Hide file tree
Showing 37 changed files with 207 additions and 2,624 deletions.
5 changes: 4 additions & 1 deletion src/Common/SI.GameServer.Client/GameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public Task<HostInfo> GetGamesHostInfoAsync(CancellationToken cancellationToken
public Task<string> GetNewsAsync(CancellationToken cancellationToken = default) =>
_connection.InvokeAsync<string>("GetNews", cancellationToken);

public Task<string> GetNewsNewAsync(CancellationToken cancellationToken = default) =>
_connection.InvokeAsync<string>("GetNewsNew", cancellationToken);

public Task<ChatMessage[]> GetLatestChatMessagesAsync(CancellationToken cancellationToken = default) =>
_connection.InvokeAsync<ChatMessage[]>("GetLatestChatMessages", cancellationToken);

Expand All @@ -126,7 +129,7 @@ private async Task AuthenticateUserAsync(
["password"] = password
});

var response = await _client.PostAsync(uri, content, cancellationToken);
using var response = await _client.PostAsync(uri, content, cancellationToken);

if (response.IsSuccessStatusCode)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Common/SI.GameServer.Client/IGameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public interface IGameServerClient : IAsyncDisposable

Task<string> GetNewsAsync(CancellationToken cancellationToken = default);

Task<string> GetNewsNewAsync(CancellationToken cancellationToken = default);

Task<ChatMessage[]> GetLatestChatMessagesAsync(CancellationToken cancellationToken = default);

Task<string[]> GetUsersAsync(CancellationToken cancellationToken = default);

Task<Slice<GameInfo>> GetGamesAsync(int fromId, CancellationToken cancellationToken = default);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/SIPackages/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class Package : InfoOwner, IEquatable<Package>
/// <summary>
/// Default package version.
/// </summary>
public const double DefaultVersion = 4.0;
public const double DefaultVersion = 5.0;

/// <summary>
/// Maximum supported package version.
Expand Down
22 changes: 7 additions & 15 deletions src/Common/SIPackages/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,26 @@ public sealed class Theme : InfoOwner, IEquatable<Theme>
/// </summary>
/// <param name="price">Question price.</param>
/// <param name="isFinal">Does the question belong to the final round.</param>
/// <param name="upgraded">Does the theme belong to an upgraded package.</param>
public Question CreateQuestion(int price = -1, bool isFinal = false, bool upgraded = false)
/// <param name="text">Question text.</param>
public Question CreateQuestion(int price = -1, bool isFinal = false, string text = "")
{
int qPrice = DetectQuestionPrice(price, isFinal);

var quest = new Question
{
Price = qPrice
};

if (upgraded)
{
quest.Parameters = new StepParameters
Price = qPrice,
Parameters = new StepParameters
{
[QuestionParameterNames.Question] = new StepParameter
{
Type = StepParameterTypes.Content,
ContentValue = new List<ContentItem>
{
new() { Type = ContentTypes.Text, Value = "" },
new() { Type = ContentTypes.Text, Value = text },
}
}
};
}
else
{
quest.Scenario.Add(new Atom());
}
}
};

quest.Right.Add("");
Questions.Add(quest);
Expand Down
9 changes: 8 additions & 1 deletion src/SIGame/SIGame.ViewModel/ViewModel/SIOnlineViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,19 @@ public async void Load()
{
try
{
var news = await _gameServerClient.GetNewsAsync(_cancellationTokenSource.Token);
var news = await _gameServerClient.GetNewsNewAsync(_cancellationTokenSource.Token);

if (!string.IsNullOrEmpty(news))
{
OnMessage(Resources.News, news);
}

var latestMesssages = await _gameServerClient.GetLatestChatMessagesAsync(_cancellationTokenSource.Token);

foreach (var item in latestMesssages)
{
OnMessage(item.UserName, item.Text);
}
}
catch (Exception exc)
{
Expand Down
10 changes: 5 additions & 5 deletions src/SIQuester/QTxtConverter/QConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ private static int CountLines(string template)
/// </summary>
/// <param name="list"></param>
/// <param name="templates"></param>
/// <param name="doc"></param>
/// <param name="document"></param>
/// <param name="addToExisting"></param>
public bool ReadFile(SIPart[][] list, SITemplate templates, ref SIDocument document, bool addToExisting, string docName, string authorName, string emptyRoundName, out int themesNum)
{
Expand Down Expand Up @@ -1601,12 +1601,12 @@ public bool ReadFile(SIPart[][] list, SITemplate templates, ref SIDocument docum

#endregion

var quest = document.Package.Rounds[roundIndex].Themes[themeIndex].CreateQuestion(int.Parse(questNumber.ClearPoints().GrowFirstLetter()));
var quest = document.Package.Rounds[roundIndex].Themes[themeIndex].CreateQuestion(
int.Parse(questNumber.ClearPoints().GrowFirstLetter()),
text: questText.ClearPoints().GrowFirstLetter());

questIndex++;

// The whole package is upgraded after completion
quest.Scenario.Clear();
quest.Scenario.Add(questText.ClearPoints().GrowFirstLetter());
quest.Right.Clear();
quest.Right.Add(questAnswer.ClearPoints().GrowFirstLetter());

Expand Down
38 changes: 15 additions & 23 deletions src/SIQuester/SIQuester.ViewModel/AnswersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,33 +236,25 @@ private void ToNewComment_Executed(object? arg)

private void SelectAtomObject_Executed(object? arg)
{
if (Owner.IsUpgraded)
if (Owner.Parameters == null)
{
if (Owner.Parameters == null)
{
return;
}

if (Owner.Parameters.Model.ContainsKey(QuestionParameterNames.Answer))
{
return;
}

var answer = new StepParameterViewModel(Owner, new StepParameter
{
Type = StepParameterTypes.Content,
ContentValue = new List<ContentItem>()
});

if (answer.ContentValue != null && answer.ContentValue.SelectAtomObjectCore(arg))
{
Owner.Parameters.AddAnswer(answer);
}
return;
}

if (Owner.Parameters.Model.ContainsKey(QuestionParameterNames.Answer))
{
return;
}

Owner.Scenario.SelectAtomObject_AsAnswer(arg);
OwnerDocument.ActiveItem = this;
var answer = new StepParameterViewModel(Owner, new StepParameter
{
Type = StepParameterTypes.Content,
ContentValue = new List<ContentItem>()
});

if (answer.ContentValue != null && answer.ContentValue.SelectAtomObjectCore(arg))
{
Owner.Parameters.AddAnswer(answer);
}
}
}
68 changes: 0 additions & 68 deletions src/SIQuester/SIQuester.ViewModel/AtomViewModel.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/SIQuester/SIQuester.ViewModel/Configuration/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,4 @@ public sealed class AppOptions
/// Options configuration section name.
/// </summary>
public static readonly string ConfigurationSectionName = "SIQuester";

/// <summary>
/// Upgrade new packages to new format.
/// </summary>
public bool UpgradeNewPackages { get; set; }

/// <summary>
/// Upgrade opened packages to new format.
/// </summary>
public bool UpgradeOpenedPackages { get; set; }

/// <summary>
/// Is select answer type enabled.
/// </summary>
public bool SelectAnswerTypeEnabled { get; set; }
}
21 changes: 7 additions & 14 deletions src/SIQuester/SIQuester.ViewModel/Helpers/PackageItemsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,23 @@ internal static class PackageItemsHelper
/// Creates a question with provided price.
/// </summary>
/// <param name="price">Question price.</param>
/// <param name="upgraded">Should the question have upgraded format.</param>
internal static Question CreateQuestion(int price, bool upgraded)
internal static Question CreateQuestion(int price)
{
var question = new Question { Price = price };

if (upgraded)
var question = new Question
{
question.Parameters = new StepParameters
Price = price,
Parameters = new StepParameters
{
[QuestionParameterNames.Question] = new StepParameter
{
Type = StepParameterTypes.Content,
ContentValue = new List<ContentItem>
{
new ContentItem { Type = AtomTypes.Text, Value = "" },
new() { Type = ContentTypes.Text, Value = "" },
}
}
};
}
else
{
var atom = new Atom();
question.Scenario.Add(atom);
}
}
};

question.Right.Add("");

Expand Down
5 changes: 0 additions & 5 deletions src/SIQuester/SIQuester.ViewModel/Items/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public sealed class PackageViewModel : ItemViewModel<Package>

public ObservableCollection<RoundViewModel> Rounds { get; } = new();

/// <summary>
/// Does the package have the new format.
/// </summary>
public bool IsUpgraded => Model.Version >= 5.0;

public ICommand AddRound { get; private set; }

public SimpleCommand AddRestrictions { get; private set; }
Expand Down
Loading

0 comments on commit bd75e4b

Please sign in to comment.