Skip to content

Commit

Permalink
feat(mod): Finish #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
AamuLumi committed Nov 20, 2022
1 parent af8370f commit dd6aeea
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 44 deletions.
3 changes: 2 additions & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>aamu.diary</identifier>
<version>1.0.1</version>
<version>1.1.0</version>
<dependencies>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
</dependencies>
<loadAfter>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
<li>neptimus7.progressrenderer</li>
</loadAfter>
<showCrossPromotions>true</showCrossPromotions>
<downloadUri></downloadUri>
Expand Down
Binary file modified Assemblies/Diary.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions Languages/English/Keyed/Diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ Please check write access to the folder are correct au dossier or edit folder pa
<Diary_None>None</Diary_None>
<Diary_Log_Writer_Filter_Explanation>Diary can write automatically logs in the Diary. You just have to set the next option to the logs which must be written automatically.</Diary_Log_Writer_Filter_Explanation>
<Diary_Log_Writer_Filter>Automatic log writer filter</Diary_Log_Writer_Filter>
<Diary>Journal</Diary>
<Diary_Images>Images</Diary_Images>
<Diary_Connected_To_Progress_Renderer>Diary is correctly connected to Progress Renderer.</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary is not connected to Progress Renderer. If Progress Renderer is enabled, you have to place it before Diary.</Diary_Not_Connected_To_Progress_Renderer>
</LanguageData>
4 changes: 4 additions & 0 deletions Languages/French/Keyed/Diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ Veuillez vérifier que les droits d'accès au dossier sont corrects ou modifier
<Diary_None>Aucun</Diary_None>
<Diary_Log_Writer_Filter_Explanation>Diary peut écrire automatiquement les informations dans votre Journal. Vous devez simplement sélectionner via la prochaine option ce que vous voulez que le mod écrive automatiquement.</Diary_Log_Writer_Filter_Explanation>
<Diary_Log_Writer_Filter>Filtre d'écriture automatique des informations</Diary_Log_Writer_Filter>
<Diary>Journal</Diary>
<Diary_Images>Images</Diary_Images>
<Diary_Connected_To_Progress_Renderer>Diary est correctement connecté à Progress Renderer.</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary n'est pas connecté à Progress Renderer. Si Progress Renderer est activé, veuillez le placer avant Diary.</Diary_Not_Connected_To_Progress_Renderer>
</LanguageData>
30 changes: 29 additions & 1 deletion Source/Diary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Verse.AI;
using Verse.Sound;
using RimWorld.Planet;
using static UnityEngine.UI.Image;

namespace Diary
{
Expand All @@ -21,10 +22,37 @@ public class Diary : Mod
DiarySettings settings;

public Diary(ModContentPack content) : base(content)
{
var harmony = new Harmony("aamulumi.diary");

Init(harmony);

if (ModLister.GetActiveModWithIdentifier("neptimus7.progressrenderer") != null)
{
InitWithProgressRenderer(harmony);
}
}

public void Init(Harmony harmony)
{
settings = GetSettings<DiarySettings>();

new Harmony("aamulumi.diary").PatchAll();
harmony.PatchAll();
}

public void InitWithProgressRenderer(Harmony harmony)
{

var PR_RenderManager = System.Type.GetType("ProgressRenderer.MapComponent_RenderManager, Progress-Renderer");

if (PR_RenderManager != null)
{
var createFilePath = PR_RenderManager.GetMethod("CreateFilePath", AccessTools.all);

harmony.Patch(createFilePath, postfix: new HarmonyMethod(typeof(ListenProgressRenderer_CreateFilePath).GetMethod("Postfix", AccessTools.all)));

settings.ConnectedToProgressRenderer = true;
}
}

public override void DoSettingsWindowContents(Rect inRect)
Expand Down
77 changes: 67 additions & 10 deletions Source/DiaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ namespace Diary
public class DiaryService : GameComponent
{
private Dictionary<string, string> entries;
private Dictionary<string, List<DiaryImageEntry>> images;
private Dictionary<string, List<DiaryImageEntry>> imagesPerDay;
private List<DiaryImageEntry> allImages;

public DiaryService(Game game)
{
entries = new Dictionary<string, string>();
images = new Dictionary<string, List<DiaryImageEntry>>();
imagesPerDay = new Dictionary<string, List<DiaryImageEntry>>();
allImages = new List<DiaryImageEntry>();
}

private string[] GetTextEntriesToExport()
Expand Down Expand Up @@ -120,6 +122,8 @@ public void WriteEntryNow(string data)
public void AppendEntryNow(string data, bool onNewLine = true, bool writeCurrentHour = true)
{
string key = GetDictionaryKey(TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear());
string currentEntry = entries.TryGetValue(key);


if (writeCurrentHour)
{
Expand All @@ -129,30 +133,55 @@ public void AppendEntryNow(string data, bool onNewLine = true, bool writeCurrent
{
data = $"\n{data}";
}
if (currentEntry != null)
{
data = $"{currentEntry}{data}";
}

entries.SetOrAdd(key, $"{entries[key]}{data}");
entries.SetOrAdd(key, data);
}

public List<DiaryImageEntry> ReadImages(int day, Quadrum quadrum, int year)
public List<DiaryImageEntry> GetAllImages()
{
DefaultMessage defaultMessageSetting = LoadedModManager.GetMod<Diary>().GetSettings<DiarySettings>().DefaultMessage;
return allImages;
}

public int GetIndexForAllImages(int day, Quadrum quadrum, int year)
{
for (int i = 0; i < allImages.Count; i++)
{
DiaryImageEntry entry = allImages[i];

if (entry.Year > year || (entry.Year == year && (entry.Quadrum > quadrum || (entry.Quadrum == quadrum && entry.Days >= day))))
{
return i;
}
}

return images.TryGetValue(GetDictionaryKey(day, quadrum, year));
return -1;
}

public List<DiaryImageEntry> ReadImages(int day, Quadrum quadrum, int year)
{
return imagesPerDay.TryGetValue(GetDictionaryKey(day, quadrum, year));
}

public void AddImageNow(string path)
{
string key = GetDictionaryKey(TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear());
List<DiaryImageEntry> currentImages = images.TryGetValue(key);
List<DiaryImageEntry> currentImages = imagesPerDay.TryGetValue(key);

if (currentImages == null)
{
currentImages = new List<DiaryImageEntry>();
}

currentImages.Add(new DiaryImageEntry(path, TimeTools.GetCurrentHour()));
DiaryImageEntry entryToAdd = new DiaryImageEntry(path, TimeTools.GetCurrentHour(), TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear());

currentImages.Add(entryToAdd);

images.SetOrAdd(key, currentImages);
imagesPerDay.SetOrAdd(key, currentImages);
allImages.Add(entryToAdd);
}

public void Export()
Expand Down Expand Up @@ -201,8 +230,36 @@ public override void ExposeData()
base.ExposeData();

Scribe_Collections.Look(ref entries, "entries", LookMode.Value, LookMode.Value);
Scribe_Collections.Look(ref allImages, "allImages", LookMode.Deep);

if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
if (entries == null)
{
entries = new Dictionary<string, string>();
}
if (allImages == null)
{
allImages = new List<DiaryImageEntry>();
imagesPerDay = new Dictionary<string, List<DiaryImageEntry>>();
}

Log.Message(entries.ToStringFullContents());
foreach (DiaryImageEntry entry in allImages)
{
string key = GetDictionaryKey(entry.Days, entry.Quadrum, entry.Year);

List<DiaryImageEntry> currentImages = imagesPerDay.TryGetValue(key);

if (currentImages == null)
{
currentImages = new List<DiaryImageEntry>();
}

currentImages.Add(entry);

imagesPerDay.SetOrAdd(key, currentImages);
}
}
}

public override void FinalizeInit()
Expand Down
13 changes: 13 additions & 0 deletions Source/DiarySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class DiarySettings : ModSettings
private LogWriterFilter logWriterFilter;
private LogFilter defaultLogFilter;

public bool ConnectedToProgressRenderer;

public string FolderPath
{
get { return folderPath; }
Expand Down Expand Up @@ -44,6 +46,8 @@ public override void ExposeData()
{
base.ExposeData();

ConnectedToProgressRenderer = false;

Scribe_Values.Look(ref folderPath, "folderPath", Application.dataPath);
Scribe_Values.Look(ref exportFormat, "exportFormat", ExportFormat.Text);
Scribe_Values.Look(ref defaultMessage, "defaultMessage", DefaultMessage.Empty);
Expand Down Expand Up @@ -130,6 +134,15 @@ public void DoSettingsWindowContents(Rect inRect)
Find.WindowStack.Add(new FloatMenu(list));
}

if (ConnectedToProgressRenderer)
{
listingStandard.Label("Diary_Connected_To_Progress_Renderer".Translate());
}
else
{
listingStandard.Label("Diary_Not_Connected_To_Progress_Renderer".Translate());
}

listingStandard.End();
}
}
Expand Down
5 changes: 5 additions & 0 deletions Source/DiaryTimeTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public static Vector2 GetCurrentLocation()
return vector;
}

public static int GetCurrentTicks()
{
return Find.TickManager.TicksAbs;
}

public static int GetCurrentHour()
{
return GenDate.HourOfDay(Find.TickManager.TicksAbs, TimeTools.GetCurrentLocation().x);
Expand Down
23 changes: 21 additions & 2 deletions Source/DiaryTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,34 @@ public static string GetLogWriterFilterName(LogWriterFilter f)
}
}

public class DiaryImageEntry
public class DiaryImageEntry : IExposable
{
public string Path;
public int Hours;
public int Days;
public Quadrum Quadrum;
public int Year;

public DiaryImageEntry(string path, int hours)
public DiaryImageEntry()
{
}

public DiaryImageEntry(string path, int hours, int day, Quadrum quadrum, int year)
{
Path = path;
Hours = hours;
Days = day;
Quadrum = quadrum;
Year = year;
}

public void ExposeData()
{
Scribe_Values.Look(ref Path, "Path");
Scribe_Values.Look(ref Hours, "Hours");
Scribe_Values.Look(ref Days, "Days");
Scribe_Values.Look(ref Quadrum, "Quadrum");
Scribe_Values.Look(ref Year, "Year");
}
}
}
9 changes: 7 additions & 2 deletions Source/GUIDraggableTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public class GUIDraggableTexture
private Rect outerRect;
private Rect initialOuterRect;
private bool mustRecomputeOuterRect;
private bool firstLoading;

public GUIDraggableTexture()
{
currentImageScale = 1.0f;

imageRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
mustRecomputeOuterRect = false;
firstLoading = true;
}

public bool HasImageLoaded()
Expand All @@ -56,7 +58,6 @@ public bool IsLoading()

public void LoadTexture(string path)
{
Log.Message($"Laod {path}");
imageLoading = true;
imageLoadRequest = UnityWebRequestTexture.GetTexture($"file://{path}");

Expand All @@ -68,7 +69,11 @@ public void LoadTexture(string path)
imageHeight = currentImageDisplayed.height;

imageLoading = false;
mustRecomputeOuterRect = true;
if (firstLoading)
{
mustRecomputeOuterRect = true;
}
firstLoading = false;
};
}

Expand Down

0 comments on commit dd6aeea

Please sign in to comment.