Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Nov 30, 2023
2 parents 4fd37a6 + b947066 commit b91b3dd
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Authors>Vladimir Khil</Authors>
<Company>Khil-soft</Company>
<SIGameVersion>7.10.0</SIGameVersion>
<SIQuesterVersion>5.11.0</SIQuesterVersion>
<SIQuesterVersion>5.11.3</SIQuesterVersion>
<SImulatorVersion>2.14.0</SImulatorVersion>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/Common/SIPackages/ContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("placement", _placement);
}
else if (_type == ContentTypes.Audio || _type == AtomTypes.Audio) // For backward compatibility; remove later
{
writer.WriteAttributeString("placement", GetDefaultPlacement());
}

if (_duration != DefaultDuration)
{
Expand Down
5 changes: 4 additions & 1 deletion src/SIQuester/SIQuester.ViewModel/Items/ThemeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ private void AddQuestion_Executed(object? arg)
var questionViewModel = new QuestionViewModel(question);
Questions.Add(questionViewModel);

QDocument.ActivatedObject = questionViewModel.Scenario.FirstOrDefault();
QDocument.ActivatedObject = IsUpgraded
? questionViewModel.Parameters?.FirstOrDefault().Value.ContentValue?.FirstOrDefault()
: questionViewModel.Scenario.FirstOrDefault();

document.Navigate.Execute(questionViewModel);
}
catch (Exception exc)
Expand Down
5 changes: 5 additions & 0 deletions src/SIQuester/SIQuester.ViewModel/Model/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace SIQuester.Model;
/// </summary>
public sealed class AppSettings : INotifyPropertyChanged
{
/// <summary>
/// Manufacturer name.
/// </summary>
public const string ManufacturerName = "Khil-soft";

/// <summary>
/// Application name.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SIQuester.ViewModel.PlatformSpecific;
/// </summary>
public abstract class PlatformManager
{
internal static PlatformManager Instance;
public static PlatformManager Instance;

public IServiceProvider ServiceProvider { get; set; }

Expand Down
18 changes: 18 additions & 0 deletions src/SIQuester/SIQuester.ViewModel/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@
<data name="NumOfThemes" xml:space="preserve">
<value>Theme count</value>
</data>
<data name="ObjectInNewFormat" xml:space="preserve">
<value>Object is created in new format and could not be added to current package</value>
</data>
<data name="ObjectNotFound" xml:space="preserve">
<value>The next object was not found: {0}</value>
</data>
Expand Down Expand Up @@ -438,6 +441,9 @@
<data name="PackageEmptyName" xml:space="preserve">
<value>Empty package</value>
</data>
<data name="PackageInNewFormat" xml:space="preserve">
<value>Package is created in new format and could not be added to current</value>
</data>
<data name="PackageServerFull" xml:space="preserve">
<value>currently, there is no space on the server to accept new packages</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/SIQuester/SIQuester.ViewModel/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,10 @@ theme - тема Кота</value>
<data name="AudioIsNotOnBackground" xml:space="preserve">
<value>Аудио файл {0} не указан как фоновый</value>
</data>
<data name="PackageInNewFormat" xml:space="preserve">
<value>Пакет создан в новом формате и не может быть присоединён к данному</value>
</data>
<data name="ObjectInNewFormat" xml:space="preserve">
<value>Объект создан в новом формате и не может быть присоединён к данному пакету</value>
</data>
</root>
106 changes: 94 additions & 12 deletions src/SIQuester/SIQuester.ViewModel/Workspaces/QDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ internal void ClearLinks(QuestionViewModel question)
{
ClearLinks(atom);
}

foreach (var content in question.Model.GetContent())
{
ClearLinks(content);
}
}

internal void ClearLinks(AtomViewModel atom)
Expand Down Expand Up @@ -1285,7 +1290,7 @@ internal QDocument(
StorageContext = storageContextViewModel;

ImportSiq = new SimpleCommand(ImportSiq_Executed);

Save = new AsyncCommand(Save_Executed);
SaveAs = new AsyncCommand(SaveAs_Executed);
SaveAsTemplate = new AsyncCommand(SaveAsTemplate_Executed);
Expand All @@ -1306,7 +1311,7 @@ internal QDocument(
ConvertToMillionaire = new SimpleCommand(ConvertToMillionaire_Executed);
ConvertToSportSI = new SimpleCommand(ConvertToSportSI_Executed);

Wikify = new SimpleCommand(Wikify_Executed);
Wikify = new SimpleCommand(Wikify_Executed);

Navigate = new SimpleCommand(Navigate_Executed);

Expand Down Expand Up @@ -1413,7 +1418,7 @@ private ICollection<string> FillFiles(MediaStorageViewModel mediaStorage, int ma
{
warnings.Add(new WarningViewModel(string.Format(Resources.FileIsDuplicated, name), () => NavigateToStorageItem(mediaStorage, item)));
}

if (AppSettings.Default.CheckFileSize && mediaStorage.GetLength(item.Model.Name) > maxFileSize * 1024)
{
warnings.Add(new WarningViewModel(string.Format(Resources.MediaFileTooLarge, name, maxFileSize), () => NavigateToStorageItem(mediaStorage, item)));
Expand All @@ -1436,7 +1441,7 @@ internal void NavigateToStorageItem(MediaStorageViewModel mediaStorage, MediaIte
/// Checks missing and unused files in document.
/// </summary>
/// <param name="allowExternal">Allow external files to be used.</param>
internal (IEnumerable<WarningViewModel>,string) CheckLinks(bool allowExternal = false)
internal (IEnumerable<WarningViewModel>, string) CheckLinks(bool allowExternal = false)
{
var warnings = new List<WarningViewModel>();
var errors = new List<string>();
Expand All @@ -1453,7 +1458,7 @@ internal void NavigateToStorageItem(MediaStorageViewModel mediaStorage, MediaIte
foreach (var item in images.Except(usedImages))
{
warnings.Add(
new WarningViewModel(string.Format(Resources.UnusedFile, item),
new WarningViewModel(string.Format(Resources.UnusedFile, item),
() => NavigateToStorageItem(Images, Images.Files.FirstOrDefault(f => f.Model.Name == item))));
}

Expand Down Expand Up @@ -1674,10 +1679,37 @@ internal void Paste_Executed(object? arg)
var itemData = (InfoOwnerData)_clipboardService.GetData(ClipboardKey);
var level = itemData.ItemLevel;

var isUpgraded = Package.IsUpgraded;

if (level == InfoOwnerData.Level.Round)
{
var round = (Round)itemData.GetItem();

if (isUpgraded)
{
foreach (var theme in round.Themes)
{
foreach (var question in theme.Questions)
{
question.Upgrade();
}
}
}
else
{
foreach (var theme in round.Themes)
{
foreach (var question in theme.Questions)
{
if (question.Parameters != null)
{
PlatformManager.Instance.ShowExclamationMessage(Resources.ObjectInNewFormat);
return;
}
}
}
}

if (_activeNode is PackageViewModel myPackage)
{
myPackage.Rounds.Add(new RoundViewModel(round));
Expand All @@ -1698,6 +1730,25 @@ internal void Paste_Executed(object? arg)
{
var theme = (Theme)itemData.GetItem();

if (isUpgraded)
{
foreach (var question in theme.Questions)
{
question.Upgrade();
}
}
else
{
foreach (var question in theme.Questions)
{
if (question.Parameters != null)
{
PlatformManager.Instance.ShowExclamationMessage(Resources.ObjectInNewFormat);
return;
}
}
}

if (_activeNode is RoundViewModel myRound)
{
myRound.Themes.Add(new ThemeViewModel(theme));
Expand All @@ -1720,6 +1771,16 @@ internal void Paste_Executed(object? arg)
{
var question = (Question)itemData.GetItem();

if (isUpgraded)
{
question.Upgrade();
}
else if (question.Parameters != null)
{
PlatformManager.Instance.ShowExclamationMessage(Resources.ObjectInNewFormat);
return;
}

if (_activeNode is ThemeViewModel myTheme)
{
myTheme.Questions.Add(new QuestionViewModel(question));
Expand Down Expand Up @@ -1875,6 +1936,16 @@ private async void ImportSiq_Executed(object? arg)
using var stream = File.OpenRead(file);
using var doc = SIDocument.Load(stream);

if (Package.IsUpgraded)
{
doc.Upgrade();
}
else if (doc.Package.Version >= 5.0)
{
PlatformManager.Instance.ShowExclamationMessage(Resources.PackageInNewFormat);
return;
}

CopyAuthorsAndSources(doc, doc.Package);

foreach (var round in doc.Package.Rounds)
Expand All @@ -1899,14 +1970,17 @@ private async void ImportSiq_Executed(object? arg)
await ImportContentItemAsync(doc, item, contentImportTable);
}

foreach (var atom in question.Scenario)
if (!Package.IsUpgraded)
{
if (atom.Type != AtomTypes.Image && atom.Type != AtomTypes.Audio && atom.Type != AtomTypes.AudioNew && atom.Type != AtomTypes.Video && atom.Type != AtomTypes.Html)
foreach (var atom in question.Scenario)
{
continue;
}
if (atom.Type != AtomTypes.Image && atom.Type != AtomTypes.Audio && atom.Type != AtomTypes.AudioNew && atom.Type != AtomTypes.Video && atom.Type != AtomTypes.Html)
{
continue;
}

await ImportAtomAsync(doc, atom, scenarioImportTable);
await ImportAtomAsync(doc, atom, scenarioImportTable);
}
}
}
}
Expand Down Expand Up @@ -2894,6 +2968,14 @@ private void WikifyAsync()
}
}

foreach (var item in quest.Model.GetContent())
{
if (item.Type == ContentTypes.Text)
{
item.Value = item.Value.Wikify();
}
}

for (int i = 0; i < quest.Right.Count; i++)
{
var value = quest.Right[i];
Expand Down Expand Up @@ -2975,7 +3057,7 @@ private void ConvertToCompTvSI_Executed(object? arg)
allthemes.Add(theme);
}
}

while (Package.Rounds.Count > 0)
{
Package.Rounds.RemoveAt(0);
Expand Down Expand Up @@ -3616,7 +3698,7 @@ internal void RestoreFromFolder(DirectoryInfo folder)
Package.Tags.Merge(package.Tags);

Package.Model.Language = package.Language;
Package.Model.Publisher= package.Publisher;
Package.Model.Publisher = package.Publisher;
Package.Model.Date = package.Date;
Package.Model.Difficulty = package.Difficulty;
Package.Model.Name = package.Name;
Expand Down
Loading

0 comments on commit b91b3dd

Please sign in to comment.