Skip to content
This repository was archived by the owner on May 30, 2026. It is now read-only.

Commit 448b1d5

Browse files
committed
refuck
1 parent a363205 commit 448b1d5

3 files changed

Lines changed: 69 additions & 25 deletions

File tree

Overlayer/Core/TextConfigImporter.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,47 @@ public static TextConfig Import(JToken node) {
2929
var targetPath = Path.Combine(fontsDir, @ref.Name);
3030
File.WriteAllBytes(targetPath, @ref.Raw.Decompress());
3131

32+
var relPath = "{ModDir}References/Fonts/" + @ref.Name;
33+
3234
if((Path.GetFileName(config.Font?.Replace("{ModDir}", Main.Mod.Path)) ?? "") == @ref.Name) {
33-
config.Font = targetPath;
35+
config.Font = relPath;
3436
}
3537
}
3638
}
3739
}
3840

3941
return config;
4042
}
43+
public static void ImportRef(TextConfig config, JToken node) {
44+
var refsNode = node["References"] ?? new JArray();
45+
var refs = ModelUtils.UnwrapList<Reference>((JArray)refsNode);
46+
47+
if(!refs.Any()) {
48+
return;
49+
}
50+
51+
var refsDir = Path.Combine(Main.Mod.Path, "References");
52+
var fontsDir = Path.Combine(refsDir, "Fonts");
53+
54+
Directory.CreateDirectory(refsDir);
55+
56+
if(refs.Any(r => r.ReferenceType == Reference.Type.Font)) {
57+
Directory.CreateDirectory(fontsDir);
58+
}
59+
60+
foreach(var @ref in refs) {
61+
if(@ref.ReferenceType == Reference.Type.Font) {
62+
var targetPath = Path.Combine(fontsDir, @ref.Name);
63+
File.WriteAllBytes(targetPath, @ref.Raw.Decompress());
64+
65+
var relPath = "{ModDir}References/Fonts/" + @ref.Name;
66+
67+
if((Path.GetFileName(config.Font?.Replace("{ModDir}", Main.Mod.Path)) ?? "") == @ref.Name) {
68+
config.Font = relPath;
69+
}
70+
}
71+
}
72+
}
4173
public static JArray GetReferences(TextConfig text) {
4274
var references = new List<Reference>();
4375

Overlayer/Views/SettingsDrawer.cs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,32 +267,50 @@ await Task.Run(() => {
267267
return;
268268
}
269269

270-
var content = File.ReadAllText(pf);
270+
string targetPath = Path.Combine(Main.ProfilePath, name + ".json");
271+
272+
if(!string.Equals(
273+
Path.GetFullPath(pf),
274+
Path.GetFullPath(targetPath),
275+
StringComparison.OrdinalIgnoreCase
276+
)) {
277+
File.Copy(pf, targetPath, true);
278+
}
279+
280+
var content = File.ReadAllText(targetPath);
271281
if(string.IsNullOrWhiteSpace(content)) {
272282
return;
273283
}
274284

275285
var token = JToken.Parse(content);
276286
var cfg = new ProfileConfig();
277287
cfg.Deserialize(token);
278-
cfg.Path = pf;
288+
cfg.Path = targetPath;
279289
cfg.Name = name;
280290

281-
Main.MainThreadDispatcher.Enqueue(() => {
282-
try {
283-
var profileGO = new GameObject(cfg.Name ?? "Profile");
284-
var profile = profileGO.AddComponent<OverlayerProfile>();
285-
profile.Config = cfg;
286-
profile.Init(cfg.Name);
287-
288-
profile.TextManager.Import(cfg.Texts);
289-
ProfileManager.Profiles.Add(profile);
290-
dragSoltNeedInit = true;
291-
} catch(Exception ex) {
292-
Debug.LogError($"Failed to create profile '{pf}' on main thread: {ex}");
293-
}
294-
});
295-
} catch(Exception e) {
291+
Main.MainThreadDispatcher.Enqueue(() => {
292+
try {
293+
var profileGO = new GameObject(cfg.Name ?? "Profile");
294+
var profile = profileGO.AddComponent<OverlayerProfile>();
295+
profile.Config = cfg;
296+
profile.Init(cfg.Name);
297+
298+
foreach(var t in cfg.Texts) {
299+
TextConfigImporter.ImportRef(t, token);
300+
}
301+
302+
profile.TextManager.Import(cfg.Texts);
303+
304+
ProfileManager.Profiles.Add(profile);
305+
profile.TextManager.Refresh();
306+
dragSoltNeedInit = true;
307+
308+
} catch(Exception ex) {
309+
Debug.LogError($"Failed to create profile '{pf}' on main thread: {ex}");
310+
}
311+
});
312+
313+
} catch(Exception e) {
296314
Debug.LogError($"Failed to load profile '{pf}': {e}");
297315
}
298316
});

Overlayer/Views/TextConfigDrawer.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public override void Draw() {
135135
changed |= Drawer.DrawCodeEditor(Drawer.Icon_Pause, Main.Lang.Get("NOT_PLAYING_TEXT", "Not Playing Text"), model.Name + "NotPlayingText", ref model.NotPlayingText);
136136
GUILayout.BeginHorizontal();
137137
GUI.color = new Color(1f, 0.8f, 1f);
138-
if(Drawer.Button(Main.Lang.Get("EXPORT", "Export"))) {
138+
if(Drawer.Button(Drawer.Icon_Up)) {
139139
string target = StandaloneFileBrowser.SaveFilePanel(Main.Lang.Get("SELECT_TEXT", "Select Text"), Persistence.GetLastUsedFolder(), $"{model.Name}.json", "json");
140140
if(!string.IsNullOrWhiteSpace(target)) {
141141
JObject node = model.Serialize() as JObject;
@@ -146,12 +146,6 @@ public override void Draw() {
146146
);
147147
}
148148
}
149-
GUI.color = Color.white;
150-
GUI.color = new Color(1f, 1f, 0.8f);
151-
if(Drawer.Button(Main.Lang.Get("RESET", "Reset"))) {
152-
changed = true;
153-
text.Config = model = new TextConfig();
154-
}
155149
GUI.color = new Color(1f, 0.8f, 0.8f);
156150
if(Drawer.Button(Main.Lang.Get("DESTROY", "Destroy"))) {
157151
text.Parant.TextManager.Destroy(text);

0 commit comments

Comments
 (0)