ace/Source/ACE.Database/SQLFormatters/World/LandblockInstanceWriter.cs
Mag-nus 004d7d4f19 LandblockInstance refactored. DYNAMIC SUPPORT REMOVED
Columns id and guid have been combined into a single guid column.

This requires that every landblock instance be provided with a valid unique guid.

In the old code, you could provide an instance that would have an auto generated id (column) and a guid of 0. ACE would then see the guid is 0 and would use the following:
GuidManager.NewDynamicGuid();

In the cache.bin, every landblock instance has a unique id.

If we need to add the ability to have dynamically guid'd landblockinstances, this is an easy thing to add back.
2018-08-05 07:30:14 -05:00

95 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ACE.Database.Models.World;
namespace ACE.Database.SQLFormatters.World
{
public class LandblockInstanceWriter : SQLWriter
{
/// <summary>
/// Set this to enable auto commenting when creating SQL statements.<para />
/// If a child link is found in the dictionary, the name will be added in the form of a /* Friendly Instance Name */
/// </summary>
public Dictionary<uint, string> InstanceNames;
/// <summary>
/// Default is formed from: (input.ObjCellId >> 16).ToString("X4")
/// </summary>
public string GetDefaultFileName(LandblockInstance input)
{
string fileName = (input.ObjCellId >> 16).ToString("X4");
fileName = IllegalInFileName.Replace(fileName, "_");
fileName += ".sql";
return fileName;
}
public void CreateSQLDELETEStatement(IList<LandblockInstance> input, StreamWriter writer)
{
throw new NotImplementedException();
}
/// <exception cref="System.Exception">WeenieClassNames must be set, and must have a record for input.ClassId.</exception>
public void CreateSQLINSERTStatement(IList<LandblockInstance> input, StreamWriter writer)
{
input = input.OrderBy(r => r.Guid).ToList();
foreach (var value in input)
{
if (value != input[0])
writer.WriteLine();
writer.WriteLine("INSERT INTO `landblock_instance` (`guid`, `weenie_Class_Id`, `obj_Cell_Id`, `origin_X`, `origin_Y`, `origin_Z`, `angles_W`, `angles_X`, `angles_Y`, `angles_Z`, `is_Link_Child`)");
string label = null;
if (WeenieNames != null)
WeenieNames.TryGetValue(value.WeenieClassId, out label);
var output = "VALUES (" +
$"{value.Guid.ToString().PadLeft(10)}, " +
$"{value.WeenieClassId.ToString().PadLeft(5)}, " +
$"{value.ObjCellId}, " +
$"{value.OriginX}, " +
$"{value.OriginY}, " +
$"{value.OriginZ}, " +
$"{value.AnglesW}, " +
$"{value.AnglesX}, " +
$"{value.AnglesY}, " +
$"{value.AnglesZ}, " +
$"{value.IsLinkChild.ToString().PadLeft(5)}" +
$"); /* {label} */";
output = FixNullFields(output);
writer.WriteLine(output);
if (value.LandblockInstanceLink != null && value.LandblockInstanceLink.Count > 0)
{
writer.WriteLine();
CreateSQLINSERTStatement(value.LandblockInstanceLink.OrderBy(r => r.ChildGuid).ToList(), writer);
}
}
}
private void CreateSQLINSERTStatement(IList<LandblockInstanceLink> input, StreamWriter writer)
{
writer.WriteLine("INSERT INTO `landblock_instance_link` (`parent_GUID`, `child_GUID`)");
var lineGenerator = new Func<int, string>(i =>
{
string label = null;
if (InstanceNames != null)
InstanceNames.TryGetValue(input[i].ChildGuid, out label);
return $"{input[i].ParentGuid.ToString().PadLeft(10)}, {input[i].ChildGuid.ToString().PadLeft(10)}) /* {label} */";
});
ValuesWriter(input.Count, lineGenerator, writer);
}
}
}