Define 1.0.2
See the version list below for details.
dotnet add package Define --version 1.0.2
NuGet\Install-Package Define -Version 1.0.2
<PackageReference Include="Define" Version="1.0.2" />
paket add Define --version 1.0.2
#r "nuget: Define, 1.0.2"
// Install Define as a Cake Addin #addin nuget:?package=Define&version=1.0.2 // Install Define as a Cake Tool #tool nuget:?package=Define&version=1.0.2
Define
Define is a library used to load discreet data objects, known as defs, from XML documents.
These defs are intended to be used in games and similar projects to define anything from world objects, entities, or weapons to menu buttons or music tracks.
It is primarily intended for game developers who value a clear separation between their game's data and behaviour,
and is ideal for developers who are interested in allowing their players to inspect and even modify the game data (although this is far from a requirement).
Define is heavily inspired by Rimworld's game data system, which is functionally similar to this library.
An example def file might look like this:
<Defs>
<EvilRaiders Type="FactionDef">
<Slogan>Arr! We're really evil!</Slogan>
</EvilRaiders>
<BasicEnemy Type="EnemyDef">
<Hitpoints>100</Hitpoints>
<AttackPower>10</AttackPower>
<Faction>EvilRaiders</Faction>
</BasicEnemy>
<BossEnemy Parent="BasicEnemy">
<Hitpoints>200</Hitpoints>
</BossEnemy>
</Defs>
The corresponding C# types for the above defs are as follows:
class FactionDef : IDef
{
public string ID { get; set; }
public string Slogan = "Default slogan";
}
class EnemyDef : IDef
{
public string ID { get; set; }
public int Hitpoints = 10;
public int AttackPower = 5;
public FactionDef Faction;
}
These defs can be loaded like this:
// A def database is used to load and keep track of defs.
var config = new DefSerializeConfig();
var database = new DefDatabase(config);
string xmlText = File.ReadAllText("MyDefFile.xml");
database.AddDefDocument(xmlText, "MyDefFile.xml");
database.FinishLoading();
// Defs are now loaded and can be accessed.
IReadOnlyList<EnemyDef> allEnemies = database.GetAll<EnemyDef>();
foreach (var enemy in allEnemies)
{
Console.WriteLine($"{enemy.ID}: {enemy.Hitpoints} hp, {enemy.AttackPower} ap");
}
/*
* Prints:
* BasicEnemy: 100 hp, 10 ap
* BossEnemy: 200 hp, 10 ap
*/
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Define:
Package | Downloads |
---|---|
Define.FastCache
Package Description |
|
Define.Monogame
Package Description |
|
Define.Zip
Package Description |
|
Define.KNI
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.