MonoChestnut.Data
0.22.0
dotnet add package MonoChestnut.Data --version 0.22.0
NuGet\Install-Package MonoChestnut.Data -Version 0.22.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MonoChestnut.Data" Version="0.22.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MonoChestnut.Data" Version="0.22.0" />
<PackageReference Include="MonoChestnut.Data" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MonoChestnut.Data --version 0.22.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MonoChestnut.Data, 0.22.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MonoChestnut.Data@0.22.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MonoChestnut.Data&version=0.22.0
#tool nuget:?package=MonoChestnut.Data&version=0.22.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MonoChestnut.Data
MonoChestnut 游戏引擎的游戏配置模型。引擎读取它运行游戏,设计器 MonoChestnut Studio 用它编辑游戏。不依赖 MonoGame。
- 数据类:
GameConfig→ScreenConfig(屏幕、跳转和屏幕的菜单)→Elements(组成屏幕的ScreenElement:Logo、标题、关卡、视频……,每种屏幕由哪些 Element 组成见ScreenTypes)→ScreenEntityConfig(玩家、道具、敌人、移动平台、检查点……); 菜单在GameConfig.Menus中(MenuConfig:标题和按钮,按钮的操作和去处写在按钮上),屏幕按名称引用。 - JSON 读写:枚举写成名称,颜色写成
#RRGGBB,多态的 Element 和实体用Type区分(可以写在对象中的任意位置)。 读写代码编译时生成(System.Text.Json 源生成),不用反射,可以裁剪和 AOT 编译。 - 游戏名:
GameConfig.Title是显示给玩家的名称,GameConfig.Name是英文标识(如NunuRun,用于安卓包名com.clawit.monochestnut.NunuRun,打包安卓 App 时必须填写),格式检查见ConfigValidator.IsValidGameName。 - 校验:一次列出所有问题,每个问题带有出错位置。
- 格式版本:
GameConfig.FormatVersion,只读取当前版本的配置,其他版本明确报错(引擎还没有发布,不保留旧格式的迁移)。 - 关卡和跳转:关卡的
Genre(GenreConfig:平台跳跃PlatformerGenreConfig、竖版射击ShooterGenreConfig、俯视角 RPGRpgGenreConfig、 塔防TowerDefenseGenreConfig) 写游戏类型和这个类型特有的参数。屏幕的Transitions(TransitionConfig)写条件、条件的参数和目标; 目标是关卡时Arrive写玩家出现在目标关卡的哪个检查点(多张地图用检查点当出入口、来回走)。 关卡的Persistent为 true 时记住它的状态:离开后再回来,拾取过的道具、击败的敌人不再出现;RespawnEnemies为 true 时打倒的敌人会重新出现,只记住道具。 - NPC 和对话:实体
NpcEntityConfig(Type: "Npc")有名字Name、台词Lines(每句一页)和走动的路径Path, 玩家面对它按确认键时在对话框里显示台词(目前只有俯视角 RPG 的关卡支持)。GameConfig.Dialogue(DialogueConfig) 设置对话框每秒显示的字数和行数。道具(ItemEntityConfig)的Interact为 true 时要面对它按确认键才生效(宝箱),Lines是生效时显示的文字。 - 塔防:敌人库
GameConfig.Enemies(EnemyTypeConfig)和塔库GameConfig.Towers(TowerConfig,各等级TowerLevelConfig)按名称定义, 关卡的TowerDefenseGenreConfig写可以建的塔和波次(WaveConfig→WaveGroupConfig);实体SpawnerEntityConfig(Type: "Spawner",出怪口和路线) 和TowerSlotEntityConfig(Type: "TowerSlot",塔位)只有塔防关卡支持。 - 精灵:精灵库在
GameConfig.Sprites中定义(SpriteConfig:横向排列帧序列的图片、帧数、帧时长、是否循环), 实体各状态的动画(AnimationConfig)按名称引用精灵,再加上这个状态的碰撞尺寸。 - 地图(
MonoChestnut.Data.Maps):图块集在GameConfig.Tilesets中定义;每张关卡地图是一个.map.json文件(TileMap), 由渲染实体的Map引用。图层分背景 / 场景 / 前景,格子的值见MapTile(图块集序号、图块编号和翻转), 文件中按 zlib 压缩后的 Base64 文本保存。地形碰撞来自实心图层(相邻格子合并成矩形,见MapTerrain)和手画的矩形。 图层的Parallax(地图格式 2)让远景跟着相机移动得慢、近景快,相机在地图左下角时各层对齐。MapReader读写,MapValidator校验。
using MonoChestnut.Data;
using MonoChestnut.Data.Maps;
// 打开配置(不校验,还没写完的配置也能打开)
var config = ConfigReader.Deserialize(File.ReadAllText("game.json"));
// 列出问题:Path 是与 JSON 属性一致的路径,如 "Screens[3].Elements[0].Entities[2].Path.Points"
foreach (var issue in ConfigValidator.Validate(config))
Console.WriteLine($"{issue.Path}: {issue.Message}");
// 保存
ConfigWriter.WriteConfig(config, "game.json");
// 读取并校验,有问题时抛出 ConfigException(Issues 列出所有问题)
var valid = ConfigReader.Parse(File.ReadAllText("game.json"));
// 地图:读取(不校验)、列出问题、保存
var map = MapReader.Deserialize(File.ReadAllText("Content/Map/beach.map.json"));
var mapIssues = MapValidator.Validate(map, config.Tilesets);
MapReader.Write(map, "Content/Map/beach.map.json");
许可证:GPL-3.0-only。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.22.0 | 116 | 11/17/2026 |
| 0.20.0 | 117 | 11/17/2026 |
| 0.18.0 | 116 | 11/16/2026 |
| 0.17.0 | 118 | 11/14/2026 |
| 0.16.0 | 115 | 11/14/2026 |
| 0.15.0 | 114 | 11/14/2026 |
| 0.14.0 | 125 | 11/14/2026 |
| 0.13.0 | 113 | 11/13/2026 |
| 0.12.0 | 114 | 11/13/2026 |
| 0.11.0 | 130 | 11/13/2026 |
| 0.10.0 | 114 | 11/13/2026 |
| 0.9.0 | 92 | 11/12/2026 |
| 0.8.0 | 92 | 11/8/2026 |
| 0.7.0 | 91 | 11/8/2026 |
| 0.6.0 | 93 | 11/3/2026 |
| 0.5.0 | 93 | 11/3/2026 |
| 0.4.0 | 111 | 11/3/2026 |
| 0.3.0 | 96 | 11/2/2026 |
| 0.2.0 | 109 | 11/1/2026 |
| 0.1.0 | 110 | 10/30/2026 |