模型(回退 Flutter 内嵌 → Avalonia):
- 恢复 model/_sdk、5 个模型 src/、GC-DRAW/PlayerWindow、ModelHost/AvaloniaHost(源自 5b62897)
- FlutterShell 主线程承载 Avalonia 事件循环,根治 1.1.1 的 AppKit 崩溃
- /api/models/{id}/launch 由后端开独立 Avalonia 窗口
- 前端删除 Flutter 模型实现与 ModelViewPage 死代码(13 个文件)
积分:
- Points/ThemePaid int → decimal,精确到 0.01;pw.yaml 兼容旧整数格式
- 主题色退款保留 2 位小数;前端新增 formatPoints 显示
人品值/二选一计费(原前端本地免费随机 → 后端计费):
- 新增 POST /api/user/fortune、/api/user/pick,随机数与扣费都在服务端
- 人品值阶梯:当日免费 1 次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起
- 二选一:当日免费 1 次 → 0.5/次;计数按 UTC 日期持久化,跨天清零
- 前端两个功能需登录,扣费后提示本次消耗
附 RELEASE-1.1.2.md 更新日志。
97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using Avalonia;
|
||
using Avalonia.Controls;
|
||
using Avalonia.Layout;
|
||
using Avalonia.Media;
|
||
using GC.ModelSdk;
|
||
|
||
namespace GC.ContourMap;
|
||
|
||
/// <summary>等高线模型入口(清单里的 type 指向这里)。</summary>
|
||
public sealed class ContourMapFactory : IModelFactory
|
||
{
|
||
public int ApiVersion => 1;
|
||
public IModelRuntime Create() => new ContourMapRuntime();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 等高线模型运行时。
|
||
/// 依据人教版七年级上册「地形图的判读」:海拔与相对高度、等高线与等高距、
|
||
/// 山峰/山脊/山谷/鞍部/陡崖的判读、坡度陡缓与等高线疏密的关系。
|
||
/// </summary>
|
||
public sealed class ContourMapRuntime : IModelRuntime
|
||
{
|
||
private TerrainField? _field;
|
||
private Dictionary<string, string>? _texts;
|
||
private ContourPage? _page;
|
||
|
||
public void Prepare(IModelContext context)
|
||
{
|
||
context.ReportProgress(0.15, "生成地形高度场");
|
||
_field = new TerrainField(TerrainKind.Mountain, 192);
|
||
|
||
context.ReportProgress(0.70, "提取等高线");
|
||
_texts = LoadTexts(context.DataDirectory, context.Language);
|
||
|
||
context.ReportProgress(0.92, "准备界面");
|
||
context.Log($"[contour-map] 地形 {_field.Size}×{_field.Size}," +
|
||
$"海拔 {_field.MinHeight:0}~{_field.MaxHeight:0} m,等高距 {_field.EffectiveInterval:0} m");
|
||
}
|
||
|
||
public Control CreateView(IModelContext context)
|
||
{
|
||
_texts ??= LoadTexts(context.DataDirectory, context.Language);
|
||
// 实验地形 + 五大地貌都在界面里现场生成(切换很快,不必预先生成全部)
|
||
_page = new ContourPage(_texts);
|
||
return _page.Build();
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
_page?.Dispose();
|
||
_page = null;
|
||
_field = null;
|
||
_texts = null;
|
||
System.GC.SuppressFinalize(this);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 文案 = 内置默认(保证任何语言都有词)+ dataDir/i18n/<lang>.json 覆盖。
|
||
/// 语言包缺失或某条没翻译时自动退回内置默认,不会露出裸 key。
|
||
/// </summary>
|
||
private static Dictionary<string, string> LoadTexts(string dataDir, string language)
|
||
{
|
||
var isEn = language.StartsWith("en", StringComparison.OrdinalIgnoreCase);
|
||
var map = new Dictionary<string, string>(DefaultTexts.Zh);
|
||
if (isEn) foreach (var kv in DefaultTexts.En) map[kv.Key] = kv.Value;
|
||
|
||
var candidates = new List<string>();
|
||
if (!string.IsNullOrWhiteSpace(language)) candidates.Add(language);
|
||
candidates.Add(isEn ? "en" : "zh-CN");
|
||
|
||
foreach (var lang in candidates)
|
||
{
|
||
var path = System.IO.Path.Combine(dataDir, "i18n", lang + ".json");
|
||
if (!System.IO.File.Exists(path)) continue;
|
||
try
|
||
{
|
||
using var doc = System.Text.Json.JsonDocument.Parse(System.IO.File.ReadAllText(path));
|
||
if (doc.RootElement.ValueKind != System.Text.Json.JsonValueKind.Object) continue;
|
||
foreach (var p in doc.RootElement.EnumerateObject())
|
||
{
|
||
if (p.Value.ValueKind != System.Text.Json.JsonValueKind.String) continue;
|
||
var v = p.Value.GetString();
|
||
if (!string.IsNullOrWhiteSpace(v)) map[p.Name] = v!;
|
||
}
|
||
break;
|
||
}
|
||
catch
|
||
{
|
||
// 语言包损坏不影响开课,继续用内置默认
|
||
}
|
||
}
|
||
return map;
|
||
}
|
||
}
|