-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
515 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// --------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. | ||
// See LICENSE file in the project root for license information. | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
namespace Core.DataReader.Txt | ||
{ | ||
using System; | ||
|
||
public struct Task | ||
{ | ||
public string TaskId; | ||
public string TaskTitle; | ||
public string TaskInfo; | ||
public string TaskType; | ||
public string IsLastOne; | ||
|
||
public bool IsMainTask => string.Equals(TaskType, "0", StringComparison.Ordinal); | ||
} | ||
|
||
public sealed class TaskDefinitionFile | ||
{ | ||
public Task[] Tasks { get; } | ||
|
||
public TaskDefinitionFile(Task[] tasks) | ||
{ | ||
Tasks = tasks; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Scripts/Core/DataReader/Txt/TaskDefinitionFile.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
Assets/Scripts/Core/DataReader/Txt/TaskDefinitionFileReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// --------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. | ||
// See LICENSE file in the project root for license information. | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
namespace Core.DataReader.Txt | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
public sealed class TaskDefinitionFileReader : IFileReader<TaskDefinitionFile> | ||
{ | ||
private readonly int _codepage; | ||
|
||
public TaskDefinitionFileReader(int codepage) | ||
{ | ||
_codepage = codepage; | ||
} | ||
|
||
public TaskDefinitionFile Read(IBinaryReader reader) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public TaskDefinitionFile Read(byte[] data) | ||
{ | ||
var content = Encoding.GetEncoding(_codepage).GetString(data, 0, data.Length); | ||
var tasks = new List<Task>(); | ||
var taskLines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); | ||
var currentTask = new Task(); | ||
|
||
foreach (var taskLine in taskLines) | ||
{ | ||
if (taskLine.TrimStart().StartsWith(";")) continue; | ||
|
||
var splitLine = taskLine.Split('$'); | ||
var tag = splitLine[0].Trim(); | ||
var value = splitLine.Length > 1 ? splitLine[1].Trim().Trim('$', '&') : string.Empty; | ||
|
||
switch (tag) | ||
{ | ||
case "tname": | ||
currentTask.TaskId = value; | ||
break; | ||
case "title": | ||
currentTask.TaskTitle = value; | ||
break; | ||
case "info": | ||
currentTask.TaskInfo = value; | ||
break; | ||
case "type": | ||
currentTask.TaskType = value; | ||
break; | ||
case "last": | ||
currentTask.IsLastOne = value; | ||
break; | ||
case "#": | ||
tasks.Add(currentTask); | ||
currentTask = new Task(); // reset task for next one | ||
break; | ||
} | ||
} | ||
|
||
return new TaskDefinitionFile(tasks.ToArray()); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Scripts/Core/DataReader/Txt/TaskDefinitionFileReader.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.