-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from TORISOUP/parupunte_name
パルプンテ発動時の字幕内容をconfに切り出した
- Loading branch information
Showing
57 changed files
with
702 additions
and
517 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
55 changes: 55 additions & 0 deletions
55
Inferno/InfernoScripts/Parupunte/ParupunteConfigElement.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,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Inferno.InfernoScripts | ||
{ | ||
internal class ParupunteConfigElement | ||
{ | ||
public string StartMessage { get; set; } | ||
public string SubMessage { get; set; } | ||
public string FinishMessage { get; set; } | ||
|
||
public ParupunteConfigElement(string startMessage, string subMessage, string finishMessage) | ||
{ | ||
StartMessage = startMessage; | ||
SubMessage = subMessage; | ||
FinishMessage = finishMessage; | ||
} | ||
|
||
public ParupunteConfigElement(string startMessage, string finishMessage) | ||
{ | ||
StartMessage = startMessage; | ||
SubMessage = startMessage; | ||
FinishMessage = finishMessage; | ||
} | ||
|
||
public static ParupunteConfigElement Default = new ParupunteConfigElement("", ""); | ||
} | ||
|
||
internal class ParupunteConfigDto | ||
{ | ||
public string ParupunteName { get; set; } | ||
|
||
[DefaultValue("")] | ||
public string StartMessage { get; set; } | ||
|
||
[DefaultValue("")] | ||
public string SubMessage { get; set; } | ||
|
||
[DefaultValue("")] | ||
public string FinishMessage { get; set; } | ||
|
||
public ParupunteConfigDto(string parupunteName, string startMessage, string subMessage, string finishMessage) | ||
{ | ||
ParupunteName = parupunteName; | ||
StartMessage = startMessage; | ||
SubMessage = subMessage; | ||
FinishMessage = finishMessage; | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
Inferno/InfernoScripts/Parupunte/ParupunteConfigRepository.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,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace Inferno.InfernoScripts | ||
{ | ||
/// <summary> | ||
/// ParupunteConfigElementの管理 | ||
/// </summary> | ||
class ParupunteConfigRepository | ||
{ | ||
protected readonly Encoding _encoding = Encoding.UTF8; | ||
protected DebugLogger _debugLogger; | ||
protected string _filePath = @"./scripts/confs/Parupunte.conf"; | ||
|
||
protected virtual DebugLogger DebugLogger | ||
{ | ||
get | ||
{ | ||
if (_debugLogger != null) return _debugLogger; | ||
_debugLogger = new DebugLogger(@"Inferno.log"); | ||
return _debugLogger; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// ファイルから読み込んで設定ファイル返す | ||
/// </summary> | ||
public Dictionary<string, ParupunteConfigElement> LoadSettingFile() | ||
{ | ||
|
||
if (!File.Exists(_filePath)) | ||
{ | ||
return new Dictionary<string, ParupunteConfigElement>(); | ||
} | ||
|
||
var readString = ""; | ||
try | ||
{ | ||
using (var sr = new StreamReader(_filePath, _encoding)) | ||
{ | ||
readString = sr.ReadToEnd(); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
DebugLogger.Log(e.Message); | ||
DebugLogger.Log(e.StackTrace); | ||
return new Dictionary<string, ParupunteConfigElement>(); | ||
} | ||
|
||
try | ||
{ | ||
var dto = JsonConvert.DeserializeObject<ParupunteConfigDto[]>(readString); | ||
return dto.ToDictionary(x => x.ParupunteName, | ||
x => new ParupunteConfigElement(x.StartMessage, x.SubMessage, x.FinishMessage)); | ||
} | ||
catch (Exception e) | ||
{ | ||
DebugLogger.Log(e.Message); | ||
DebugLogger.Log(e.StackTrace); | ||
return new Dictionary<string, ParupunteConfigElement>(); | ||
} | ||
} | ||
|
||
public async Task SaveSettings(Dictionary<string, ParupunteConfigElement> configs) | ||
{ | ||
var directoryPath = Path.GetDirectoryName(_filePath); | ||
//存在しないならディレクトリを作る | ||
if (!Directory.Exists(directoryPath)) | ||
{ | ||
Directory.CreateDirectory(directoryPath); | ||
} | ||
|
||
var dto = configs.Select(x => | ||
{ | ||
var name = x.Key; | ||
var elem = x.Value; | ||
return new ParupunteConfigDto(name, elem.StartMessage, elem.SubMessage, elem.FinishMessage); | ||
}).ToArray(); | ||
|
||
try | ||
{ | ||
using (var w = new StreamWriter(_filePath, false, _encoding)) | ||
{ | ||
var settings = new JsonSerializerSettings | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
var json = JsonConvert.SerializeObject(dto, Formatting.Indented, settings); | ||
await w.WriteAsync(json); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
DebugLogger.Log(e.Message); | ||
DebugLogger.Log(e.StackTrace); | ||
} | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.