|
8 | 8 | using Datamodel; |
9 | 9 | using System.Numerics; |
10 | 10 | using DM = Datamodel.Datamodel; |
11 | | -using System.Text; |
12 | 11 | using System.Globalization; |
13 | | -using ValveResourceFormat.IO.ContentFormats.ValveMap; |
14 | | -using System.ComponentModel.DataAnnotations; |
| 12 | +using VMAP; |
15 | 13 |
|
16 | 14 | namespace Datamodel_Tests |
17 | 15 | { |
@@ -298,40 +296,27 @@ public static void TypedArrayAddingRemoving() |
298 | 296 |
|
299 | 297 |
|
300 | 298 | [Test] |
301 | | - public void Create_Datamodel_Vmap() |
302 | | - { |
303 | | - //using var datamodel = new DM("vmap", 29); |
304 | | - //datamodel.PrefixAttributes.Add("map_asset_references", new List<string>()); |
305 | | - //datamodel.Root = new Element(datamodel, "root", classNameOverride: "CMapRootElement") |
306 | | - //{ |
307 | | - // ["isprefab"] = false, |
308 | | - // ["showgrid"] = true, |
309 | | - // ["snaprotationangle"] = 15, |
310 | | - // ["gridspacing"] = 64, |
311 | | - // ["show3dgrid"] = true, |
312 | | - // ["itemFile"] = true, |
313 | | - // ["world"] = new Element(datamodel, "world", classNameOverride: "CMapWorld"), |
314 | | - //}; |
315 | | - // |
316 | | - //using var stream = new MemoryStream(); |
317 | | - //datamodel.Save(stream, "keyvalues2", 4); |
318 | | - //Assert.That(stream.Length, Is.GreaterThan(0)); |
319 | | - |
320 | | - using var actual = DM.Load(Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "cs2_map.vmap.txt")); |
321 | | - |
322 | | - CMapRootElement root = (CMapRootElement)actual.Root; |
| 299 | + public void LoadVmap_Reflection_Binary() |
| 300 | + { |
| 301 | + var unserialisedVmap = DM.Load(Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "cs2_map.vmap")); |
| 302 | + |
| 303 | + Assert.AreEqual(unserialisedVmap.Root.GetType(), typeof(CMapRootElement)); |
| 304 | + |
| 305 | + CMapRootElement root = (CMapRootElement)unserialisedVmap.Root; |
| 306 | + |
| 307 | + Assert.AreEqual(root.world.GetType(), typeof(CMapWorld)); |
| 308 | + |
323 | 309 | var world = root.world; |
324 | | - var prop = (CMapEntity)world.children[1]; |
325 | | - var propProperties = prop.EntityProperties; |
326 | 310 |
|
| 311 | + var props = world.children.Where(i => i.ClassName == "CMapEntity").OfType<CMapEntity>().ToList(); |
| 312 | + |
| 313 | + var propProperties = props[0].EntityProperties; |
327 | 314 | var classname = propProperties.Get<string>("classname"); |
328 | 315 |
|
329 | | - var meshes = world.children.Where(i => i.ClassName == "CMapMesh"); |
| 316 | + var meshes = world.children.Where(i => i.ClassName == "CMapMesh").OfType<CMapMesh>().ToList(); |
| 317 | + var mesh = meshes[0]; |
330 | 318 |
|
331 | | - //Assert.That(actual.PrefixAttributes.ContainsKey("map_asset_references"), Is.True); |
332 | | - //Assert.That(actual.PrefixAttributes["map_asset_references"], Is.Empty); |
333 | | - Assert.That(actual.Root, Is.Not.Null); |
334 | | - Assert.That(actual.Root["world"], Is.Not.Null); |
| 319 | + Assert.That(unserialisedVmap.PrefixAttributes["map_asset_references"], Is.Not.Empty); |
335 | 320 | } |
336 | 321 |
|
337 | 322 | public class NullOwnerElement |
@@ -417,16 +402,6 @@ public void PropertyAccessByKey() |
417 | 402 | Assert.That(myprop, Is.EqualTo(1337)); |
418 | 403 | } |
419 | 404 |
|
420 | | - [Test] |
421 | | - public void PropertySetByKey_Throws() |
422 | | - { |
423 | | - var elem = new CustomElement(); |
424 | | - |
425 | | - var ex = Assert.Throws(typeof(InvalidOperationException), () => elem["MyProperty"] = 5); |
426 | | - |
427 | | - Assert.That(ex.Message, Does.Contain("Cannot set the value of a property-derived attribute by key")); |
428 | | - } |
429 | | - |
430 | 405 | [Test] |
431 | 406 | public void CanBeAssignedToDatamodelRoot() |
432 | 407 | { |
@@ -600,7 +575,7 @@ public void TF2_KeyValues2_1() |
600 | 575 | [Test, TestCaseSource(nameof(GetDmxFiles))] |
601 | 576 | public void Unserialize(string path) |
602 | 577 | { |
603 | | - var dm = DM.Load(path); |
| 578 | + var dm = DM.Load(path, Datamodel.Codecs.DeferredMode.Automatic); |
604 | 579 | PrintContents(dm); |
605 | 580 | dm.Dispose(); |
606 | 581 | } |
|
0 commit comments