This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Hey folks! This Gist details how to use the `check_for_nil_arguments!` method, | |
# which is available to you via including NilArgsCheckHelper into the class of | |
# your choice. | |
# | |
# Briefly, it's a shorthand for checking if any of your arguments are nil without | |
# explicitly writing out checks for each one you care about. This is especially | |
# helpful with methods that use a long list of keyword required arguments. | |
# | |
# For real usage examples, check out `bulk_label_data.rb` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Registry : MonoBehaviour { | |
// ... | |
private static Registry _instance; | |
public static Registry Instance { get { return _instance; }} | |
void Awake() { | |
if (_instance != null && _instance != this) { | |
Destroy(this.gameObject); | |
} else { | |
_instance = this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Registry : MonoBehaviour { | |
// ... | |
public static void GetNewReceiver(Transmitter transmitter) { | |
// If the controller is already controlling a receiver, we'll look for the next | |
// free receiver starting above that index. Otherwise, we'll start the search | |
// from receiver 0 | |
int transmitterIdx = Array.IndexOf(_instance.transmitterAssignments, transmitter); | |
int nextFreeIndex = NextFreeRecvIdx(transmitterIdx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Registry : MonoBehaviour { | |
// ... | |
// Receivers and transmitterAssignments indexes must be the same length. | |
// It is assumed that every element in receivers is occupied. However, it's okay | |
// if some or all of the transmitters are not occupied | |
[SerializeField] private Receiver[] receivers = new Receiver[2]; | |
private Transmitter[] transmitterAssignments = new Transmitter[2]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(PlayerInput))] | |
public class Transmitter : MonoBehaviour { | |
private Receiver receiver; | |
private PlayerInput playerInput; | |
void Start() { | |
this.playerInput = this.GetComponent<PlayerInput>(); | |
this.playerInput.enabled = true; | |
Registry.Instance.GetNewReceiver(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Transmitter : MonoBehaviour { | |
// ... | |
public void OnSwitchReceiver(InputValue inputValue) { | |
Registry.GetNewReceiver(this); | |
} | |
public void Disconnect(Receiver receiver) { | |
receiver.SendCommand("OnDisconnect"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Receiver : MonoBehaviour { | |
public Camera receiverCamera; | |
public GameObject[] listeners; | |
public void SendCommand(string cmd, object val = null) { | |
foreach (GameObject listener in listeners) { | |
listener.SendMessage(cmd, val, SendMessageOptions.DontRequireReceiver); | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /config/initializers/devise.rb | |
# Turbo doesn't work with devise by default. | |
# Keep tabs on https://github.com/heartcombo/devise/issues/5446 for a possible fix | |
# Fix from https://gorails.com/episodes/devise-hotwire-turbo | |
class TurboFailureApp < Devise::FailureApp | |
def respond | |
if request_format == :turbo_stream | |
redirect | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/turbo_devise_controller.rb | |
class TurboDeviseController < ApplicationController | |
class Responder < ActionController::Responder | |
def to_turbo_stream | |
controller.render(options.merge(formats: :html)) | |
rescue ActionView::MissingTemplate => error | |
if get? | |
raise error | |
elsif has_errors? && default_action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TurboDeviseController < ApplicationController | |
class Responder < ActionController::Responder | |
def to_turbo_stream | |
controller.render(options.merge(formats: :html)) | |
rescue ActionView::MissingTemplate => error | |
if get? | |
raise error | |
elsif has_errors? && default_action | |
render rendering_options.merge(formats: :html, status: :unprocessable_entity) | |
else |
OlderNewer