Skip to content

Commit

Permalink
Возможность заменять подстроки в Batch конвертере, релоад текущей мод…
Browse files Browse the repository at this point in the history
…ели если ее изменил батч
  • Loading branch information
VaIeroK committed Mar 2, 2023
1 parent 5d320e3 commit 9d85f50
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 44 deletions.
6 changes: 5 additions & 1 deletion OGF tool/Forms/Batch/AddDeleteData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public partial class AddDeleteData : Form
private string folder;
private Batch.BatchChunks Chunk;
private bool delete;
public AddDeleteData(Batch.BatchChunks chunk, string ogf_folder_path, bool delete)
private Editor Editor;
public AddDeleteData(Editor editor, Batch.BatchChunks chunk, string ogf_folder_path, bool delete)
{
InitializeComponent();
folder = ogf_folder_path;
Chunk = chunk;
this.delete = delete;
Editor = editor;

if (Chunk == Batch.BatchChunks.Lod)
DataTextBox.Multiline = false;
Expand Down Expand Up @@ -61,6 +63,8 @@ private void StartButton_Click(object sender, EventArgs e)
{
Model.SaveFile(files[i]);
FilesCount++;
if (Model.FileName == Editor.Model.FileName)
Editor.ReloadModel();
}
}
}
Expand Down
116 changes: 90 additions & 26 deletions OGF tool/Forms/Batch/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,54 @@ static private bool SafeCheckLineExist(string[] arr, string chk_line)
return false;
}

static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string replacer, string new_val, ref uint lines_counter)
static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string replacer, string new_val, bool substring, ref uint lines_counter)
{
bool ret = false;
switch (chunk)
{
case BatchChunks.Texture:
foreach (var ch in Model.childs)
{
if (ch.m_texture == replacer)
if (substring)
{
ch.m_texture = new_val;
ret = true;
lines_counter++;
if (ch.m_texture.Contains(replacer))
{
ch.m_texture = ch.m_texture.Replace(replacer, new_val);
ret = true;
lines_counter++;
}
}
else
{
if (ch.m_texture == replacer)
{
ch.m_texture = new_val;
ret = true;
lines_counter++;
}
}
}
break;
case BatchChunks.Shader:
foreach (var ch in Model.childs)
{
if (ch.m_shader == replacer)
if (substring)
{
ch.m_shader = new_val;
ret = true;
lines_counter++;
if (ch.m_shader.Contains(replacer))
{
ch.m_shader = ch.m_shader.Replace(replacer, new_val);
ret = true;
lines_counter++;
}
}
else
{
if (ch.m_shader == replacer)
{
ch.m_shader = new_val;
ret = true;
lines_counter++;
}
}
}
break;
Expand All @@ -80,14 +104,28 @@ static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string re
string userdata = "";
foreach (string line in Lines)
{
if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer))
if (substring)
{
userdata += new_val + "\r\n";
ret = true;
lines_counter++;
if (line.Contains(replacer))
{
userdata += line.Replace(replacer, new_val) + "\r\n";
ret = true;
lines_counter++;
}
else
userdata += RemoveNewLines(line) + "\r\n";
}
else
userdata += RemoveNewLines(line) + "\r\n";
{
if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer))
{
userdata += new_val + "\r\n";
ret = true;
lines_counter++;
}
else
userdata += RemoveNewLines(line) + "\r\n";
}
}
if (ret)
Model.userdata.userdata = userdata.TrimEnd(new char[] { '\r', '\n' });
Expand All @@ -100,23 +138,49 @@ static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string re
Model.motion_refs.refs.Clear();
foreach (string line in Lines)
{
if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer))
if (substring)
{
Model.motion_refs.refs.Add(new_val);
ret = true;
lines_counter++;
if (line.Contains(replacer))
{
Model.motion_refs.refs.Add(line.Replace(replacer, new_val));
ret = true;
lines_counter++;
}
else
Model.motion_refs.refs.Add(line);
}
else
Model.motion_refs.refs.Add(line);
{
if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer))
{
Model.motion_refs.refs.Add(new_val);
ret = true;
lines_counter++;
}
else
Model.motion_refs.refs.Add(line);
}
}
}
break;
case BatchChunks.Lod:
if (Model.lod != null && RemoveSpacesAndNewLines(Model.lod.lod_path) == RemoveSpacesAndNewLines(replacer))
if (substring)
{
Model.lod.lod_path = new_val;
ret = true;
lines_counter++;
if (Model.lod != null && Model.lod.lod_path.Contains(replacer))
{
Model.lod.lod_path = Model.lod.lod_path.Replace(replacer, new_val);
ret = true;
lines_counter++;
}
}
else
{
if (Model.lod != null && RemoveSpacesAndNewLines(Model.lod.lod_path) == RemoveSpacesAndNewLines(replacer))
{
Model.lod.lod_path = new_val;
ret = true;
lines_counter++;
}
}
break;
}
Expand Down Expand Up @@ -275,7 +339,7 @@ private void ProcessReplacer(BatchChunks chunk)
{
if (Directory.Exists(PathTextBox.Text))
{
ReplaceData textBoxReplacer = new ReplaceData(chunk, PathTextBox.Text);
ReplaceData textBoxReplacer = new ReplaceData(Editor, chunk, PathTextBox.Text);
textBoxReplacer.Show();
}
else
Expand All @@ -286,7 +350,7 @@ private void ProcessAdd(BatchChunks chunk)
{
if (Directory.Exists(PathTextBox.Text))
{
AddDeleteData textBoxReplacer = new AddDeleteData(chunk, PathTextBox.Text, false);
AddDeleteData textBoxReplacer = new AddDeleteData(Editor, chunk, PathTextBox.Text, false);
textBoxReplacer.Show();
}
else
Expand All @@ -297,7 +361,7 @@ private void ProcessDelete(BatchChunks chunk)
{
if (Directory.Exists(PathTextBox.Text))
{
AddDeleteData textBoxReplacer = new AddDeleteData(chunk, PathTextBox.Text, true);
AddDeleteData textBoxReplacer = new AddDeleteData(Editor, chunk, PathTextBox.Text, true);
textBoxReplacer.Show();
}
else
Expand Down
19 changes: 16 additions & 3 deletions OGF tool/Forms/Batch/ReplaceData.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions OGF tool/Forms/Batch/ReplaceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public partial class ReplaceData : Form
{
private string folder;
private Batch.BatchChunks Chunk;
public ReplaceData(Batch.BatchChunks chunk, string ogf_folder_path)
private Editor Editor;
public ReplaceData(Editor editor, Batch.BatchChunks chunk, string ogf_folder_path)
{
InitializeComponent();
folder = ogf_folder_path;
Chunk = chunk;
Text = "Replace " + Batch.Capitalize(chunk.ToString());
Editor = editor;

BoxTextChanged(NewTextBox, null);
}
Expand All @@ -38,10 +40,12 @@ private void StartButton_Click(object sender, EventArgs e)
XRay_Model Model = new XRay_Model();
if (Model.OpenFile(files[i]))
{
if (Batch.ProcessReplace(Model, Chunk, ReplacerTextBox.Text, NewTextBox.Text, ref LinesCount))
if (Batch.ProcessReplace(Model, Chunk, ReplacerTextBox.Text, NewTextBox.Text, ReplaceSubstrings.Checked, ref LinesCount))
{
Model.SaveFile(files[i]);
FilesCount++;
if (Model.FileName == Editor.Model.FileName)
Editor.ReloadModel();
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions OGF tool/Forms/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ public Editor()

if (Environment.GetCommandLineArgs().Length > 1)
{
if (Model.OpenFile(Environment.GetCommandLineArgs()[1]))
{
Clear();
Clear();
if (Model.OpenFile(Environment.GetCommandLineArgs()[1]))
AfterLoad(true);
}
}
else
{
Expand Down Expand Up @@ -989,16 +987,19 @@ private void CreateLodButton_Click(object sender, EventArgs e)

private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Model.FileName == "") return;
ReloadModel();
}

string cur_fname = Model.FileName;
if (Model.OpenFile(cur_fname))
{
public void ReloadModel()
{
if (Model.FileName == "") return;

if (Model.OpenFile(Model.FileName))
{
Clear();
Model.FileName = cur_fname;
AfterLoad(true);
}
}
AfterLoad(true);
}
}

private void TabControl_SelectedIndexChanged(object sender, EventArgs e)
{
Expand Down

0 comments on commit 9d85f50

Please sign in to comment.