Repository navigation
Expand file tree
/
Copy pathRomanceText.cs
More file actions
114 lines (97 loc) · 2.89 KB
/
Copy pathRomanceText.cs
File metadata and controls
114 lines (97 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using UnityEngine;
using HistoryKit;
using SimpleJSON;
using XRL;
namespace HistoryKit
{
static class acegiak_RomanceText
{
private static bool initialized = false;
private static bool debug = true;
private static StreamWriter debugLogger = null;
public static void Init()
{
if (initialized) return;
if (debug)
{
string logPath = Application.persistentDataPath + "/log_romance.txt";
debugLogger = new StreamWriter(logPath);
if (debugLogger != null)
{
debugLogger.WriteLine("Opened RomanceSpice log...");
debugLogger.Flush();
Logger.gameLog.Info("Opened RomanceSpice log at " + logPath);
}
else Logger.gameLog.Info("Failed to open RomanceSpice log at " + logPath);
}
initialized = true;
}
public static string ExpandString(string input, Dictionary<string, string> vars = null)
{
return ExpandString(input, null, null, vars);
}
public static string ExpandString(string input, HistoricEntitySnapshot entity, Dictionary<string, string> vars = null)
{
return ExpandString(input, entity, null, vars);
}
public static string ExpandQuery(string input, HistoricEntitySnapshot entity, History history, Dictionary<string, string> vars = null)
{
if (!initialized) Init();
string output = HistoricStringExpander.ExpandQuery(input, entity, history, vars, null);
LogQuery(input, output);
return output;
}
public static string ExpandString(string input, HistoricEntitySnapshot entity, History history, Dictionary<string, string> vars = null)
{
if (!initialized) Init();
string output = HistoricStringExpander.ExpandString(input, entity, history, vars);
LogQuery(input, output);
return output;
}
public static void Log(string line)
{
if (debugLogger != null)
debugLogger.WriteLine(line);
}
private static void LogQuery(string input, string output)
{
if (debugLogger != null && input != output)
{
if (input.First() == '<' && input.Last() == '>')
{
// Condense tags.
int first = 1, last = input.Count()-1;
if (input.StartsWith("<spice.eros.")) first += 11;
else if (input.StartsWith("<spice.")) first += 6;
if (input.EndsWith(".!random>")) last -= 8;
input = input.Substring(first, last-first);
debugLogger.Write("~");
debugLogger.Write(input);
}
else
{
debugLogger.Write("[[");
debugLogger.Write(input);
debugLogger.Write("]]");
}
if (output.Count() > 0)
{
debugLogger.WriteLine();
debugLogger.Write('\t');
debugLogger.WriteLine(output);
}
else
{
debugLogger.WriteLine(" <empty>");
}
debugLogger.Flush();
}
}
}
}