Skip to content

Commit

Permalink
Fixed QTask Id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jones-HM committed Mar 14, 2023
1 parent 021fa0b commit 5aec387
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 67 deletions.
31 changes: 12 additions & 19 deletions IGIEditor/IGIEditorUI.Designer.cs

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

2 changes: 1 addition & 1 deletion IGIEditor/IGIEditorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public IGIEditorUI()
{
QUtils.ResetScriptFile(gameLevel);
}
clearTempToolStripMenuItem_Click(null, null);
QUtils.CleanUpTmpFiles();

if (appLogs)
{
Expand Down
99 changes: 52 additions & 47 deletions QTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,85 +71,90 @@ internal static int GetUniqueQTaskId(int taskId)

internal static int GenerateTaskID(bool minimalId = false, bool fromBackup = false)
{
int taskId = 0;
try
{
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "called minimal Id : " + minimalId + " fromBackup: " + fromBackup + " Level: " + QUtils.gGameLevel);
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "Method called with parameters: minimalId=" + minimalId + ", fromBackup=" + fromBackup + ", Level=" + QUtils.gGameLevel);

string inputQscPath = cfgQscPath + QUtils.gGameLevel + "\\" + objectsQsc;
string qscData = fromBackup ? LoadFile(inputQscPath) : LoadFile();
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "inputQscPath: " + inputQscPath);

string qscData = fromBackup ? LoadFile(inputQscPath) : LoadFile();
qscData = qscData.Replace("\t", String.Empty);
string[] qscDataSplit = qscData.Split('\n');

List<int> qIdsList = new List<int>();
foreach (var data in qscDataSplit)
{
if (data.Contains(taskNew))
{
var startIndex = data.IndexOf(',', 14) + 1;
var taskName = (data.Slice(13, startIndex));

string[] taskNew = data.Split(',');
int taskIndex = 0;

foreach (var task in taskNew)
{
if (taskIndex == (int)QTASKINFO.QTASK_ID)
{
var taskIdx = task.IndexOf('(');
if (taskIdx == -1) break;
var qidSub = task.Substring(taskIdx + 1);
int qid = Convert.ToInt32(qidSub);
if (qid == -1) break;
if (qid > QUtils.LEVEL_FLOW_TASK_ID)
qIdsList.Add(qid);
break;
}
}
int qid = GetTaskIdFromData(taskNew);

if (qid > QUtils.LEVEL_FLOW_TASK_ID)
qIdsList.Add(qid);
}
}

qIdsList.Sort();
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "sorting done. count: " + qIdsList.Count);
int taskId = GetNextTaskId(qIdsList, minimalId);

taskId = qIdsList[0] + 1;
int maxVal = qIdsList[0], minVal = qIdsList[1];
taskId = GetUniqueQTaskId(taskId);
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "Unique task ID generated. Task ID: " + taskId);

return taskId;
}
catch (Exception ex)
{
QUtils.ShowLogException(MethodBase.GetCurrentMethod().Name, ex);
return 0;
}
}

if (minimalId)
private static int GetTaskIdFromData(string[] taskNew)
{
int qid = -1;
foreach (var task in taskNew)
{
int taskIndex = Array.IndexOf(taskNew, task);
if (taskIndex == (int)QTASKINFO.QTASK_ID)
{
int diffVal = 0;
for (int index = 0; index < qIdsList.Count; index++)
var taskIdx = task.IndexOf('(');
if (taskIdx != -1 && int.TryParse(task.Substring(taskIdx + 1), out qid) && qid != -1)
{
minVal = qIdsList[index];
maxVal = qIdsList[index + 1];
diffVal = Math.Abs(maxVal - minVal);
//QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "maxVal : " + maxVal + "\tminVal : " + minVal + "\tdiffVal : " + diffVal);

if (diffVal >= QUtils.MAX_MINIMAL_ID_DIFF)
{
taskId = minVal + 1;
break;
}
break;
}
}
else
}
return qid;
}

private static int GetNextTaskId(List<int> qIdsList, bool minimalId)
{
if (minimalId)
{
for (int index = 0; index < qIdsList.Count - 1; index++)
{
qIdsList.Reverse();
maxVal = qIdsList[0];
taskId = maxVal + 1;
int minVal = qIdsList[index];
int maxVal = qIdsList[index + 1];
int diffVal = Math.Abs(maxVal - minVal);

if (diffVal >= QUtils.MAX_MINIMAL_ID_DIFF)
{
return minVal + 1;
}
}
taskId = GetUniqueQTaskId(taskId);
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "Returned Task Id: " + taskId);
}
catch (Exception ex)
else
{
QUtils.ShowLogException(MethodBase.GetCurrentMethod().Name, ex);
return qIdsList[qIdsList.Count - 1] + 1;
}
return taskId;

return qIdsList[0] + 1;
}




internal static QScriptTask GetQTask(string taskName)
{
AddLog(MethodBase.GetCurrentMethod().Name, " taskName called");
Expand Down

0 comments on commit 5aec387

Please sign in to comment.