Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@

# Visual Studio cache directory
.vs/
.vscode/
bin/

# Gradle cache directory
.gradle/


# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
Expand Down
2 changes: 1 addition & 1 deletion Assets/Build/DLS.unity
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
openSaveDirectory: 0
openInMainMenu: 0
openInMainMenu: 1
testProjectName: MainTest
openA: 1
chipToOpenA: BuzzTest
Expand Down
31 changes: 16 additions & 15 deletions Assets/Scripts/DLS.asmdef
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "DLS",
"rootNamespace": "",
"references": [
"GUID:d4f8eab5cdd4a544c9923829818c11c0",
"GUID:2b65bcfb6aad3f1459e94b356ff58293"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
"name": "DLS",
"rootNamespace": "",
"references": [
"Assembly-Seb",
"DLS.Description",
"DLSModdingAPI"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
3 changes: 2 additions & 1 deletion Assets/Scripts/Description/Helpers/ChipTypeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace DLS.Description
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public static class ChipTypeHelper
{ ChipType.Bus_8Bit, "BUS-8" },
{ ChipType.BusTerminus_1Bit, "BUS-TERMINUS-1" },
{ ChipType.BusTerminus_4Bit, "BUS-TERMINUS-4" },
{ ChipType.BusTerminus_8Bit, "BUS-TERMINUS-8" }
{ ChipType.BusTerminus_8Bit, "BUS-TERMINUS-8" },
};

public static string GetName(ChipType type) => Names[type];
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Description/Types/ChipDescription.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace DLS.Description
Expand All @@ -11,6 +12,7 @@ public class ChipDescription

// ---- Data ----
public string DLSVersion;
public List<string> DependsOnModIDs = new();
public string Name;
public NameDisplayLocation NameLocation;
public ChipType ChipType;
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Description/Types/ProjectDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class ChipCollection
[JsonIgnore] string displayName_open;
public bool IsToggledOpen;
public string Name;
public List<string> DependsOnModIDs = new();

public ChipCollection(string name, params string[] chips)
{
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace DLS.Description
public enum ChipType
{
Custom,
Modded,

// ---- Basic Chips ----
Nand,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;

namespace DLS.Description
Expand All @@ -9,12 +10,14 @@ public struct DisplayDescription
public int SubChipID;
public Vector2 Position;
public float Scale;
public List<string> DependsOnModIDs;

public DisplayDescription(int subChipID, Vector2 position, float scale)
{
SubChipID = subChipID;
Position = position;
Scale = scale;
DependsOnModIDs = new();
}
}
}
10 changes: 10 additions & 0 deletions Assets/Scripts/Description/Types/SubTypes/PinDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public PinDescription(string name, int id, Vector2 position, PinBitCount bitCoun
Colour = colour;
ValueDisplayMode = valueDisplayMode;
}

public PinDescription(string name, int id)
{
Name = name;
ID = id;
Position = Vector2.zero;
BitCount = PinBitCount.Bit1;
Colour = PinColour.Red;
ValueDisplayMode = PinValueDisplayMode.Off;
}
}

public enum PinBitCount
Expand Down
10 changes: 6 additions & 4 deletions Assets/Scripts/Game/Elements/SubChipInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ static List<DisplayInstance> CreateDisplayInstances(ChipDescription chipDesc)

static DisplayInstance CreateDisplayInstance(DisplayDescription displayDesc, ChipDescription chipDesc)
{
DisplayInstance instance = new();
instance.Desc = displayDesc;
instance.DisplayType = chipDesc.ChipType;
DisplayInstance instance = new()
{
Desc = displayDesc,
DisplayType = chipDesc.ChipType
};

if (chipDesc.ChipType == ChipType.Custom)
if (chipDesc.ChipType == ChipType.Custom)
{
ChipDescription childDesc = GetDescriptionOfDisplayedSubChip(chipDesc, displayDesc.SubChipID);
instance.ChildDisplays = CreateDisplayInstances(childDesc);
Expand Down
57 changes: 53 additions & 4 deletions Assets/Scripts/Game/Interaction/ChipInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
using System.Linq;
using DLS.Description;
using DLS.Graphics;
using DLS.ModdingAPI;
using DLS.Mods;
using DLS.SaveSystem;
using Seb.Helpers;
using UnityEngine;
using PinBitCount = DLS.Description.PinBitCount;
using PinDescription = DLS.Description.PinDescription;

namespace DLS.Game
{
Expand Down Expand Up @@ -239,9 +243,25 @@ void HandleMouseInput()
if (HasControl) UpdatePositionsToMouse();

// --- Mouse button input ---
if (InputHelper.IsMouseDownThisFrame(MouseButton.Left)) HandleLeftMouseDown();
if (InputHelper.IsMouseDownThisFrame(MouseButton.Left))
{
ModLoader.NotifyMods((mod, args) => mod.OnMouseClick(args), new IMod.InputEventArgs
{
Position = InputHelper.MousePosWorld,
Button = IMod.MouseButton.Left
});
HandleLeftMouseDown();
}
if (InputHelper.IsMouseUpThisFrame(MouseButton.Left)) HandleLeftMouseUp();
if (InputHelper.IsMouseDownThisFrame(MouseButton.Right)) HandleRightMouseDown();
if (InputHelper.IsMouseDownThisFrame(MouseButton.Right))
{
ModLoader.NotifyMods((mod, args) => mod.OnMouseClick(args), new IMod.InputEventArgs
{
Position = InputHelper.MousePosWorld,
Button = IMod.MouseButton.Right
});
HandleRightMouseDown();
}

// Shift + scroll to increase vertical spacing between elements when placing multiple at a time
// (disabled if elements were duplicated since then we want to preserve relative positions)
Expand Down Expand Up @@ -565,7 +585,16 @@ void FinishMovingElements()
return;
}

hasMoved |= (element.MoveStartPosition != element.Position);
hasMoved |= element.MoveStartPosition != element.Position;

if (hasMoved)
{
ModLoader.NotifyMods((mod, args) => mod.OnMoveChip(args, element.Position), new IMod.ChipEventArgs
{
ChipName = element is SubChipInstance subchip ? subchip.Description.Name : string.Empty,
Position = element.MoveStartPosition
});
}
}

if (hasMoved) ActiveDevChip.UndoController.RecordMoveElements(SelectedElements);
Expand Down Expand Up @@ -598,8 +627,16 @@ void FinishPlacingNewElements()
if (elementToPlace is SubChipInstance subchip)
{
ActiveDevChip.AddNewSubChip(subchip, false);
ModLoader.NotifyMods((mod, args) => mod.OnPlaceChip(args), new IMod.ChipEventArgs
{
ChipName = subchip.Description.Name,
Position = subchip.Position
});
}
else if (elementToPlace is DevPinInstance devPin)
{
ActiveDevChip.AddNewDevPin(devPin, false);
}
else if (elementToPlace is DevPinInstance devPin) ActiveDevChip.AddNewDevPin(devPin, false);
}

foreach (WireInstance wire in DuplicatedWires)
Expand Down Expand Up @@ -630,6 +667,12 @@ void ExitWireEditMode()
if (wireToEdit != null && isMovingWireEditPoint)
{
wireToEdit.SetWirePoint(wireEditPointOld, wireEditPointSelectedIndex);
ModLoader.NotifyMods((mod, args) => mod.OnEditWire(args), new IMod.WireEventArgs
{
SourcePinName = wireToEdit.SourcePin.Name,
TargetPinName = wireToEdit.TargetPin.Name,
BitCount = (int) wireToEdit.bitCount
});
}

wireToEdit = null;
Expand Down Expand Up @@ -841,6 +884,12 @@ void CompleteConnection(WireInstance.ConnectionInfo info)
WireToPlace.FinishPlacingWire(info);
ActiveDevChip.AddWire(WireToPlace, false);
ActiveDevChip.UndoController.RecordAddWire(WireToPlace);
ModLoader.NotifyMods((mod, args) => mod.OnPlaceWire(args), new IMod.WireEventArgs
{
SourcePinName = WireToPlace.SourcePin.Name,
TargetPinName = WireToPlace.TargetPin.Name,
BitCount = (int) WireToPlace.bitCount
});
}
}

Expand Down
17 changes: 17 additions & 0 deletions Assets/Scripts/Game/Interaction/KeyboardShortcuts.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using DLS.ModdingAPI;
using Seb.Helpers;
using UnityEngine;

Expand Down Expand Up @@ -51,5 +53,20 @@ public static class KeyboardShortcuts
static bool CtrlShortcutTriggered(KeyCode key) => InputHelper.IsKeyDownThisFrame(key) && InputHelper.CtrlIsHeld && !(InputHelper.AltIsHeld || InputHelper.ShiftIsHeld);
static bool CtrlShiftShortcutTriggered(KeyCode key) => InputHelper.IsKeyDownThisFrame(key) && InputHelper.CtrlIsHeld && InputHelper.ShiftIsHeld && !(InputHelper.AltIsHeld);
static bool ShiftShortcutTriggered(KeyCode key) => InputHelper.IsKeyDownThisFrame(key) && InputHelper.ShiftIsHeld && !(InputHelper.AltIsHeld || InputHelper.CtrlIsHeld);

// ---- Modded shortcuts ----
public static bool GetModdedShortcut(string shortcutName)
{
if (Registry.ModdedShortcuts.TryGetValue(shortcutName, out var shortcut))
{
bool keyTriggered = InputHelper.IsKeyDownThisFrame(shortcut.Key);
bool modifierConditionMet = shortcut.ModifierCondition?.Invoke() ?? true;

return keyTriggered && modifierConditionMet;
}

Debug.LogWarning($"Shortcut '{shortcutName}' is not registered.");
return false;
}
}
}
4 changes: 4 additions & 0 deletions Assets/Scripts/Game/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using DLS.Description;
using DLS.Graphics;
using DLS.Mods;
using DLS.SaveSystem;
using UnityEngine;

Expand All @@ -24,6 +25,8 @@ public static class Main
public static void Init(AudioState audioState)
{
SavePaths.EnsureDirectoryExists(SavePaths.ProjectsPath);
SavePaths.EnsureDirectoryExists(SavePaths.ModsPath);
ModLoader.InitializeMods(SavePaths.ModsPath);
SaveAndApplyAppSettings(Loader.LoadAppSettings());
Main.audioState = audioState;
}
Expand Down Expand Up @@ -68,6 +71,7 @@ public static void CreateOrLoadProject(string projectName, string startupChipNam
else ActiveProject = CreateProject(projectName);

ActiveProject.LoadDevChipOrCreateNewIfDoesntExist(startupChipName);

ActiveProject.StartSimulation();
ActiveProject.audioState = audioState;
UIDrawer.SetActiveMenu(UIDrawer.MenuType.None);
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Game/Project/BuiltinChipCreator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DLS.Description;
using UnityEngine;
using static DLS.Graphics.DrawSettings;
Expand Down Expand Up @@ -55,6 +56,8 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
};
}



static ChipDescription CreateNand()
{
Color col = new(0.73f, 0.26f, 0.26f);
Expand Down
Loading