Skip to content

Commit

Permalink
style: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Sep 30, 2024
1 parent d508880 commit ae100c5
Show file tree
Hide file tree
Showing 16 changed files with 926 additions and 920 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,96 +6,97 @@

namespace Xsolla.Core.Browser
{
internal class Display2DBehaviour : MonoBehaviour
{
private IXsollaBrowserRender xsollaRender;
public RawImage renderImage;

public Vector2Int CurrentRenderSize { get; private set; }

public event Action<int, int> ViewportChangedEvent;
public event Action RedrawFrameCompleteEvent;
public event Action FirstRedrawFrameCompleteEvent;

private IEnumerator Start()
{
if (!GetComponentInParent<Canvas>())
{
XDebug.LogError("Canvas not found. This browser for 2D project.");
Destroy(gameObject);
yield break;
}

renderImage = gameObject.GetComponent<RawImage>();
SetOpacity(0);

yield return new WaitWhile(() => !GetComponent<XsollaBrowser>());
var xsollaBrowser = GetComponent<XsollaBrowser>();

yield return new WaitWhile(() => xsollaBrowser.Render == null);
xsollaRender = xsollaBrowser.Render;
}

private void OnDestroy()
{
StopRedraw();
}

public void StartRedraw(int width, int height)
{
if (xsollaRender == null)
return;

StopRedraw();
xsollaRender.SetResolution(width, height, OnRenderResolutionChanged);
}

private void StopRedraw()
{
if (xsollaRender != null)
StopAllCoroutines();
}

private void SetOpacity(float opacity)
{
if (renderImage == null)
return;

var color = renderImage.color;
color.a = opacity;
renderImage.color = color;
}

private void OnRenderResolutionChanged(int width, int height)
{
CurrentRenderSize = new Vector2Int(width, height);
ViewportChangedEvent?.Invoke(width, height);
StartCoroutine(RedrawCoroutine());
}

private IEnumerator RedrawCoroutine()
{
var isFirstRedraw = true;
while (enabled)
{
yield return ActionExtensions.WaitMethod<Texture2D>(
xsollaRender.To,
texture => {
if (renderImage != null && texture != null)
{
SetOpacity(1.0f);
renderImage.texture = texture;
}
RedrawFrameCompleteEvent?.Invoke();
if (isFirstRedraw)
{
FirstRedrawFrameCompleteEvent?.Invoke();
isFirstRedraw = false;
}
});
}
}
}
internal class Display2DBehaviour : MonoBehaviour
{
private IXsollaBrowserRender xsollaRender;
public RawImage renderImage;

public Vector2Int CurrentRenderSize { get; private set; }

public event Action<int, int> ViewportChangedEvent;
public event Action RedrawFrameCompleteEvent;
public event Action FirstRedrawFrameCompleteEvent;

private IEnumerator Start()
{
if (!GetComponentInParent<Canvas>())
{
XDebug.LogError("Canvas not found. This browser for 2D project.");
Destroy(gameObject);
yield break;
}

renderImage = gameObject.GetComponent<RawImage>();
SetOpacity(0);

yield return new WaitWhile(() => !GetComponent<XsollaBrowser>());
var xsollaBrowser = GetComponent<XsollaBrowser>();

yield return new WaitWhile(() => xsollaBrowser.Render == null);
xsollaRender = xsollaBrowser.Render;
}

private void OnDestroy()
{
StopRedraw();
}

public void StartRedraw(int width, int height)
{
if (xsollaRender == null)
return;

StopRedraw();
xsollaRender.SetResolution(width, height, OnRenderResolutionChanged);
}

private void StopRedraw()
{
if (xsollaRender != null)
StopAllCoroutines();
}

private void SetOpacity(float opacity)
{
if (renderImage == null)
return;

var color = renderImage.color;
color.a = opacity;
renderImage.color = color;
}

private void OnRenderResolutionChanged(int width, int height)
{
CurrentRenderSize = new Vector2Int(width, height);
ViewportChangedEvent?.Invoke(width, height);
StartCoroutine(RedrawCoroutine());
}

private IEnumerator RedrawCoroutine()
{
var isFirstRedraw = true;
while (enabled)
{
yield return ActionExtensions.WaitMethod<Texture2D>(
xsollaRender.To,
texture =>
{
if (renderImage != null && texture != null)
{
SetOpacity(1.0f);
renderImage.texture = texture;
}
RedrawFrameCompleteEvent?.Invoke();
if (isFirstRedraw)
{
FirstRedrawFrameCompleteEvent?.Invoke();
isFirstRedraw = false;
}
});
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,83 @@

namespace Xsolla.Core.Browser
{
internal class Keyboard2DBehaviour : MonoBehaviour
{
private IXsollaBrowserKeyboardInput keyboardInput;
internal class Keyboard2DBehaviour : MonoBehaviour
{
private IXsollaBrowserKeyboardInput keyboardInput;

public event Action EscapePressed;
public event Action EscapePressed;

private static readonly List<KeyCode> SystemKeys = new List<KeyCode> {
KeyCode.Escape
};
private static readonly List<KeyCode> SystemKeys = new List<KeyCode> {
KeyCode.Escape
};

// @formatter:off
private static readonly Dictionary<KeyCode, string> ModificationKeys = new Dictionary<KeyCode, string>{
{KeyCode.LeftShift, "Shift"},
{KeyCode.RightShift, "Shift"},
{KeyCode.LeftAlt, "Alt"},
{KeyCode.RightAlt, "Alt"},
{KeyCode.LeftControl, "Control"},
{KeyCode.RightControl, "Control"}
};

private static readonly Dictionary<KeyCode, string> NumpadKeys = new Dictionary<KeyCode, string>{
{KeyCode.Keypad0, "Digit0"},
{KeyCode.Keypad1, "Digit1"},
{KeyCode.Keypad2, "Digit2"},
{KeyCode.Keypad3, "Digit3"},
{KeyCode.Keypad4, "Digit4"},
{KeyCode.Keypad5, "Digit5"},
{KeyCode.Keypad6, "Digit6"},
{KeyCode.Keypad7, "Digit7"},
{KeyCode.Keypad8, "Digit8"},
{KeyCode.Keypad9, "Digit9"}
};
// @formatter:on
// @formatter:off
private static readonly Dictionary<KeyCode, string> ModificationKeys = new Dictionary<KeyCode, string>{
{KeyCode.LeftShift, "Shift"},
{KeyCode.RightShift, "Shift"},
{KeyCode.LeftAlt, "Alt"},
{KeyCode.RightAlt, "Alt"},
{KeyCode.LeftControl, "Control"},
{KeyCode.RightControl, "Control"}
};

private static readonly List<KeyCode> AllKeyCodes = Enum.GetValues(typeof(KeyCode)).OfType<KeyCode>()
.Where(key => key < KeyCode.Mouse0)
.Except(SystemKeys)
.Except(ModificationKeys.Keys)
.Except(NumpadKeys.Keys)
.ToList();
private static readonly Dictionary<KeyCode, string> NumpadKeys = new Dictionary<KeyCode, string>{
{KeyCode.Keypad0, "Digit0"},
{KeyCode.Keypad1, "Digit1"},
{KeyCode.Keypad2, "Digit2"},
{KeyCode.Keypad3, "Digit3"},
{KeyCode.Keypad4, "Digit4"},
{KeyCode.Keypad5, "Digit5"},
{KeyCode.Keypad6, "Digit6"},
{KeyCode.Keypad7, "Digit7"},
{KeyCode.Keypad8, "Digit8"},
{KeyCode.Keypad9, "Digit9"}
};
// @formatter:on

private void Awake()
{
keyboardInput = GetComponent<XsollaBrowser>().Input.Keyboard;
}
private static readonly List<KeyCode> AllKeyCodes = Enum.GetValues(typeof(KeyCode)).OfType<KeyCode>()
.Where(key => key < KeyCode.Mouse0)
.Except(SystemKeys)
.Except(ModificationKeys.Keys)
.Except(NumpadKeys.Keys)
.ToList();

private void Update()
{
if (InputProxy.GetKeyUp(KeyCode.Escape))
{
EscapePressed?.Invoke();
}
private void Awake()
{
keyboardInput = GetComponent<XsollaBrowser>().Input.Keyboard;
}

foreach (var pair in ModificationKeys)
{
if (InputProxy.GetKeyDown(pair.Key))
keyboardInput.KeyDown(pair.Value);
private void Update()
{
if (InputProxy.GetKeyUp(KeyCode.Escape))
{
EscapePressed?.Invoke();
}

if (InputProxy.GetKeyUp(pair.Key))
keyboardInput.KeyUp(pair.Value);
}
foreach (var pair in ModificationKeys)
{
if (InputProxy.GetKeyDown(pair.Key))
keyboardInput.KeyDown(pair.Value);

foreach (var pair in NumpadKeys)
{
if (InputProxy.GetKeyDown(pair.Key))
keyboardInput.PressKey(pair.Value);
}
if (InputProxy.GetKeyUp(pair.Key))
keyboardInput.KeyUp(pair.Value);
}

AllKeyCodes.ForEach(code =>
{
if (InputProxy.GetKeyDown(code))
{
var key = KeysConverter.Convert(code);
keyboardInput.PressKey(key);
}
});
}
}
foreach (var pair in NumpadKeys)
{
if (InputProxy.GetKeyDown(pair.Key))
keyboardInput.PressKey(pair.Value);
}

AllKeyCodes.ForEach(code =>
{
if (InputProxy.GetKeyDown(code))
{
var key = KeysConverter.Convert(code);
keyboardInput.PressKey(key);
}
});
}
}
}
#endif
Loading

0 comments on commit ae100c5

Please sign in to comment.