Skip to content

Commit

Permalink
Merge pull request #9 from hkviz/v1_6
Browse files Browse the repository at this point in the history
v1.6.0.0
  • Loading branch information
OliverGrack authored Jan 31, 2025
2 parents 8a7c79d + bf1a87c commit 2177aab
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 50 deletions.
47 changes: 47 additions & 0 deletions HKVizMod/CharmsExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Modding;
using Satchel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace HKViz {
internal class CharmsExport : Loggable {
class CharmInfo {
public string charmId;

Check warning on line 14 in HKVizMod/CharmsExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'charmId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string spriteName;

Check warning on line 15 in HKVizMod/CharmsExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'spriteName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
}


private static CharmsExport? _instance;
public static CharmsExport Instance {
get {
if (_instance != null) return _instance;
_instance = new CharmsExport();
return _instance;
}
}


public void Export() {
var go = GameObject.FindObjectOfType<CharmVibrations>().transform.Find("Collected Charms");
var sprites = go.GetComponentsInChildren<SpriteRenderer>();
Log("sprites length" + sprites.Length);

var infos = sprites.Where(it => it.gameObject.name == "Sprite").Select(it => new CharmInfo {
charmId = it.transform.parent.gameObject.name,
spriteName = it.sprite.name,
}).ToList();

Debug.Log("infos" + infos.Count);

var json = Json.Stringify(infos);
using (var writer = new StreamWriter(StoragePaths.GetUserFilePath("charms-inventory-export.txt"))) {
writer.Write(json);
}
}
}
}
6 changes: 6 additions & 0 deletions HKVizMod/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ internal static class Constants {
public static string WEBSITE_DISPLAY_LINK = "hkviz.org";
public static string WEBSITE_LINK = "https://www.hkviz.org";

// ----- PRODUCTION -----
public static string API_URL = "https://www.hkviz.org/api/rest/";
public static string LOGIN_URL = "https://www.hkviz.org/ingameauth/";
public static string API_URL_SUFFIX = "";

// ----- LOCAL -----
//public static string API_URL = "http://localhost:3000/api/rest/";
//public static string LOGIN_URL = "http://localhost:3000/ingameauth/";
//public static string API_URL_SUFFIX = "";

public static string RECORDER_FILE_VERSION = "1.6.0";

public static string GetVersion() => typeof(Constants).Assembly.GetName().Version.ToString();
}
Expand Down
58 changes: 58 additions & 0 deletions HKVizMod/EnemiesExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Modding;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace HKViz {
internal class EnemiesExport : Loggable {
class EnemyJournalInfo {
public string portraitName;

Check warning on line 13 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'portraitName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 13 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'portraitName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string convoName;

Check warning on line 14 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'convoName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 14 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'convoName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string descConvo;

Check warning on line 15 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'descConvo' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string nameConvo;

Check warning on line 16 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'nameConvo' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string notesConvo;

Check warning on line 17 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'notesConvo' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string playerDataBoolName;

Check warning on line 18 in HKVizMod/EnemiesExport.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'playerDataBoolName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string playerDataKillsName;
public string playerDataName;
public string playerDataNewDataName;
}


private static EnemiesExport? _instance;
public static EnemiesExport Instance {
get {
if (_instance != null) return _instance;
_instance = new EnemiesExport();
return _instance;
}
}


public void Export() {
var journalList = GameObject.FindObjectOfType<JournalList>();
var listItems = journalList.transform.GetComponentsInChildren<JournalEntryStats>(true);

var enemies = listItems.Select(e => new EnemyJournalInfo {
portraitName = e.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite.name,
convoName = e.convoName,
descConvo = e.descConvo,
nameConvo = e.nameConvo,
notesConvo = e.notesConvo,
playerDataBoolName = e.playerDataBoolName,
playerDataKillsName = e.playerDataKillsName,
playerDataName = e.playerDataName,
playerDataNewDataName = e.playerDataNewDataName,
}).ToList();


var json = Json.Stringify(enemies);
using (var writer = new StreamWriter(StoragePaths.GetUserFilePath("enemies-journal-export.txt"))) {
writer.Write(json);
}
}
}
}
2 changes: 1 addition & 1 deletion HKVizMod/HKVizAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void GlobalSettingsLoaded() {
}

private void Application_focusChanged(bool focused) {
Log("Focus changed");
// Log("Focus changed");
if (focused && State == LoginState.WAITING_FOR_USER_LOGIN_IN_BROWSER) {
CheckSessionState(fromSettings: false);
}
Expand Down
6 changes: 5 additions & 1 deletion HKVizMod/HKVizMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ private void InitFsmIfNotAlreadyHappened() {
recording.WriteEntry(RecordingPrefixes.SPELL_UP);
});

// ----- HEALING / FOCUSING -----
PlayerHealthWriter.Instance.InitFsm();

// ----- NAIL ARTS -----
// cyclone
Hooks.HookStateEntered(new FSMData(
Expand Down Expand Up @@ -259,6 +262,7 @@ private void InitFsmIfNotAlreadyHappened() {
private void HeroUpdateHook() {
var unixMillis = recording.GetUnixMillis();

KnightManager.Instance.UpdateKnight();
ModWriter.Instance.OnKnightUpdate();
GameManagerWriter.Instance.WriteChangedFields(unixMillis);
PlayerPositionWriter.Instance.WritePositionsIfNeeded(unixMillis);
Expand Down Expand Up @@ -318,7 +322,7 @@ public MenuScreen GetMenuScreen(MenuScreen modListMenu, ModToggleDelegates? togg
=> HKVizModUI.Instance.GetMenuScreen(modListMenu, toggleDelegates);

public void OnLoadGlobal(GlobalSettings s) {
Log("Steam-user" + GameLauncherUser.Instance.GetUserId());
//Log("Steam-user" + GameLauncherUser.Instance.GetUserId());
GlobalSettingsManager.Instance.InitializeFromSavedSettings(s);
HKVizAuthManager.Instance.GlobalSettingsLoaded();
UploadManager.Instance.GlobalSettingsLoaded();
Expand Down
2 changes: 1 addition & 1 deletion HKVizMod/HKVizMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Copyright>Copyright © Oliver Grack 2024</Copyright>
<Authors>Oliver Grack</Authors>
<NoWarn>7035</NoWarn>
<AssemblyVersion>1.5.1</AssemblyVersion>
<AssemblyVersion>1.6.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<OutputPath>bin\$(Configuration)\</OutputPath>
<LangVersion>latest</LangVersion>
Expand Down
33 changes: 33 additions & 0 deletions HKVizMod/KnightManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;

namespace HKViz {
internal class KnightManager {
private static KnightManager instance;
public static KnightManager Instance {
get {
if (instance == null) {
instance = new KnightManager();
}
return instance;
}
}


private Transform? knight;

public Transform? Knight => knight;

public void UpdateKnight() {
if (knight == null) {
// if destroyed needs to find new player
knight = GameObject.Find("Knight").transform;
if (knight != null) {
//OnNewKnightFound?.Invoke(knight);
PlayerHealthWriter.Instance.InitNewKnight(knight);
}
}
}

//public event Action<Transform>? OnNewKnightFound;
}
}
59 changes: 52 additions & 7 deletions HKVizMod/MapExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Modding;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;

Expand All @@ -18,7 +19,18 @@ public static MapExport Instance {
}
}


private string getObjectPath(GameObject go, GameObject relativeToParent) {
var builder = new StringBuilder();
var current = go;
while (current != null && current != relativeToParent) {
if (go != current) {
builder.Insert(0, "/");
}
builder.Insert(0, current.name);
current = current.transform.parent.gameObject;
}
return builder.ToString();
}
public MapData Export() {
Log("Started map export. This should run at the beginning of the game, after buying the first map, but before buying the quill");

Expand All @@ -29,9 +41,40 @@ public MapData Export() {
var gameMapGO = GameObject.Find("Game_Map(Clone)");
var gameMapPos = gameMapGO.transform.position;

TextData textDataFromObjects(SetTextMeshProGameText it) {
var current = it.gameObject;
while (current != null) {
current.SetActive(true);
current = current.transform.parent?.gameObject;
}
var tmp = it.GetComponent<TMPro.TextMeshPro>();
tmp.ForceMeshUpdate(true);
return new TextData(
objectPath: getObjectPath(it.gameObject, gameMapGO),
convoName: it.convName,
sheetName: it.sheetName,
position: it.transform.position - gameMapPos,
fontSize: tmp.fontSize,
fontWeight: tmp.fontWeight,
bounds: new ExportBounds(
min: it.transform.TransformPoint(tmp.textBounds.min) - gameMapPos,
max: it.transform.TransformPoint(tmp.textBounds.max) - gameMapPos
),
origColor: tmp.color
);
}

var areaNames = gameMapGO.GetComponentsInChildren<AreaName>(true)
.Select(areaName => textDataFromObjects(areaName.GetComponent<SetTextMeshProGameText>()))
.ToList();

foreach (var m in gameMapGO.GetComponentsInChildren<RoomSprite>(true)) {
var rsd = m.Rsd;
var roomSpriteDefinition = m.Rsd;

var textDatas = m.gameObject.GetComponentsInChildren<SetTextMeshProGameText>(true)
//.Where(it => it.gameObject.name.Contains("Area Name"))
.Select(it => textDataFromObjects(it))
.ToList();


//Log(m.Rsd?.MapZone);
Expand All @@ -43,8 +86,8 @@ public MapData Export() {
//Log(spriteRenderer.bounds);
//Log(spriteRenderer.sprite.texture.GetPixels32());

var mapZone = rsd.MapZone.ToString();
var sceneName = rsd.SceneName;
var mapZone = roomSpriteDefinition.MapZone.ToString();
var sceneName = roomSpriteDefinition.SceneName;
var gameObjectName = m.name;
var roughMapRoom = m.GetComponent<RoughMapRoom>();

Expand Down Expand Up @@ -97,12 +140,14 @@ public MapData Export() {
// spriteRough = roughSpriteInfo != null ? $"IMPORT_STRING_START:{roughSpriteInfo.name?.ToLower()}:IMPORT_STRING_END" : null,
sprite = $"{spriteInfo.name}",
spriteRough = roughSpriteInfo != null ? $"{roughSpriteInfo.name}" : null,
texts = textDatas
});
}

var mapData = new MapData() {
rooms = rooms,
};
var mapData = new MapData(
rooms: rooms,
areaNames: areaNames
);
var json = Json.Stringify(mapData);
//var js = json
// .Replace("\"IMPORT_STRING_START:", "")
Expand Down
34 changes: 24 additions & 10 deletions HKVizMod/MapExportTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,37 @@ public class MapRoomData {
public string sprite;
public string? spriteRough;
public bool hasRoughVersion;
public List<TextData> texts;
}

[System.Serializable]
public class ExportBounds {
public Vector3 min;
public Vector3 max;
public record TextData(
string objectPath,
string convoName,
string sheetName,
Vector3 position,
float fontSize,
float fontWeight,
ExportBounds bounds,
Vector4 origColor
);

[System.Serializable]
public record ExportBounds(
Vector3 min,
Vector3 max
) {
public static ExportBounds fromBounds(UnityEngine.Bounds bounds, UnityEngine.Vector3 substract) {
return new ExportBounds {
min = bounds.min - substract,
max = bounds.max - substract,
};
return new ExportBounds(
min: bounds.min - substract,
max: bounds.max - substract
);
}
}

[System.Serializable]
public class MapData {
public List<MapRoomData> rooms;
}
public record MapData(
List<MapRoomData> rooms,
List<TextData> areaNames
);
}
Loading

0 comments on commit 2177aab

Please sign in to comment.