Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Grille committed May 14, 2024
1 parent 1e8e162 commit 6fbd6b5
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Grille.BeamNG.Lib/Collections/KeyedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class KeyedCollection<T> : ICollection<T> where T : class, IKeyed

public KeyedCollection()
{
_dict = new Dictionary<string, T>();
_dict = new();
}

public int Count => _dict.Count;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Text;
using Grille.IO;
using Grille.BeamNG.IO.Binary;

namespace Grille.BeamNG.IO;
namespace Grille.BeamNG.IO.Binary;

public class TerrainV9Serializer
{
Expand Down Expand Up @@ -124,6 +123,6 @@ public static float GetSingleHeight(ushort u16height, float maxHeight)
float height = u16height;
float u16max = ushort.MaxValue;

return (height / u16max) * maxHeight;
return height / u16max * maxHeight;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Grille.BeamNG.Logging;
using System.IO.Compression;

namespace Grille.BeamNG.IO;
namespace Grille.BeamNG.IO.Resources;

public static class ZipFileManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Grille.BeamNG.IO;
namespace Grille.BeamNG.IO.Text;
public class BeamJsonSerializer
{
public static IEnumerable<JsonDict> Load(string filePath)
Expand Down
88 changes: 88 additions & 0 deletions Grille.BeamNG.Lib/IO/Text/JsonDict.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Grille.BeamNG.IO.Text;
public class JsonDict : IDictionary<string, object>
{
SortedList<string, object> _dict;

public JsonDict()
{
_dict = new SortedList<string, object>();
}

public JsonDict(JsonDict dict)
{
_dict = new SortedList<string, object>(dict._dict);
}

public object this[string key] { get => _dict[key]; set => _dict[key] = value; }

public ICollection<string> Keys => _dict.Keys;

public ICollection<object> Values => _dict.Values;

public int Count => _dict.Count;

public bool IsReadOnly => ((ICollection<KeyValuePair<string, object>>)_dict).IsReadOnly;

public void Add(string key, object value)
{
_dict.Add(key, value);
}

public void Add(KeyValuePair<string, object> item)
{
((ICollection<KeyValuePair<string, object>>)_dict).Add(item);
}

public void Clear()
{
_dict.Clear();
}

public bool Contains(KeyValuePair<string, object> item)
{
return _dict.Contains(item);
}

public bool ContainsKey(string key)
{
return _dict.ContainsKey(key);
}

public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
((ICollection<KeyValuePair<string, object>>)_dict).CopyTo(array, arrayIndex);
}

public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return _dict.GetEnumerator();
}

public bool Remove(string key)
{
return _dict.Remove(key);
}

public bool Remove(KeyValuePair<string, object> item)
{
return ((ICollection<KeyValuePair<string, object>>)_dict).Remove(item);
}

public bool TryGetValue(string key, [MaybeNullWhen(false)] out object value)
{
return _dict.TryGetValue(key, out value);
}

IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_dict).GetEnumerator();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace Grille.BeamNG.IO;
namespace Grille.BeamNG.IO.Text;

public class JsonDictSerializer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Grille.BeamNG.SceneTree;
using System.Text;

namespace Grille.BeamNG.IO;
namespace Grille.BeamNG.IO.Text;

public static class SimItemsJsonSerializer
{
Expand Down
5 changes: 1 addition & 4 deletions Grille.BeamNG.Lib/LevelBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.IO.Resources;
using Grille.BeamNG.IO.Resources;
using Grille.BeamNG.SceneTree.Art;
using Grille.BeamNG.SceneTree.Main;
using System.IO;
Expand All @@ -21,8 +20,6 @@ public class LevelBuilder

public Resource? Preview { get; set; }

bool _setup;

public LevelBuilder(string @namespace)
{
Namespace = @namespace;
Expand Down
5 changes: 1 addition & 4 deletions Grille.BeamNG.Lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ Its currently focusing on level data and is generally very WIP.
If you find a piece of code useful but don’t want to include the whole library, feel free to copy paste.
Credits to this project are appreciated but not necessary.


## Links
- [\[GitHub\] https://github.com/Grille/BeamNG_LevelTemplateCreator/tree/main/Grille.BeamNG.Lib](https://github.com/Grille/BeamNG_LevelTemplateCreator/tree/main/Grille.BeamNG.Lib)
- [\[NuGet\] https://www.nuget.org/packages/Grille.BeamNG.Lib](https://www.nuget.org/packages/Grille.BeamNG.Lib)
- [\[BeamNG Forum\] https://www.beamng.com/threads/beamng_leveltemplatecreator-pbr-v0-2.98334/](https://www.beamng.com/threads/beamng_leveltemplatecreator-pbr-v0-2.98334/)

- [\[BeamNG Forum\] https://www.beamng.com/threads/c-grille-beamng-lib-v0-1.98413/](https://www.beamng.com/threads/c-grille-beamng-lib-v0-1.98413/)

## Features

- Read/Write BeamNG terrain binary files (testet againt file version 9 used by 0.32)
- Parsing/Writing of BeamNG scene-tree json


## Disclaimer
This library is an independent project and is not affiliated with, endorsed by, or in any way officially connected to BeamNG GmbH. All trademarks, service marks, product names, and logos appearing in this library are the property of their respective owners.
3 changes: 1 addition & 2 deletions Grille.BeamNG.Lib/SceneTree/Art/ArtItemsCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.SceneTree.Main;
using Grille.BeamNG.SceneTree.Main;
using Grille.BeamNG.SceneTree.Registry;

namespace Grille.BeamNG.SceneTree.Art;
Expand Down
1 change: 0 additions & 1 deletion Grille.BeamNG.Lib/SceneTree/JsonDictWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.Collections;
using Grille.BeamNG.IO;
using Grille.BeamNG.SceneTree.Main;

namespace Grille.BeamNG.SceneTree;
Expand Down
4 changes: 2 additions & 2 deletions Grille.BeamNG.Lib/SceneTree/Main/SimGroup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Grille.BeamNG.Collections;
using Grille.BeamNG.IO;
using Grille.BeamNG.IO;
using Grille.BeamNG.IO.Text;
using Grille.BeamNG.SceneTree.Art;
using Grille.BeamNG.SceneTree.Registry;

Expand Down
3 changes: 1 addition & 2 deletions Grille.BeamNG.Lib/SceneTree/Main/SimItemCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.SceneTree.Registry;
using Grille.BeamNG.SceneTree.Registry;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Grille.BeamNG.Collections;
using Grille.BeamNG.IO.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
3 changes: 1 addition & 2 deletions Grille.BeamNG.Lib/Terrain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.IO.Binary;
using Grille.BeamNG.IO.Binary;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
Expand Down
2 changes: 1 addition & 1 deletion Grille.BeamNG.Lib/TerrainTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.IO.Binary;

namespace Grille.BeamNG;

Expand Down
2 changes: 1 addition & 1 deletion Grille.BeamNG.Lib/usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
global using System.IO;
global using System.Numerics;

global using JsonDict = System.Collections.Generic.Dictionary<string, object>;
global using Grille.BeamNG.IO.Text;
2 changes: 0 additions & 2 deletions Grille.BeamNG.Lib_Tests/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Grille.BeamNG.IO;
using Grille.BeamNG;
using System.IO.Enumeration;

Expand Down
12 changes: 2 additions & 10 deletions LevelTemplateCreator/Assets/AssetLibaryLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using LevelTemplateCreator.IO.Resources;
using LevelTemplateCreator.IO.Resources;
using LevelTemplateCreator.Properties;
using Grille.BeamNG.SceneTree;
using Grille.BeamNG.SceneTree.Art;
Expand All @@ -8,6 +7,7 @@
using System.Text;
using System.Xml.Linq;
using Grille.BeamNG.Logging;
using Grille.BeamNG.IO.Resources;

namespace LevelTemplateCreator.Assets;

Expand All @@ -26,7 +26,6 @@ public override string ToString()
const string JsonConstant = "Constant";
const string JsonInclude = "Include";


public int MaxWrongFileCount { get; set; } = 20;
int _wrongFileCount = 0;
bool _exit = false;
Expand Down Expand Up @@ -148,13 +147,6 @@ void LoadJsonFile(string path)
Deserialize(stream);
}

void Deserialize(string text)
{
var bytes = Encoding.UTF8.GetBytes(text);
using var stream = new MemoryStream(bytes);
Deserialize(stream);
}

void Deserialize(Stream stream)
{
var dict = JsonDictSerializer.Deserialize(stream);
Expand Down
4 changes: 0 additions & 4 deletions LevelTemplateCreator/Assets/LevelObjectsAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public LevelObjectsAsset(JsonDictWrapper data, AssetSource info) : base(data, in
foreach (var rawitem in rawitems)
{
var item = new SimItem(rawitem, (string)rawitem["class"]);
foreach (var pair in rawitem)
{
item[pair.Key] = pair.Value;
}
Items.Add(item);
}
}
Expand Down
3 changes: 1 addition & 2 deletions LevelTemplateCreator/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grille.BeamNG.IO;
using Grille.BeamNG.IO.Resources;
using Grille.BeamNG.IO.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion LevelTemplateCreator/usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
global using System.Windows.Forms;
global using System.Drawing;

global using JsonDict = System.Collections.Generic.Dictionary<string, object>;
global using Grille.BeamNG.IO.Text;
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Setting up a new scenario from scratch can be a bit tiresome, especially if you
The goal of this project is to provide an easy solution to create empty map templates.
I also aimed to make it easily extendable for people with deeper knowledge of BeamNG.

## Links
- [\[GitHub\] https://github.com/Grille/BeamNG_LevelTemplateCreator](https://github.com/Grille/BeamNG_LevelTemplateCreator)
- [\[NuGet\] https://www.nuget.org/packages/Grille.BeamNG.Lib](https://www.nuget.org/packages/Grille.BeamNG.Lib)
- [\[BeamNG Forum\] https://www.beamng.com/threads/beamng_leveltemplatecreator-pbr-v0-2.98334/](https://www.beamng.com/threads/beamng_leveltemplatecreator-pbr-v0-2.98334/)

## Features
* Setup of needed level folder structure without manual renaming.
* Asset System based on BeamNG's Json structure.
Expand Down Expand Up @@ -47,15 +52,18 @@ Object material, indirectly added if used by any other object.

### Paths

* `.`
Relative path from the folder containing the Json file.

* `/`
Absolute path either from the local package folder, or alternatively if beginning with `/level` and contains an valid BeamNG-level name e.g `/levels/driver_training/` an pointer to an BeamNG resource.

* `.`
Relative path from the folder containing the Json file.

* `#`
Hex color code `#ffffff` used to generate a single-color texture file on export.

* `$`
Variable

Each part must start with one of the above characters.

## Requirements
Expand Down

0 comments on commit 6fbd6b5

Please sign in to comment.