Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Digital Logic Sim

​A minimalistic digital logic simulator · By Sebastian Lague

I added the ability to toggle snapping

A topic by HMT created Apr 13, 2025 Views: 115 Replies: 1
Viewing posts 1 to 2
(1 edit)

Just add the following line to the Update function (around line 280) in the Project.cs file in Assets\Scripts\Game\Project :

KeyboardShortcuts.Update();

and modify the KeyboardShortcuts.cs file in Assets\Scripts\Game\Interaction\ to look like this:

using Seb.Helpers;
using UnityEngine;
namespace DLS.Game
{
public static class KeyboardShortcuts
{
public static void Update()
{
            if (InputHelper.IsKeyDownThisFrame(KeyCode.RightControl))
            {
                ToggleSnapping();
                Debug.Log("Executed Toggle function");
            }
        }
public static bool SnapToGrid;
// ---- Main Menu shortcuts
public static bool MainMenu_NewProjectShortcutTriggered => CtrlShortcutTriggered(KeyCode.N);
public static bool MainMenu_OpenProjectShortcutTriggered => CtrlShortcutTriggered(KeyCode.O);
public static bool MainMenu_SettingsShortcutTriggered => CtrlShortcutTriggered(KeyCode.S);
public static bool MainMenu_QuitShortcutTriggered => CtrlShortcutTriggered(KeyCode.Q);
// ---- Bottom Bar Menu shorcuts ----
public static bool SaveShortcutTriggered => CtrlShortcutTriggered(KeyCode.S);
public static bool LibraryShortcutTriggered => CtrlShortcutTriggered(KeyCode.L);
public static bool PreferencesShortcutTriggered => CtrlShortcutTriggered(KeyCode.P);
public static bool CreateNewChipShortcutTriggered => CtrlShortcutTriggered(KeyCode.N);
public static bool QuitToMainMenuShortcutTriggered => CtrlShortcutTriggered(KeyCode.Q);
public static bool SearchShortcutTriggered => CtrlShortcutTriggered(KeyCode.Space) || CtrlShortcutTriggered(KeyCode.F);
// ---- Misc shortcuts ----
//public static bool DuplicateShortcutTriggered => MultiModeHeld && InputHelper.IsKeyDownThisFrame(KeyCode.D);
public static bool DuplicateShortcutTriggered => CtrlShortcutTriggered(KeyCode.D);
public static bool ToggleGridShortcutTriggered => CtrlShortcutTriggered(KeyCode.G);
public static bool ResetCameraShortcutTriggered => CtrlShortcutTriggered(KeyCode.R);
// ---- Single key shortcuts ----
public static bool CancelShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Escape);
public static bool ConfirmShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Return);
public static bool DeleteShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Backspace) || InputHelper.IsKeyDownThisFrame(KeyCode.Delete);
public static bool SimNextStepShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Tab);
// ---- Dev shortcuts ----
public static bool OpenSaveDataFolderShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.O) && InputHelper.CtrlIsHeld && InputHelper.ShiftIsHeld && InputHelper.AltIsHeld;
// ---- Modifiers ----
public static bool SnapModeHeld => SnapToGrid;
// In "Multi-mode", placed chips will be duplicated once placed to allow placing again; selecting a chip will add it to the current selection; etc.
public static bool MultiModeHeld => InputHelper.AltIsHeld || InputHelper.ShiftIsHeld;
public static bool StraightLineModeHeld => InputHelper.ShiftIsHeld;
public static bool StraightLineModeTriggered=> InputHelper.IsKeyDownThisFrame(KeyCode.LeftShift);
public static bool CameraActionKeyHeld => InputHelper.AltIsHeld;
public static bool TakeFirstFromCollectionModifierHeld => InputHelper.CtrlIsHeld || InputHelper.AltIsHeld || InputHelper.ShiftIsHeld;
// ---- Helpers ----
static bool CtrlShortcutTriggered(KeyCode key) => InputHelper.IsKeyDownThisFrame(key) && InputHelper.CtrlIsHeld && !(InputHelper.AltIsHeld || InputHelper.ShiftIsHeld);
static bool ShiftShortcutTriggered(KeyCode key) => InputHelper.IsKeyDownThisFrame(key) && InputHelper.ShiftIsHeld && !(InputHelper.AltIsHeld || InputHelper.CtrlIsHeld);
        public static bool ToggleSnapping()
{
            Debug.Log("Old value: " + SnapToGrid);
bool debugVar = SnapToGrid;
if (SnapToGrid == false)
{
SnapToGrid = true;
}
else
{
SnapToGrid = false;
                }
            Debug.Log("New value: " + SnapToGrid);
Debug.Log((SnapToGrid == debugVar) ? "Function unsuccessful" : "Function successful");
            return SnapToGrid;
        }
}
}

Why not make a PR for it? Sebastian might merge it. Worse case is that he might not so might as well :)