Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sargeantPig committed Jun 10, 2024
1 parent 7c3fd07 commit 421dbb3
Show file tree
Hide file tree
Showing 27 changed files with 25,239 additions and 120 deletions.
117 changes: 101 additions & 16 deletions RTWLibPlus/dataWrappers/baseWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
using RTWLibPlus.parsers.objects;
using System;
using System.Collections.Generic;
using System.Formats.Asn1;
using System.IO;
using System.Linq;

public abstract class BaseWrapper
{
private string outputPath;

public string OutputPath
{
get
{
string path = ExString.CrossPlatPath(this.outputPath);
string dir = Path.GetDirectoryName(path);
if (Directory.Exists(dir))
{ return path; }
public string OutputPath { get; set; }
// {
// get
// {
// string path = ExString.CrossPlatPath(this.outputPath);
// string dir = Path.GetDirectoryName(path);
// if (Directory.Exists(dir))
// { return path; }

return path.Split('/').Last();
}
// return path.Split('/').Last();
// }

set => this.outputPath = value;
}
// set => this.outputPath = value;
// }
public string LoadPath { get; set; }

public List<IBaseObj> Data { get; set; } = new();
public List<IBaseObj> Data { get; set; } = [];
/// <summary>
/// Location is a collection of strings that represent the tags. Once the final string is found it will return the corresponding kv
/// </summary>
Expand Down Expand Up @@ -105,6 +105,91 @@ public void DeleteChunks(string stopAt, string ident)
}
}
}

public Dictionary<int, List<IBaseObj>> GetChunks(string stopAt, string ident)
{
Dictionary<int, List<IBaseObj>> chunks = [];
int ready = 0;
bool identFound = false;
int startI = -1;
int count = 0;
for (int i = 0; i < this.Data.Count; i++)
{
IBaseObj item = this.Data[i];
if (identFound && ready == 2)
{
chunks.Add(i, this.Data.GetRange(startI, count));
count = 0;
identFound = false;
ready = 0;
i -= 2;
}

if (stopAt == item.Ident && ready == 1)
{
ready += 1;
}

if (ready == 1)
{
count++;
}

if (ident == item.Ident && ready == 0)
{
identFound = true;
ready += 1;
startI = i;
count++;
}

}

return chunks;
}

public Dictionary<int, int> GetChunkIndexes(string stopAt, string ident)
{
Dictionary<int, int> chunks = [];
int ready = 0;
bool identFound = false;
int startI = -1;
int count = 0;
for (int i = 0; i < this.Data.Count; i++)
{
IBaseObj item = this.Data[i];
if (identFound && ready == 2)
{
chunks.Add(startI, count);
count = 0;
identFound = false;
ready = 0;
i -= 2;
}

if (stopAt == item.Ident && ready == 1)
{
ready += 1;
}

if (ready == 1)
{
count++;
}

if (ident == item.Ident && ready == 0)
{
identFound = true;
ready += 1;
startI = i;
count++;
}

}

return chunks;
}

public bool AddObjToList(List<IBaseObj> items, IBaseObj obj, int locInd = 0, bool done = false, params string[] location)
{
foreach (BaseObj item in items)
Expand Down Expand Up @@ -167,10 +252,10 @@ public List<IBaseObj> GetItemsByIdent(string ident)
found.Push(item);
}
});*/


return found;
}


public List<IBaseObj> GetItemsByCriteria(string stopAt, string lookFor, params string[] criteriaTags)
{
bool[] criteria = new bool[criteriaTags.Length];
Expand Down
138 changes: 138 additions & 0 deletions RTWLibPlus/dataWrappers/dmb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
namespace RTWLibPlus.dataWrappers;
using RTWLibPlus.data;
using RTWLibPlus.helpers;
using RTWLibPlus.interfaces;
using RTWLibPlus.parsers.objects;
using System;
using System.Collections.Generic;
using System.IO;

public class DMB : BaseWrapper, IWrapper
{
private readonly string name = "dmb";

public string GetName() => this.name;
public DMB(string outputPath, string loadPath)
{
this.OutputPath = outputPath;
this.LoadPath = loadPath;
}

public DMB(List<IBaseObj> data, TWConfig config)
{
this.Data = data;
this.LoadPath = config.GetPath(Operation.Load, "dmb");
this.OutputPath = config.GetPath(Operation.Save, "dmb");
Console.WriteLine(this.OutputPath);
}

public void Parse() => this.Data = RFH.ParseFile(Creator.DMBcreator, ' ', false, this.LoadPath);

public string Output()
{
string output = string.Empty;

for (int i = 0; i < this.Data.Count; i++)
{
DMBObj obj = (DMBObj)this.Data[i];
DMBObj next = new();
if (i + 1 < this.Data.Count)
{
next = (DMBObj)this.Data[i + 1];
}
if (next.Ident == "type")
{
output += obj.Output() + Format.UniversalNewLine();
}
else
{
output += obj.Output();
}
}

// if (Directory.Exists(this.OutputPath))
// {
// RFH.Write(this.OutputPath, output + Format.UniversalNewLine());
// }

return output + Format.UniversalNewLine();
}

public void AddFallBacksForAllTypes()
{
Dictionary<int, int> chunks = this.GetChunkIndexes("type", "type");
int modifier = 0;
int errors = 0;
foreach (KeyValuePair<int, int> pair in chunks)
{
bool hasDefault = false;
IBaseObj insertion = null;
IBaseObj type = this.Data[pair.Key + modifier];
for (int i = pair.Key + modifier; i < pair.Key + pair.Value + modifier; i++)
{
string line = this.Data[i].Output();
if (!line.StartsWith(';') && line.Contains("texture ") && line.Contains("Default "))
{
hasDefault = true;
}

if (!line.StartsWith(';') && (line.Contains("texture ") || line.Contains("texture\t")) && !line.Contains("pbr_"))
{
insertion = this.Data[i];
}

if (hasDefault)
{
break;
}
}

if (!hasDefault && insertion != null)
{
insertion = ChangeFaction(insertion);

if (insertion != null)
{
this.Data.Insert(pair.Key + pair.Value + modifier, insertion);
modifier += 1;
}

continue;
}

else if (insertion == null)
{
errors += 1;
string str = this.Data[pair.Key + modifier].Value;
Console.WriteLine("Error no texture for: " + str + "\n");
}

else
{
string str = this.Data[pair.Key + modifier].Value;
Console.WriteLine("Error no texture for: " + str + "\n");
}
}

}

private static IBaseObj ChangeFaction(IBaseObj obj)
{

IBaseObj copy = obj.Copy();
string[] split = copy.Value.Split(",");

if (split.Length == 1)
{
return null;
}

split[0] = "Default";
string val = split.ToString(',');
copy.Value = val;

return copy;
}

public void Clear() => this.Data.Clear();
}
8 changes: 6 additions & 2 deletions RTWLibPlus/dataWrappers/ds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using RTWLibPlus.parsers.objects;
using System;
using System.Collections.Generic;
using System.Numerics;

public class DS : BaseWrapper, IWrapper
{
Expand Down Expand Up @@ -82,6 +81,7 @@ public void AddUnitToArmy(IBaseObj faction, IBaseObj character, IBaseObj unit)
}



public string GetFactionByRegion(string region)
{
string s = this.GetTagByContentsValue(this.Data, "faction", region);
Expand All @@ -94,5 +94,9 @@ public string GetFactionByRegion(string region)
return s.Split('\t')[1].Trim(',');
}


public static string GetUnitName(IBaseObj unit)
{
string name = string.Format("{0} {1}", unit.Tag.Split('\t', StringSplitOptions.RemoveEmptyEntries)[1], unit.Value.GetFirstWord('\t'));
return name;
}
}
6 changes: 6 additions & 0 deletions RTWLibPlus/dataWrappers/edu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public EDU(List<IBaseObj> data, TWConfig config)
{
this.Data = data;
this.SetEndOfUnits();
//this.PrepareEDU();
this.LoadPath = config.GetPath(Operation.Load, "edu");
this.OutputPath = config.GetPath(Operation.Save, "edu");
}
Expand Down Expand Up @@ -80,6 +81,11 @@ public List<string> GetUnitsFromFaction(string faction)
IBaseObj obj = ownerships[i];
IBaseObj unit = type[i];

if (unit.Value.Contains("roman general"))
{
int b = 0;

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-linux

The variable 'b' is assigned but its value is never used

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-linux

The variable 'b' is assigned but its value is never used

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-windows

The variable 'b' is assigned but its value is never used

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-windows

The variable 'b' is assigned but its value is never used

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-macos

The variable 'b' is assigned but its value is never used

Check warning on line 86 in RTWLibPlus/dataWrappers/edu.cs

View workflow job for this annotation

GitHub Actions / build-macos

The variable 'b' is assigned but its value is never used
}

if (obj.Value.Contains(faction))
{
units.Add(unit.Value);
Expand Down
2 changes: 1 addition & 1 deletion RTWLibPlus/helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class RFH
{
public static void Write(string path, string content)
{
StreamWriter sw = new(path);
StreamWriter sw = new(@path);
sw.Write(content);
sw.Flush();
sw.Close();
Expand Down
Loading

0 comments on commit 421dbb3

Please sign in to comment.