Skip to content

Commit

Permalink
Refactor the way we manage devlogs in preparation for #5. Currently w…
Browse files Browse the repository at this point in the history
…e are not generating a markdown file at all. We will, shortly, generate it whenever a change occurs.
  • Loading branch information
rgardler-msft committed Jul 30, 2020
1 parent 1c63fc0 commit 6ccfc0a
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 43 deletions.
76 changes: 70 additions & 6 deletions Assets/Dev Log 1.0.asset
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ MonoBehaviour:
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
--- !u!114 &-4136142861470906683
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa508ee653f80ef478ab4842c6bb02ba, type: 3}
m_Name: 7/29/2020 11:13 PM
m_EditorClassIdentifier:
shortDescription: Everything looks good one more test...
longDescription:
metaData: []
captures: []
commitHash:
isSocial: 0
tweeted: 0
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
--- !u!114 &-2968178578384053856
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -157,6 +179,28 @@ MonoBehaviour:
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
--- !u!114 &-1030454258410723379
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa508ee653f80ef478ab4842c6bb02ba, type: 3}
m_Name: 7/29/2020 11:13 PM
m_EditorClassIdentifier:
shortDescription: A second entry to test reording with
longDescription:
metaData: []
captures: []
commitHash:
isSocial: 0
tweeted: 0
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
--- !u!114 &-993016919206714112
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -327,12 +371,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 29cf0f8db76caf6458571bbe2db3c861, type: 3}
m_Name: Dev Log 1.0
m_EditorClassIdentifier:
entries:
- {fileID: -5034860452252757136}
- {fileID: -993016919206714112}
- {fileID: 374282915631882679}
- {fileID: 5510801695314803418}
- {fileID: -394096443042062930}
m_Entries:
- {fileID: 9012443712184459491}
- {fileID: -1030454258410723379}
- {fileID: -4136142861470906683}
--- !u!114 &374282915631882679
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -684,3 +726,25 @@ MonoBehaviour:
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
--- !u!114 &9012443712184459491
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa508ee653f80ef478ab4842c6bb02ba, type: 3}
m_Name: 7/29/2020 11:12 PM
m_EditorClassIdentifier:
shortDescription: Testing out the new DevLogEntries management refactoring
longDescription:
metaData: []
captures: []
commitHash:
isSocial: 0
tweeted: 0
lastTweetFileTime: 0
discordPost: 0
lastDiscordPostFileTime: 0
5 changes: 3 additions & 2 deletions Assets/Editor/DevLog.cs → Assets/Editor/DevLogMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
namespace WizardsCode.DevLogger
{
/// <summary>
/// Manages a DevLog document.
/// Manages a DevLog markdown document. This is not the DevLog data strucutre (see
/// DevLogEntries). This is only concerned with writing the DevLog markdown file.
/// </summary>
public class DevLog
public class DevLogMarkdown
{
public const string STORAGE_DIRECTORY = "DevLog/";

Expand Down
File renamed without changes.
41 changes: 21 additions & 20 deletions Assets/Editor/DevLogPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class DevLogPanel

public DevLogPanel(DevLogEntries entries)
{
Entries = entries;
this.entries = entries;
}

internal DevLogEntries Entries { get; set; }
internal DevLogEntries entries { get; set; }
internal DevLogScreenCaptures ScreenCaptures { get; set; }

public void OnGUI()
Expand All @@ -39,9 +39,9 @@ public void OnGUI()
string response;
if (GUILayout.Button("Tweet Selected Entry", GUILayout.Height(50)))
{
if (Twitter.PublishTweet(Entries.entries[logList.index], out response)) {
Entries.entries[logList.index].tweeted = true;
Entries.entries[logList.index].lastTweetFileTime = DateTime.Now.ToFileTimeUtc();
if (Twitter.PublishTweet(entries.GetEntry(logList.index), out response)) {
entries.GetEntry(logList.index).tweeted = true;
entries.GetEntry(logList.index).lastTweetFileTime = DateTime.Now.ToFileTimeUtc();
} else
{
// TODO Handle failed tweet gracefully
Expand All @@ -50,9 +50,9 @@ public void OnGUI()
}
if (GUILayout.Button("Post to Discord", GUILayout.Height(50)))
{
Discord.PostEntry(Entries.entries[logList.index]);
Entries.entries[logList.index].discordPost = true;
Entries.entries[logList.index].lastDiscordPostFileTime = DateTime.Now.ToFileTimeUtc();
Discord.PostEntry(entries.GetEntry(logList.index));
entries.GetEntry(logList.index).discordPost = true;
entries.GetEntry(logList.index).lastDiscordPostFileTime = DateTime.Now.ToFileTimeUtc();
}
}
listScrollPosition = EditorGUILayout.BeginScrollView(listScrollPosition);
Expand All @@ -64,26 +64,27 @@ public void OnGUI()
private DevLogEntries lastEntriesList;
private void ConfigureReorderableLogList()
{
if (Entries != lastEntriesList)
if (entries != lastEntriesList)
{
logList = new ReorderableList(Entries.entries, typeof(DevLogEntry), true, true, true, true);
logList = new ReorderableList(entries.GetEntries(), typeof(DevLogEntry), true, true, true, true);
logList.drawElementCallback = DrawLogListElement;
logList.drawHeaderCallback = DrawHeader;
logList.elementHeightCallback = ElementHeightCallback;
logList.onReorderCallback = SaveReorderedList;
logList.displayAdd = false;

lastEntriesList = Entries;
lastEntriesList = entries;
}
else if (Entries == null)
else if (entries == null)
{
logList = null;
}
}

private void SaveReorderedList(ReorderableList list)
{
EditorUtility.SetDirty(Entries);
EditorUtility.SetDirty(entries);

AssetDatabase.SaveAssets();
}

Expand All @@ -92,8 +93,8 @@ private float ElementHeightCallback(int index)
float height = EditorGUIUtility.singleLineHeight; // title
height += EditorGUIUtility.singleLineHeight;// Date
height += EditorGUIUtility.singleLineHeight * listDescriptionLines; // descrption
height += EditorGUIUtility.singleLineHeight * Entries.entries[index].metaData.Count; // meta data
height += EditorGUIUtility.singleLineHeight * Entries.entries[index].captures.Count; // capture
height += EditorGUIUtility.singleLineHeight * entries.GetEntry(index).metaData.Count; // meta data
height += EditorGUIUtility.singleLineHeight * entries.GetEntry(index).captures.Count; // capture
height += EditorGUIUtility.singleLineHeight;// Commit Hash
height += EditorGUIUtility.singleLineHeight;// Social Flag
height += EditorGUIUtility.singleLineHeight;// Tweeted
Expand All @@ -109,7 +110,7 @@ private void DrawHeader(Rect rect)

private void DrawLogListElement(Rect rect, int index, bool isActive, bool isFocused)
{
DevLogEntry entry = Entries.entries[index];
DevLogEntry entry = entries.GetEntry(index);

Rect labelRect = new Rect(rect.x, rect.y, listLabelWidth, EditorGUIUtility.singleLineHeight);
EditorGUI.PrefixLabel(labelRect, new GUIContent("Title"));
Expand All @@ -127,7 +128,7 @@ private void DrawLogListElement(Rect rect, int index, bool isActive, bool isFocu
EditorGUI.LabelField(fieldRect, entry.created.ToString("dd MMM yyyy"));

labelRect = new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight, labelRect.width, labelRect.height);
if (Entries.entries[index].metaData.Count != 0)
if (entries.GetEntry(index).metaData.Count != 0)
{
EditorGUI.PrefixLabel(labelRect, new GUIContent("Meta Data"));
for (int i = 0; i < entry.metaData.Count; i++)
Expand All @@ -137,8 +138,8 @@ private void DrawLogListElement(Rect rect, int index, bool isActive, bool isFocu
}
}

labelRect = new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight * Entries.entries[index].metaData.Count, labelRect.width, labelRect.height);
if (Entries.entries[index].captures.Count != 0)
labelRect = new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight * entries.GetEntry(index).metaData.Count, labelRect.width, labelRect.height);
if (entries.GetEntry(index).captures.Count != 0)
{
EditorGUI.PrefixLabel(labelRect, new GUIContent("Captures"));
for (int i = 0; i < entry.captures.Count; i++)
Expand All @@ -148,7 +149,7 @@ private void DrawLogListElement(Rect rect, int index, bool isActive, bool isFocu
}
}

labelRect = new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight * Entries.entries[index].captures.Count, labelRect.width, labelRect.height);
labelRect = new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight * entries.GetEntry(index).captures.Count, labelRect.width, labelRect.height);
EditorGUI.PrefixLabel(labelRect, new GUIContent("Commit"));
fieldRect = new Rect(fieldRect.x, labelRect.y, fieldRect.width, EditorGUIUtility.singleLineHeight);
EditorGUI.TextArea(fieldRect, entry.commitHash);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Editor/DevLoggerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void OnGUI()
if (m_DevLogEntries != null && m_ScreenCaptures != null)
{
entryPanel.ScreenCaptures = m_ScreenCaptures;
entryPanel.Entries = m_DevLogEntries;
entryPanel.entries = m_DevLogEntries;
entryPanel.OnGUI();

EditorGUILayout.Space();
Expand Down Expand Up @@ -179,7 +179,7 @@ void OnGUI()
if (devLogPanel == null) devLogPanel = new DevLogPanel(m_DevLogEntries);

devLogPanel.ScreenCaptures = m_ScreenCaptures;
devLogPanel.Entries = m_DevLogEntries;
devLogPanel.entries = m_DevLogEntries;
devLogPanel.OnGUI();
break;
case 2:
Expand Down
15 changes: 6 additions & 9 deletions Assets/Editor/EntryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class EntryPanel

public EntryPanel(DevLogEntries entries, DevLogScreenCaptures screenCaptures)
{
Entries = entries;
this.entries = entries;
ScreenCaptures = screenCaptures;
}

internal DevLogEntries Entries { get; set; }
internal DevLogEntries entries { get; set; }
internal DevLogScreenCaptures ScreenCaptures { get; set; }

internal void OnEnable()
Expand Down Expand Up @@ -192,7 +192,7 @@ private void FoldersGUI() {
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Open Devlog"))
{
string filepath = DevLog.GetAbsoluteProjectDirectory() + DevLog.GetRelativeCurrentFilePath();
string filepath = DevLogMarkdown.GetAbsoluteProjectDirectory() + DevLogMarkdown.GetRelativeCurrentFilePath();
System.Diagnostics.Process.Start(filepath);
}
EditorGUILayout.EndHorizontal();
Expand Down Expand Up @@ -244,18 +244,15 @@ public void AppendDevlog(bool withImage, bool withTweet)
}

entry.longDescription = detailText;

DevLog.Append(entry);
}
else
{
entry.longDescription = detailText;
DevLog.Append(entry);
}

Entries.entries.Add(entry);
AssetDatabase.AddObjectToAsset(entry, Entries);
EditorUtility.SetDirty(Entries);
entries.AddEntry(entry);
AssetDatabase.AddObjectToAsset(entry, entries);
EditorUtility.SetDirty(entries);
AssetDatabase.SaveAssets();

shortText = "";
Expand Down
22 changes: 18 additions & 4 deletions Assets/Editor/ScriptableObject/DevLogEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ namespace WizardsCode.DevLogger
public class DevLogEntries : ScriptableObject
{
[SerializeField, Tooltip("The entries in this Dev Log.")]
public List<DevLogEntry> entries = new List<DevLogEntry>();
List<DevLogEntry> m_Entries = new List<DevLogEntry>();

internal void AddEntry(DevLogEntry entry)
{
m_Entries.Add(entry);
}
internal DevLogEntry GetEntry(int index)
{
return m_Entries[index];
}

internal List<DevLogEntry> GetEntries()
{
return m_Entries;
}

/// <summary>
/// Get list of all Entries that are marked for social sharing
Expand All @@ -19,10 +33,10 @@ public class DevLogEntries : ScriptableObject
internal List<DevLogEntry> GetAvailableSocialEntries()
{
List<DevLogEntry> results = new List<DevLogEntry>();
for (int i = 0; i < entries.Count; i++)
for (int i = 0; i < m_Entries.Count; i++)
{
if (entries[i].isSocial && !entries[i].tweeted && !entries[i].discordPost) {
results.Add(entries[i]);
if (m_Entries[i].isSocial && !m_Entries[i].tweeted && !m_Entries[i].discordPost) {
results.Add(m_Entries[i]);
}
}
return results;
Expand Down

0 comments on commit 6ccfc0a

Please sign in to comment.