Skip to content

Commit e08f13d

Browse files
authored
feat: hot reload for Google Sheets (#26)
1 parent b156827 commit e08f13d

22 files changed

+423
-27
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
targetPlatform: ${{ matrix.targetPlatform }}
9999
versioning: Custom
100100
version: ${{ needs.release.outputs.version }}
101+
buildMethod: Editor.BuildScript.Build
101102
- name: Create zip archive
102103
run: |
103104
cd build/${{ matrix.targetPlatform }}

.github/workflows/verify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
unityVersion: 2022.3.6f1
5151
targetPlatform: ${{ matrix.targetPlatform }}
5252
versioning: Tag
53+
buildMethod: Editor.BuildScript.Build
5354
- uses: actions/upload-artifact@v3
5455
with:
5556
name: Build

Assets/DevTools.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/DevTools/CSV.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/Typewriter/CsvConverter.cs renamed to Assets/DevTools/CSV/CsvConverter.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using UnityEngine;
1111
using Object = UnityEngine.Object;
1212

13-
namespace Editor.Typewriter {
13+
namespace DevTools.CSV {
1414
public static class CsvConverter {
1515
private enum ScriptState {
1616
Initial,
@@ -69,7 +69,7 @@ Object context
6969
}
7070

7171
// _collection =
72-
// LocalizationEditorSettings.GetStringTableCollection("Dialogue");
72+
// LocalizationEditorSettings.GetStringTableCollection("Dialogue");
7373

7474
_lookup.Add("LT", InteractionContext.LT);
7575
_lookup.Add("RT", InteractionContext.RT);
@@ -84,7 +84,7 @@ Object context
8484
BaseEntry previous = null;
8585
for (var i = 1; i < rows.Count; i++) {
8686
var cells = rows[i].Cells;
87-
if (cells.Key() == "") {
87+
if (cells.IsEmpty()) {
8888
continue;
8989
}
9090

@@ -106,7 +106,10 @@ Object context
106106
type = typeof(FactEntry);
107107
break;
108108
default:
109-
Debug.LogError($"Row {i + 1}: Unknown type {cells.Type()}", context);
109+
Debug.LogError(
110+
$"Row {i + 1} ({cells.Key()}): Unknown type {cells.Type()}",
111+
context
112+
);
110113
continue;
111114
}
112115

@@ -138,7 +141,7 @@ Object context
138141

139142
for (var i = 1; i < rows.Count; i++) {
140143
var cells = rows[i].Cells;
141-
if (cells.Key() == "") {
144+
if (cells.IsEmpty()) {
142145
previous = null;
143146
continue;
144147
}
@@ -160,7 +163,7 @@ Object context
160163
break;
161164
}
162165
} catch (Exception e) {
163-
Debug.LogError($"Row {i + 1}: {e.Message}", context);
166+
Debug.LogError($"Row {i + 1} ({cells.Key()}): {e.Message}", context);
164167
Debug.LogException(e);
165168
}
166169
}
@@ -434,13 +437,21 @@ private static IEnumerable<ScriptResult> ParseScript(string text) {
434437
text += '\n';
435438
}
436439

440+
var isComment = false;
437441
var context = new ParsingContext {
438442
Code = text,
439443
Line = 0,
440444
Column = 0,
441445
};
442446

443447
foreach (var c in text) {
448+
if (isComment) {
449+
if (c == '\n') {
450+
isComment = false;
451+
}
452+
continue;
453+
}
454+
444455
switch (c) {
445456
case '\r':
446457
case ' ':
@@ -467,6 +478,9 @@ private static IEnumerable<ScriptResult> ParseScript(string text) {
467478
throw new ParsingException("Unexpected '.'", context);
468479
}
469480

481+
break;
482+
case '#' when state == ScriptState.Initial:
483+
isComment = true;
470484
break;
471485
case '\n':
472486
switch (state) {
@@ -531,21 +545,31 @@ private static IEnumerable<EntryReference> ParseReferences(string text) {
531545
text += '\n';
532546
}
533547

548+
var isComment = false;
534549
var builder = new StringBuilder();
535550
foreach (var c in text) {
536551
switch (c) {
537552
case ' ':
538553
case '\r':
539554
continue;
555+
case '#' when builder.Length == 0:
556+
isComment = true;
557+
break;
540558
case ',':
541559
case '\n':
560+
if (isComment) {
561+
isComment = false;
562+
builder.Clear();
563+
break;
564+
}
565+
542566
var value = builder.ToString();
543567
builder.Clear();
544568
if (value.Length > 0) {
545569
if (_lookup.TryGetValue(value, out var entry)) {
546570
yield return entry;
547571
} else {
548-
Debug.LogWarningFormat("Missing reference {0}", value);
572+
throw new Exception($"Unknown entry reference: {value}.");
549573
}
550574
}
551575
break;
@@ -575,6 +599,9 @@ private static string GetErrorFrame(ParsingContext context) {
575599
return builder.ToString();
576600
}
577601

602+
private static bool IsEmpty(this List<string> list) =>
603+
string.IsNullOrEmpty(list[0]) || list[0].StartsWith('#');
604+
578605
private static string Key(this List<string> list) => list[0];
579606
private static string Type(this List<string> list) => list[2];
580607
private static string Speaker(this List<string> list) => list[3];
File renamed without changes.

Assets/Editor/Typewriter/CsvParser.cs renamed to Assets/DevTools/CSV/CsvParser.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace Editor.Typewriter {
5+
namespace DevTools.CSV {
66
public static class CsvParser {
77
[Serializable]
88
public struct Row {
@@ -27,7 +27,10 @@ public static IReadOnlyList<Row> Parse(string text) {
2727
continue;
2828
case '"': {
2929
isInsideField = !isInsideField;
30-
if (!isInsideField && i + 1 < text.Length && text[i + 1] != ',') {
30+
if (!isInsideField
31+
&& i + 1 < text.Length
32+
&& text[i + 1] != ','
33+
&& text[i + 1] != '\n') {
3134
_builder.Append('"');
3235
}
3336
break;
@@ -37,7 +40,9 @@ public static IReadOnlyList<Row> Parse(string text) {
3740
break;
3841
case '\n' when !isInsideField:
3942
AddCell(cells);
40-
_rows.Add(new Row { Cells = cells });
43+
if (cells.Count > 0) {
44+
_rows.Add(new Row { Cells = cells });
45+
}
4146
cells = new List<string>();
4247
break;
4348
default:
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using UnityEngine;
2+
3+
namespace DevTools {
4+
public partial class GoogleSheetLoader : MonoBehaviour { }
5+
}

Assets/DevTools/GoogleSheetLoader.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)