Skip to content

Commit

Permalink
Merge pull request #16 from o-tr/master
Browse files Browse the repository at this point in the history
v0.2.13をリリース
  • Loading branch information
o-tr authored Nov 25, 2024
2 parents 323635c + c29e813 commit 03a135a
Show file tree
Hide file tree
Showing 17 changed files with 1,639 additions and 944 deletions.
Binary file modified Assets/Textures/SplashScreen/ImageSlide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Textures/SplashScreen/ImageSlideViewer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Runtime/Editor/ImageSlideEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace jp.ootr.ImageSlide.Editor
public class ImageSlideEditor : CommonDeviceEditor
{
[SerializeField] private StyleSheet imageSlideStyle;
private readonly List<VisualElement> _definedSourceElements = new List<VisualElement>();

private VisualElement _definedSourceContainer;
private readonly List<VisualElement> _definedSourceElements = new List<VisualElement>();
private SerializedProperty _definedSourceIntervals;
private SerializedProperty _definedSourceOffsets;
private SerializedProperty _definedSources;
Expand Down Expand Up @@ -60,7 +60,7 @@ protected override VisualElement GetContentTk()
bindingPath = nameof(ImageSlide.seekMode)
};
container.Add(seekMode);

var gimbalToggle = new Toggle("Gimbal")
{
bindingPath = nameof(ImageSlide.isGimbalEnabled)
Expand Down
42 changes: 32 additions & 10 deletions Runtime/jp.ootr.ImageSlide/Scripts/00_Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public static QueueType ParseQueue(DataToken data)
}

[CanBeNull]
public static Texture2D GetByIndex([CanBeNull]this Texture2D[][] texturesList, int index)
public static Texture2D GetByIndex([CanBeNull] this Texture2D[][] texturesList, int index)
{
return texturesList.GetByIndex(index, out var tmp1, out var tmp2);
return texturesList.GetByIndex(index, out var void1, out var void2);
}

[CanBeNull]
public static Texture2D GetByIndex([CanBeNull]this Texture2D[][] texturesList, int index, out int sourceIndex,
public static Texture2D GetByIndex([CanBeNull] this Texture2D[][] texturesList, int index, out int sourceIndex,
out int fileIndex)
{
sourceIndex = -1;
Expand All @@ -40,17 +40,39 @@ public static Texture2D GetByIndex([CanBeNull]this Texture2D[][] texturesList, i

return null;
}

public static bool GetByIndex([CanBeNull] this string[][] fileNames, int index, out int sourceIndex, out int fileIndex)
{
sourceIndex = -1;
fileIndex = -1;
if (fileNames == null) return false;
for (var i = 0; i < fileNames.Length; i++)
{
var names = fileNames[i];
if (index < names.Length)
{
sourceIndex = i;
fileIndex = index;
return true;
}

index -= names.Length;
}

return false;
}
}

public enum QueueType
{
None,
AddSourceLocal,
AddSource,
SyncAll,
RemoveSource,
SeekTo,
UpdateList,
UpdateSeekMode
AddSourceLocal, //1
AddSource,//2
SyncAll,//3
RemoveSource,//4
SeekTo,//5
UpdateList,//6
UpdateSeekMode,//7
RequestSyncAll,//8
}
}
2 changes: 1 addition & 1 deletion Runtime/jp.ootr.ImageSlide/Scripts/13_UISyncingModal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UISyncingModal : UIErrorModal
[SerializeField] private TextMeshProUGUI syncingModalContent;
[SerializeField] private ContentSizeFitter syncingModalContentSizeFitter;

protected virtual void ShowSyncingModal([CanBeNull]string content)
protected virtual void ShowSyncingModal([CanBeNull] string content)
{
syncingModal.SetActive(true);
syncingModalContent.text = content;
Expand Down
104 changes: 77 additions & 27 deletions Runtime/jp.ootr.ImageSlide/Scripts/22_LogicQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class LogicQueue : LogicSync
protected string[] Options = new string[0];

protected string[] Sources = new string[0];
public Texture2D[][] Textures = new Texture2D[0][];

public string[][] FileNames
{
Expand All @@ -41,13 +40,19 @@ public string[][] FileNames
}
}

protected void AddSourceQueue([CanBeNull]string url, [CanBeNull]string options)
public string[] GetSources()
{
return Sources;
}

protected void AddSourceQueue([CanBeNull] string url, [CanBeNull] string options)
{
if (!url.IsValidUrl() || !options.ParseSourceOptions())
{
ConsoleError($"invalid url: {url}", _logicQueuePrefix);
return;
}

var dic = new DataDictionary();
dic.SetValue("type", (int)QueueType.AddSourceLocal);
dic.SetValue("url", url);
Expand All @@ -62,13 +67,14 @@ protected void AddSourceQueue([CanBeNull]string url, [CanBeNull]string options)
AddQueue(json.String);
}

protected void RemoveSourceQueue([CanBeNull]string url)
protected void RemoveSourceQueue([CanBeNull] string url)
{
if (!url.IsValidUrl())
{
ConsoleError($"invalid url: {url}", _logicQueuePrefix);
return;
}

var dic = new DataDictionary();
dic.SetValue("type", (int)QueueType.RemoveSource);
dic.SetValue("url", url);
Expand All @@ -82,7 +88,7 @@ protected void RemoveSourceQueue([CanBeNull]string url)
AddSyncQueue(json.String);
}

private void AddQueue([CanBeNull]string queue)
private void AddQueue([CanBeNull] string queue)
{
if (queue.IsNullOrEmpty())
{
Expand All @@ -98,6 +104,22 @@ private void AddQueue([CanBeNull]string queue)
ProcessQueue();
}

private void AddHeadQueue([CanBeNull] string queue)
{
if (queue.IsNullOrEmpty())
{
ConsoleWarn("failed to add queue due to empty queue", _logicQueuePrefix);
return;
}

_queue = _queue.Unshift(queue);
ConsoleDebug($"add queue to head: {queue}", _logicQueuePrefix);
if (_isProcessing) return;

_isProcessing = true;
ProcessQueue();
}

protected void SeekTo(int index)
{
var dic = new DataDictionary();
Expand Down Expand Up @@ -170,6 +192,9 @@ private void ProcessQueue()
case QueueType.UpdateSeekMode:
ApplySeekMode(data);
break;
case QueueType.RequestSyncAll:
DoSyncAll();
break;
case QueueType.None:
break;
default:
Expand All @@ -184,6 +209,7 @@ private void AddSourceLocal(DataToken data)
!data.DataDictionary.TryGetValue("options", out var options))
{
ConsoleError($"url or options not found in local source: {data}", _logicQueuePrefix);
ProcessQueue();
return;
}

Expand All @@ -201,6 +227,14 @@ private void AddSource(DataToken data)
!data.DataDictionary.TryGetValue("options", out var options))
{
ConsoleError($"url or options not found in source: {data}", _logicQueuePrefix);
ProcessQueue();
return;
}

if (Networking.IsOwner(gameObject))
{
ConsoleDebug($"ignore add source because owner", _logicQueuePrefix);
ProcessQueue();
return;
}

Expand All @@ -217,26 +251,26 @@ private void RemoveSource(DataToken data)
if (!data.DataDictionary.TryGetValue("url", out var url))
{
ConsoleError($"url not found in remove source: {data}", _logicQueuePrefix);
ProcessQueue();
return;
}

var source = url.String;
if (!Sources.Has(source, out var index))
{
ConsoleError($"source not found in current sources: {source}", _logicQueuePrefix);
ProcessQueue();
return;
}

Sources = Sources.Remove(index, out var sourceUrl);
Options = Options.Remove(index);
FileNames = FileNames.Remove(index, out var removeFileNames);
Textures = Textures.Remove(index);
if (removeFileNames != null)
{
for (var i = 0; i < removeFileNames.Length; i++)
controller.CcReleaseTexture(sourceUrl, removeFileNames[i]);
}

if (removeFileNames != null)
foreach (var fileName in removeFileNames)
controller.CcReleaseTexture(sourceUrl, fileName);

if (currentIndex >= slideCount && Networking.IsOwner(gameObject))
{
if (slideCount == 0)
Expand Down Expand Up @@ -277,6 +311,12 @@ private void Seek(DataToken data)

private void SyncAll(DataToken data)
{
if (Networking.IsOwner(gameObject))
{
ConsoleDebug($"ignore sync all because owner", _logicQueuePrefix);
ProcessQueue();
return;
}
if (!data.DataDictionary.TryGetValue("sources", TokenType.DataList, out var sources) ||
!data.DataDictionary.TryGetValue("options", TokenType.DataList, out var options) ||
!data.DataDictionary.TryGetValue("index", TokenType.Double, out var indexToken) ||
Expand Down Expand Up @@ -338,19 +378,35 @@ private void SyncAll(DataToken data)
UrlsUpdated();
ProcessQueue();
}

public void OnSyncAllRequested()
{
if (!Networking.IsOwner(gameObject))
{
ConsoleDebug("send sync all request to owner", _logicQueuePrefix);
SendCustomNetworkEvent(NetworkEventTarget.Owner, nameof(DoSyncAll));
SendCustomNetworkEvent(NetworkEventTarget.Owner, nameof(OnSyncAllRequested));
}
else
{
ConsoleDebug("do sync all", _logicQueuePrefix);
DoSyncAll();
RequestSyncAll();
}
}

private void RequestSyncAll()
{
var dic = new DataDictionary();
dic.SetValue("type", (int)QueueType.RequestSyncAll);
if (!VRCJson.TrySerializeToJson(dic, JsonExportType.Minify, out var json))
{
ConsoleError($"failed to serialize request sync all json: {json}", _logicQueuePrefix);
return;
}

AddQueue(json.String);
if (_isProcessing) return;
_isProcessing = true;
ProcessQueue();
}

private void DoSyncAll()
Expand Down Expand Up @@ -406,6 +462,8 @@ private void UpdateList(DataToken data)
return;
}



Sources = sources.DataList.ToStringArray();
Options = options.DataList.ToStringArray();
UrlsUpdated();
Expand Down Expand Up @@ -444,23 +502,15 @@ public override void OnFilesLoadSuccess(string source, string[] fileNames)
dic.SetValue("options", _currentOptions);
if (VRCJson.TrySerializeToJson(dic, JsonExportType.Minify, out var json))
{
SyncQueue = json.String;
Sync();
AddSyncQueue(json.String);
}
}
else if (_currentType == QueueType.AddSource)
{
ConsoleDebug($"add source to current sources: {_currentUrl}", _logicQueuePrefix);
Sources = Sources.Append(_currentUrl);
Options = Options.Append(_currentOptions);
FileNames = FileNames.Append(fileNames);
var textures = new Texture2D[fileNames.Length];
for (var i = 0; i < fileNames.Length; i++)
textures[i] = controller.CcGetTexture(_currentUrl, fileNames[i]);
ConsoleDebug($"add source to current sources: {_currentUrl}", _logicQueuePrefix);
Sources = Sources.Append(_currentUrl);
Options = Options.Append(_currentOptions);
FileNames = FileNames.Append(fileNames);

Textures = Textures.Append(textures);
UrlsUpdated();
}
UrlsUpdated();

ProcessQueue();
}
Expand Down
5 changes: 3 additions & 2 deletions Runtime/jp.ootr.ImageSlide/Scripts/25_LogicPreloadUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace jp.ootr.ImageSlide
{
public class LogicPreloadUrls : LogicResetTransform
{
[ItemCanBeNull][SerializeField] internal string[] definedSources = new string[0];
[ItemCanBeNull] [SerializeField] internal string[] definedSources = new string[0];
[SerializeField] internal URLType[] definedSourceTypes = new URLType[0];
[SerializeField] internal float[] definedSourceOffsets = new float[0];
[SerializeField] internal float[] definedSourceIntervals = new float[0];
[ItemCanBeNull][SerializeField] internal VRCUrl[] definedSourceUrls = new VRCUrl[0];
[ItemCanBeNull] [SerializeField] internal VRCUrl[] definedSourceUrls = new VRCUrl[0];

public override void OnPlayerJoined(VRCPlayerApi player)
{
Expand All @@ -24,6 +24,7 @@ public override void OnPlayerJoined(VRCPlayerApi player)
if (url == null) continue;
controller.UsAddUrl(url);
}

for (var i = 0; i < definedSources.Length; i++)
{
if (definedSources[i] == null) continue;
Expand Down
9 changes: 6 additions & 3 deletions Runtime/jp.ootr.ImageSlide/Scripts/31_UISourceList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public class UISourceList : LogicPreloadUrls
protected Toggle[] SourceToggles;


protected void AddUrl([CanBeNull]VRCUrl url, URLType type, [CanBeNull]string options)
protected void AddUrl([CanBeNull] VRCUrl url, URLType type, [CanBeNull] string options)
{
if (url == null || !url.ToString().IsValidUrl())
{
ConsoleError("invalid url", _uiSourceListPrefix);
return;
}

controller.UsAddUrl(url);
AddSourceQueue(url.ToString(), options);
}
Expand Down Expand Up @@ -76,7 +77,8 @@ protected void ResetInputs()
sourceVideoOffsetSlider.value = 0.5f;
}

public void BuildSourceList([CanBeNull][ItemCanBeNull]string[] sources = null, [CanBeNull]URLType[] options = null)
public void BuildSourceList([CanBeNull] [ItemCanBeNull] string[] sources = null,
[CanBeNull] URLType[] options = null)
{
if (sources == null || options == null)
{
Expand All @@ -94,13 +96,14 @@ public void BuildSourceList([CanBeNull][ItemCanBeNull]string[] sources = null, [
Generate(sources, options);
}

private void Generate([CanBeNull]string[] sources, [CanBeNull]URLType[] types)
private void Generate([CanBeNull] string[] sources, [CanBeNull] URLType[] types)
{
if (sources == null || types == null)
{
ConsoleError("sources or types is null", _uiSourceListPrefix);
return;
}

ConsoleDebug($"generate source list: {sources.Length}", _uiSourceListPrefix);
var children = rootSourceObject.transform.GetChildren();
var baseObject = originalSourceNameInput.transform.parent.gameObject;
Expand Down
1 change: 0 additions & 1 deletion Runtime/jp.ootr.ImageSlide/Scripts/41_UIDeviceList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;

namespace jp.ootr.ImageSlide
{
Expand Down
Loading

0 comments on commit 03a135a

Please sign in to comment.