Skip to content

Commit

Permalink
code clean and version up
Browse files Browse the repository at this point in the history
  • Loading branch information
denpadokei committed Jun 29, 2023
1 parent 5614239 commit 115d8ae
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 130 deletions.
28 changes: 14 additions & 14 deletions Chat/ChatDisplay.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public Color AccentColor

set
{
this.SetProperty(ref this._accentColor, value);
_ = this.SetProperty(ref this._accentColor, value);
this.UpdateMessages();
}
}
Expand All @@ -205,7 +205,7 @@ public Color HighlightColor
get => this._highlightColor;
set
{
this.SetProperty(ref this._highlightColor, value);
_ = this.SetProperty(ref this._highlightColor, value);
this.UpdateMessages();
}
}
Expand All @@ -217,7 +217,7 @@ public Color PingColor
get => this._pingColor;
set
{
this.SetProperty(ref this._pingColor, value);
_ = this.SetProperty(ref this._pingColor, value);
this.UpdateMessages();
}
}
Expand All @@ -229,7 +229,7 @@ public Color BackgroundColor
get => this._backGroundColor;
set
{
this.SetProperty(ref this._backGroundColor, value);
_ = this.SetProperty(ref this._backGroundColor, value);
this._chatScreen.GetComponentsInChildren<ImageView>().FirstOrDefault(x => x.name == "bg").color = value;
}
}
Expand All @@ -241,7 +241,7 @@ public Color TextColor
get => this._textColor;
set
{
this.SetProperty(ref this._textColor, value);
_ = this.SetProperty(ref this._textColor, value);
this.UpdateMessages();
}
}
Expand All @@ -253,7 +253,7 @@ public float FontSize
get => this._fontsize;
set
{
this.SetProperty(ref this._fontsize, value);
_ = this.SetProperty(ref this._fontsize, value);
this.UpdateMessages();
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ public int ChatWidth
get => this._chatWidth;
set
{
this.SetProperty(ref this._chatWidth, value);
_ = this.SetProperty(ref this._chatWidth, value);
this._chatScreen.ScreenSize = new Vector2(this.ChatWidth, this.ChatHeight);
this._chatContainer.GetComponent<RectMask2D>().rectTransform.sizeDelta = new Vector2(this.ChatWidth, this.ChatHeight);
this.UpdateMessages();
Expand All @@ -301,7 +301,7 @@ public int ChatHeight
get => this._chatHeight;
set
{
this.SetProperty(ref this._chatHeight, value);
_ = this.SetProperty(ref this._chatHeight, value);
this._chatScreen.ScreenSize = new Vector2(this.ChatWidth, this.ChatHeight);
this._chatContainer.GetComponent<RectMask2D>().rectTransform.sizeDelta = new Vector2(this.ChatWidth, this.ChatHeight);
this.UpdateMessages();
Expand All @@ -315,7 +315,7 @@ public Vector3 ChatPosition
get => this._chatPosition;
set
{
this.SetProperty(ref this._chatPosition, value);
_ = this.SetProperty(ref this._chatPosition, value);
this._chatScreen.ScreenPosition = value;
}
}
Expand All @@ -327,7 +327,7 @@ public Vector3 ChatRotation
get => this._chatRotation;
set
{
this.SetProperty(ref this._chatRotation, value);
_ = this.SetProperty(ref this._chatRotation, value);
this._chatScreen.ScreenRotation = Quaternion.Euler(value);
}
}
Expand All @@ -339,7 +339,7 @@ public bool AllowMovement
get => this._allowMovement;
set
{
this.SetProperty(ref this._allowMovement, value);
_ = this.SetProperty(ref this._allowMovement, value);
this._chatScreen.ShowHandle = value;
}
}
Expand All @@ -359,7 +359,7 @@ public bool ReverseChatOrder
get => this._reverseChatOrder;
set
{
this.SetProperty(ref this._reverseChatOrder, value);
_ = this.SetProperty(ref this._reverseChatOrder, value);
this._updateMessagePositions = true;
//this.UpdateMessages();
}
Expand Down Expand Up @@ -426,7 +426,7 @@ protected async void ReIrcConnect()
}
finally {
this.ReconnectEnable = true;
this._connectSemaphore.Release();
_ = this._connectSemaphore.Release();
}
}

Expand All @@ -441,7 +441,7 @@ protected async void PubSubReconnect(object instance)
Logger.Error(e);
}
finally {
this._connectSemaphore.Release();
_ = this._connectSemaphore.Release();
}
}

Expand Down
26 changes: 16 additions & 10 deletions Chat/ChatDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace EnhancedStreamChat.Chat
{
[HotReload]
public partial class ChatDisplay : BSMLAutomaticViewController, IAsyncInitializable, IChatDisplay, IDisposable, ILatePreRenderRebuildReciver//, IAffinity
public partial class ChatDisplay : BSMLAutomaticViewController, IAsyncInitializable, IChatDisplay, IDisposable, ILatePreRenderRebuildReciver
{
//゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*
#region // プロパティ
Expand All @@ -41,6 +41,12 @@ public partial class ChatDisplay : BSMLAutomaticViewController, IAsyncInitializa
#endregion
//゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*゚+。*゚+。。+゚*。+゚ ゚+。*゚+。。+゚*。+゚ ゚+。*
#region // パブリックメソッド
/// <summary>
/// 初期化処理
/// </summary>
/// <param name="token"></param>
/// <returns></returns>

public async Task InitializeAsync(CancellationToken token)
{
while (!this._fontManager.IsInitialized) {
Expand Down Expand Up @@ -75,7 +81,7 @@ public void OnMessageCleared(string messageId)
if (string.IsNullOrEmpty(messageId)) {
return;
}
MainThreadInvoker.Invoke(() =>
_ = MainThreadInvoker.Invoke(() =>
{
foreach (var msg in this._messages.Where(x => x.Text.ChatMessage?.Id == messageId)) {
this.ClearMessage(msg);
Expand All @@ -87,7 +93,7 @@ public void OnChatCleared(string userId)
if (string.IsNullOrEmpty(userId)) {
return;
}
MainThreadInvoker.Invoke(() =>
_ = MainThreadInvoker.Invoke(() =>
{
foreach (var msg in this._messages.Where(x => x.Text.ChatMessage?.Sender?.Id == userId)) {
this.ClearMessage(msg);
Expand All @@ -99,7 +105,7 @@ public async Task OnTextMessageReceived(IESCChatMessage msg, DateTime dateTime)
{
var main = await this._chatMessageBuilder.BuildMessage(msg, this._fontManager.FontInfo, BuildMessageTarget.Main);
var sub = await this._chatMessageBuilder.BuildMessage(msg, this._fontManager.FontInfo, BuildMessageTarget.Sub);
_ = MainThreadInvoker.Invoke(() => this.CreateMessage(msg, dateTime, main, sub));
await MainThreadInvoker.Invoke(() => this.CreateMessage(msg, dateTime, main, sub));
}

private void OnVRPointerHelper_OnPointerEnable(VRPointer arg1, EventArgs arg2)
Expand Down Expand Up @@ -189,9 +195,9 @@ private void SetupScreens()

private void SetCurrentLayer(int layer)
{
var visible = VisibilityLayer.HmdOnlyAndReflected;
VisibilityLayer visible;
switch ((PluginConfig.LayerType)layer) {

case PluginConfig.LayerType.UI:
visible = VisibilityLayer.UI;
break;
Expand Down Expand Up @@ -383,9 +389,9 @@ private string BuildClearedMessage(EnhancedTextMeshProUGUI msg)
var sb = new StringBuilder($"<color={nameColorCode}>{msg.ChatMessage.Sender.DisplayName}</color>");
var badgeEndIndex = msg.text.IndexOf("<color=");
if (badgeEndIndex != -1) {
sb.Insert(0, msg.text.Substring(0, badgeEndIndex));
_ = sb.Insert(0, msg.text.Substring(0, badgeEndIndex));
}
sb.Append(": <color=#bbbbbbff><message deleted></color>");
_ = sb.Append(": <color=#bbbbbbff><message deleted></color>");
return sb.ToString();
}

Expand All @@ -400,7 +406,7 @@ private void ClearMessage(EnhancedTextMeshProUGUIWithBackground msg)
}
private void CreateMessage(IESCChatMessage msg, DateTime date, string mainMessage, string subMassage)
{
MainThreadInvoker.Invoke(() =>
_ = MainThreadInvoker.Invoke(() =>
{
var newMsg = this._textPoolContaner.Spawn();
newMsg.transform.SetParent(this._chatContainer.transform, false);
Expand Down Expand Up @@ -470,6 +476,7 @@ private void OnCatCoreManager_OnFollow(string channelId, in CatCore.Models.Twitc
};
_ = this.OnTextMessageReceived(mes, DateTime.Now);
}

private void OnCatCoreManager_OnRewardRedeemed(string channelId, in CatCore.Models.Twitch.PubSub.Responses.ChannelPointsChannelV1.RewardRedeemedData data)
{
var mes = new ESCChatMessage(Guid.NewGuid().ToString(), $"{data.User.DisplayName} used points {data.Reward.Title}({data.Reward.Cost}).")
Expand All @@ -493,7 +500,6 @@ private void OnCatCoreManager_OnRewardRedeemed(string channelId, in CatCore.Mode
private Material _chatMoverMaterial;
private ImageView _bg;
private bool _updateMessagePositions = false;
private readonly WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame();
private MemoryPoolContainer<EnhancedTextMeshProUGUIWithBackground> _textPoolContaner;
private ICatCoreManager _catCoreManager;
private ChatMessageBuilder _chatMessageBuilder;
Expand Down
49 changes: 27 additions & 22 deletions Chat/ChatImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ChatImageProvider(EnhancedImageInfo.Pool pool)
private readonly MemoryPoolContainer<EnhancedImageInfo> _imageInfoContaner;
private static readonly byte[] s_animattedGIF89aPattern = Encoding.ASCII.GetBytes("GIF89a");
private static readonly byte[] s_animattedGIF87aPattern = Encoding.ASCII.GetBytes("GIF87a");

//private readonly ConcurrentDictionary<string, Texture2D> _cachedSpriteSheets = new ConcurrentDictionary<string, Texture2D>();
/// <summary>
/// Retrieves the requested content from the provided Uri.
Expand Down Expand Up @@ -71,33 +72,38 @@ public IEnumerator DownloadContent(string uri, Action<byte[]> Finally, bool isRe
Finally = Finally,
Request = wr
};
this._activeDownloads.TryAdd(uri, activeDownload);
_ = this._activeDownloads.TryAdd(uri, activeDownload);

yield return wr.SendWebRequest();
if (wr.isHttpError) {
// Failed to download due to http error, don't retry
Logger.Error($"An http error occurred during request to {uri}. Aborting! {wr.error}");
activeDownload.Finally?.Invoke(new byte[0]);
this._activeDownloads.TryRemove(uri, out var d1);
yield break;
}

if (wr.isNetworkError) {
if (!isRetry) {
Logger.Error($"A network error occurred during request to {uri}. Retrying in 3 seconds... {wr.error}");
yield return new WaitForSeconds(3);
SharedCoroutineStarter.instance.StartCoroutine(this.DownloadContent(uri, Finally, true));
switch (wr.result) {
case UnityWebRequest.Result.InProgress:
Logger.Error($"Why?");
yield break;
case UnityWebRequest.Result.Success:
break;
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
if (!isRetry) {
Logger.Error($"A network error occurred during request to {uri}. Retrying in 3 seconds... {wr.error}");
yield return new WaitForSeconds(3);
_ = SharedCoroutineStarter.instance.StartCoroutine(this.DownloadContent(uri, Finally, true));
yield break;
}
activeDownload.Finally?.Invoke(new byte[0]);
_ = this._activeDownloads.TryRemove(uri, out var d2);
yield break;
case UnityWebRequest.Result.ProtocolError:
default:
// Failed to download due to http error, don't retry
Logger.Error($"An http error occurred during request to {uri}. Aborting! {wr.error}");
activeDownload.Finally?.Invoke(new byte[0]);
_ = this._activeDownloads.TryRemove(uri, out var d1);
yield break;
}
activeDownload.Finally?.Invoke(new byte[0]);
this._activeDownloads.TryRemove(uri, out var d2);
yield break;
}

var data = wr.downloadHandler.data;
activeDownload.Finally?.Invoke(data);
activeDownload.IsCompleted = true;
this._activeDownloads.TryRemove(uri, out var d3);
_ = this._activeDownloads.TryRemove(uri, out var d3);
}
}

Expand All @@ -106,7 +112,6 @@ public IEnumerator PrecacheAnimatedImage(string uri, string id, int forcedHeight
yield return this.TryCacheSingleImage(id, uri, ESCAnimationType.GIF);
}


private void SetImageHeight(ref int spriteHeight, ref int spriteWidth, int height)
{
var scale = 1.0f;
Expand Down Expand Up @@ -208,7 +213,7 @@ public IEnumerator OnSingleImageCached(byte[] bytes, string id, ESCAnimationType
ret.Width = spriteWidth;
ret.Height = spriteHeight;
ret.AnimControllerData = animControllerData;
this.CachedImageInfo.TryAdd(id, ret);
_ = this.CachedImageInfo.TryAdd(id, ret);
}
else {
this._imageInfoContaner.Despawn(ret);
Expand Down
Loading

0 comments on commit 115d8ae

Please sign in to comment.