110 lines
3.5 KiB
C#
110 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using FlaxEngine;
|
|
using System.IO;
|
|
|
|
namespace Game
|
|
{
|
|
public class MapBrush
|
|
{
|
|
|
|
}
|
|
|
|
public class MapEntity
|
|
{
|
|
public Dictionary<string, string> properties = new Dictionary<string, string>();
|
|
public List<MapEntity> entities = new List<MapEntity>();
|
|
public List<MapBrush> brushes = new List<MapBrush>();
|
|
}
|
|
|
|
public class Q3MapImporter : Script
|
|
{
|
|
string mapPath = @"C:\dev\Goake\maps\aerowalk\aerowalk.map";
|
|
|
|
public override void OnStart()
|
|
{
|
|
string[] lines = File.ReadAllLines(mapPath);
|
|
|
|
MapEntity rootEntity = new MapEntity();
|
|
MapEntity currentEntity = rootEntity;
|
|
|
|
int level = 0;
|
|
uint lineNumber = 0;
|
|
foreach (string lineRaw in lines)
|
|
{
|
|
lineNumber++;
|
|
string line = lineRaw.TrimStart();
|
|
if (line.StartsWith("//"))
|
|
continue;
|
|
|
|
if (line[0] == '{')
|
|
{
|
|
level++;
|
|
|
|
if (level == 1)
|
|
{
|
|
currentEntity = new MapEntity();
|
|
rootEntity.entities.Add(currentEntity);
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
else if (line[0] == '}')
|
|
{
|
|
level--;
|
|
currentEntity = rootEntity;
|
|
}
|
|
//if (level < 0 || level > 2)
|
|
// throw new Exception("Failed to parse .map file: unexpected entity found at line " + lineNumber.ToString());
|
|
|
|
if (line[0] == '"')
|
|
{
|
|
string[] prop = line.Split('\"');
|
|
if (prop.Length != 5)
|
|
throw new Exception("Failed to parse .map file: failed to parse property at line " + lineNumber.ToString());
|
|
|
|
string propName = prop[1];
|
|
string propValue = prop[3];
|
|
|
|
if (currentEntity.properties.ContainsKey(propName))
|
|
throw new Exception("Failed to parse .map file: multiple properties defined for " + propName + " at line " + lineNumber.ToString());
|
|
currentEntity.properties.Add(propName, propValue);
|
|
}
|
|
else if (line[0] == '(')
|
|
{
|
|
//"( -16 302 431 ) ( -16 302 361 ) ( -16 321 361 ) dev/dev_128_gray 0 0 0 0.0625 0.0625 0 0 0"
|
|
string[] bru = line.Split(new char[] { '(', ')' });
|
|
|
|
// TODO: make geometry out of this, use planes?
|
|
foreach (var b in bru)
|
|
{
|
|
//Console.WriteLine(b);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Here you can add code that needs to be called when script is created, just before the first game update
|
|
}
|
|
|
|
public override void OnEnable()
|
|
{
|
|
// Here you can add code that needs to be called when script is enabled (eg. register for events)
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
// Here you can add code that needs to be called when script is disabled (eg. unregister from events)
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
// Here you can add code that needs to be called every frame
|
|
}
|
|
}
|
|
}
|