Skip to content

Commit

Permalink
Merge pull request #8 from Kersoph/p2_develop
Browse files Browse the repository at this point in the history
P2-Develop: Implemented Emergency System Lesson
  • Loading branch information
Kersoph authored Aug 4, 2021
2 parents 7354c5b + c22ffc7 commit 2b82f2d
Show file tree
Hide file tree
Showing 80 changed files with 1,887 additions and 363 deletions.
2 changes: 1 addition & 1 deletion data/core/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Godot;
using System;


namespace Osls
{
Expand Down
38 changes: 7 additions & 31 deletions data/core/scene_manager/navigation_steps/NavigationSteps.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Godot;
using Godot.Collections;


namespace Osls.Navigation
Expand All @@ -25,15 +26,15 @@ public override void _Ready()
{
_mainNode = GetNode<MainNode>("..");
_landingPageButton = GetNode<Button>("LandingPageButton");
_landingPageButton.Connect("toggled", this, nameof(LandingPageButtonToggled));
_landingPageButton.Connect("toggled", this, nameof(UpdateButtonState), new Array { PageCategory.LandingPage });
_sfcStepButton = GetNode<Button>("SfcStepButton");
_sfcStepButton.Connect("toggled", this, nameof(SfcStepButtonToggled));
_sfcStepButton.Connect("toggled", this, nameof(UpdateButtonState), new Array { PageCategory.LogicEditor });
_simulationStepButton = GetNode<Button>("SimulationStepButton");
_simulationStepButton.Connect("toggled", this, nameof(SimulationStepButtonToggled));
_simulationStepButton.Connect("toggled", this, nameof(UpdateButtonState), new Array { PageCategory.Simulation });
_examinationStepButton = GetNode<Button>("ExaminationStepButton");
_examinationStepButton.Connect("toggled", this, nameof(ExaminationStepButtonToggled));
_examinationStepButton.Connect("toggled", this, nameof(UpdateButtonState), new Array { PageCategory.Examination });
_exitButton = GetNode<Button>("ExitButton");
_exitButton.Connect("toggled", this, nameof(ExitButtonToggled));
_exitButton.Connect("toggled", this, nameof(UpdateButtonState), new Array { PageCategory.Exit });
}

/// <summary>
Expand All @@ -55,32 +56,7 @@ public void VisibleViewIs(PageCategory view)


#region ==================== Helpers ====================
private void LandingPageButtonToggled(bool pressed)
{
UpdateButtonState(_landingPageButton, PageCategory.LandingPage, pressed);
}

private void SfcStepButtonToggled(bool pressed)
{
UpdateButtonState(_sfcStepButton, PageCategory.LogicEditor, pressed);
}

private void SimulationStepButtonToggled(bool pressed)
{
UpdateButtonState(_simulationStepButton, PageCategory.Simulation, pressed);
}

private void ExaminationStepButtonToggled(bool pressed)
{
UpdateButtonState(_examinationStepButton, PageCategory.Examination, pressed);
}

private void ExitButtonToggled(bool pressed)
{
UpdateButtonState(_exitButton, PageCategory.Exit, pressed);
}

private void UpdateButtonState(Button button, PageCategory pages, bool pressed)
private void UpdateButtonState(bool pressed, PageCategory pages)
{
if (pressed)
{
Expand Down
8 changes: 5 additions & 3 deletions data/diagram_models/sfc/data/ActionEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class ActionEntity
/// </summary>
public static ActionEntity CreateFrom(System.IO.BinaryReader reader)
{
ActionEntity entity = new ActionEntity();
entity.Qualifier = (ActionQualifier)reader.ReadInt32();
entity.Action = reader.ReadString();
ActionEntity entity = new ActionEntity
{
Qualifier = (ActionQualifier)reader.ReadInt32(),
Action = reader.ReadString()
};
return entity;
}

Expand Down
10 changes: 7 additions & 3 deletions data/diagram_models/sfc/editor/2d_editor/Sfc2dEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Sfc2dEditorControl
{
#region ==================== Fields Properties ====================
private readonly Dictionary<int, SfcPatchControl> _controlMap = new Dictionary<int, SfcPatchControl>();
private bool _isEditable;
private readonly bool _isEditable;

/// <summary>
/// Returns the patch control map
Expand Down Expand Up @@ -118,7 +118,7 @@ private void InitialiseFromData()
IReadOnlyCollection<PatchEntity> patches = Data.SfcEntity.Patches;
foreach (PatchEntity entity in patches)
{
SfcPatchControl control = new SfcPatchControl(entity, this, !_isEditable);
SfcPatchControl control = new SfcPatchControl(entity, this, _isEditable);
_controlMap.Add(entity.Key, control);
}
UpdateGrid();
Expand Down Expand Up @@ -150,9 +150,13 @@ private void UpdateLogicalModel()
private void EnsureNeighbours(PatchEntity patchData)
{
EnsurePatchAt(patchData.X + 1, patchData.Y);
EnsurePatchAt(patchData.X + 1, patchData.Y + 1);
EnsurePatchAt(patchData.X, patchData.Y + 1);
EnsurePatchAt(patchData.X - 1, patchData.Y + 1);
EnsurePatchAt(patchData.X - 1, patchData.Y);
EnsurePatchAt(patchData.X - 1, patchData.Y - 1);
EnsurePatchAt(patchData.X, patchData.Y - 1);
EnsurePatchAt(patchData.X + 1, patchData.Y - 1);
}

/// <summary>
Expand All @@ -165,7 +169,7 @@ private void EnsurePatchAt(int x, int y)
{
Data.SfcEntity.CreatePatchAt((short)x, (short)y);
patch = Data.SfcEntity.Lookup(x, y);
SfcPatchControl control = new SfcPatchControl(patch, this, !_isEditable);
SfcPatchControl control = new SfcPatchControl(patch, this, _isEditable);
_controlMap.Add(patch.Key, control);
}
}
Expand Down
9 changes: 6 additions & 3 deletions data/diagram_models/sfc/editor/2d_editor/Sfc2dEditorNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Sfc2dEditorNode : Control
{
#region ==================== Fields Properties ====================
private ReferenceRect _renderViewportReferenceRect;
private int _zoomLevel = 2;
private static readonly float[] zoomLevels = new float[] { 0.5f, 0.7f, 1f, 1.5f, 2f, 3f };
private int _zoomLevel = 1;
private static readonly float[] zoomLevels = new float[] { 0.5f, 1f, 1.5f, 2f, 3f };
private bool _isDragging;
private Vector2 _lastDragPosition;

Expand Down Expand Up @@ -136,12 +136,15 @@ public void StopDrag()
#region ==================== Helpers ====================
private void ApplyDiagramScale(Vector2 scale)
{
Vector2 oldPosition = _renderViewportReferenceRect.RectPosition;
Vector2 oldScale = _renderViewportReferenceRect.RectScale;
_renderViewportReferenceRect.RectScale = scale;
ApplyDiagramOffset(new Vector2((oldPosition.x * scale.x) / oldScale.x, (oldPosition.y * scale.y) / oldScale.y));
}

private void ApplyDiagramOffset(Vector2 position)
{
_renderViewportReferenceRect.SetPosition(position);
_renderViewportReferenceRect.RectPosition = position;
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ namespace Osls.SfcEditor
public class ActionEditorBox : Control
{
#region ==================== Fields / Properties ====================
private const string _editorScenePath = "res://data/diagram_models/sfc/editor/2d_editor/sfc_patch/elements/ActionEditor.tscn";
private const string EditorScenePath = "res://data/diagram_models/sfc/editor/2d_editor/sfc_patch/elements/ActionEditor.tscn";

private SfcPatchControl _patchController;
private readonly List<ActionEditor> _actionEditors = new List<ActionEditor>();
private bool _isEditable;
#endregion


#region ==================== Public Methods ====================
public override void _Ready()
/// <summary>
/// Called only once when the node is created by the patch node.
/// </summary>
public void InitializeWith(SfcPatchControl sfcPatchControl, bool isEditable)
{
_patchController = GetNode<SfcPatchNode>("..").SfcPatchControl;
_patchController = sfcPatchControl;
_isEditable = isEditable;
}

/// <summary>
Expand All @@ -31,13 +36,14 @@ public void UpdateActions(PatchEntity entity, IProcessingData context)
if (i >= _actionEditors.Count) AddActionEditor(context);
_actionEditors[i].UpdateAction(entity.ActionEntries[i], context);
}

if (entity.ActionEntries.Count >= _actionEditors.Count) AddActionEditor(context);
_actionEditors[entity.ActionEntries.Count].ResetAction();

for (int i = entity.ActionEntries.Count + 1; i < _actionEditors.Count; i++)
if (_isEditable)
{
RemoveActionEditor(_actionEditors[i]);
if (entity.ActionEntries.Count >= _actionEditors.Count) AddActionEditor(context);
_actionEditors[entity.ActionEntries.Count].ResetAction();
for (int i = entity.ActionEntries.Count + 1; i < _actionEditors.Count; i++)
{
RemoveActionEditor(_actionEditors[i]);
}
}
}

Expand Down Expand Up @@ -88,7 +94,7 @@ private void UpdateVisibility(PatchEntity entity)

private void AddActionEditor(IProcessingData data)
{
Node node = ((PackedScene)GD.Load(_editorScenePath)).Instance();
Node node = ((PackedScene)GD.Load(EditorScenePath)).Instance();
ActionEditor actionEditor = (ActionEditor)node;
_actionEditors.Add(actionEditor);
GetNode<BoxContainer>("ScrollContainer/VerticalBoxContainer").AddChild(actionEditor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public class SfcActionEntity
/// </summary>
public static SfcActionEntity CreateFrom(System.IO.BinaryReader reader)
{
SfcActionEntity entity = new SfcActionEntity();
entity.Qualifier = (ActionQualifier)reader.ReadInt32();
entity.Action = reader.ReadString();
SfcActionEntity entity = new SfcActionEntity
{
Qualifier = (ActionQualifier)reader.ReadInt32(),
Action = reader.ReadString()
};
return entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public class SfcPatchControl
/// <summary>
/// Constructor. It will add the patch to the 2d editor.
/// </summary>
public SfcPatchControl(PatchEntity data, Sfc2dEditorControl control, bool setMouseFilter)
public SfcPatchControl(PatchEntity data, Sfc2dEditorControl control, bool isEditable)
{
Data = data;
Master = control;
SfcPatchMeta = new SfcPatchMeta();
Node node = ((PackedScene)GD.Load(_patchReferencePath)).Instance();
SfcPatchNode = (SfcPatchNode)node;
SfcPatchNode.InitializeWith(this, data, setMouseFilter);
SfcPatchNode.InitializeWith(this, data, isEditable);
control.ReferenceRect.AddChild(SfcPatchNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Osls.SfcEditor
{
/// <summary>
/// Entity calss to store the informations for a SFC patch
/// Entity class to store the informations for a SFC patch
/// </summary>
public class SfcPatchEntity
{
Expand Down Expand Up @@ -37,14 +37,14 @@ public class SfcPatchEntity
public SfcBranchLineType LowerBranch { get; set; }
/// <summary>
/// The raw condition text when the transition should fire.
/// It is interpreted and formed to a logical model. (Can be invaild)
/// It is interpreted and formed to a logical model. (Can be invalid)
/// </summary>
public string TransitionText { get; set; }
/// <summary>
/// Contains the action entries for the step in this patch.
/// </summary>
public List<SfcActionEntity> ActionEntries { get; private set; }
#endregion;
#endregion


#region ==================== Public ====================
Expand Down Expand Up @@ -94,12 +94,14 @@ public static SfcPatchEntity CreateFrom(System.IO.BinaryReader reader)
{
int x = reader.ReadInt32();
int y = reader.ReadInt32();
SfcPatchEntity entity = new SfcPatchEntity(x, y);
entity.SfcStepType = (SfcStepType)reader.ReadInt32();
entity.StepName = reader.ReadString();
entity.UpperBranch = (SfcBranchLineType)reader.ReadInt32();
entity.LowerBranch = (SfcBranchLineType)reader.ReadInt32();
entity.TransitionText = reader.ReadString();
SfcPatchEntity entity = new SfcPatchEntity(x, y)
{
SfcStepType = (SfcStepType)reader.ReadInt32(),
StepName = reader.ReadString(),
UpperBranch = (SfcBranchLineType)reader.ReadInt32(),
LowerBranch = (SfcBranchLineType)reader.ReadInt32(),
TransitionText = reader.ReadString()
};
int entryCount = reader.ReadInt32();
for (int i = 0; i < entryCount; i++)
{
Expand Down Expand Up @@ -149,7 +151,7 @@ public enum SfcStepType
/// </summary>
StartingStep,
/// <summary>
/// This step cell is a jump, connectiong it to another cell.
/// This step cell is a jump, connecting it to another cell.
/// </summary>
Jump
}
Expand All @@ -165,7 +167,7 @@ public enum SfcBranchLineType
/// </summary>
Single,
/// <summary>
/// This branch line is used as a aprallel branch/merge
/// This branch line is used as a parallel branch/merge
/// </summary>
Double,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ public class SfcPatchNode : ReferenceRect
/// <summary>
/// Called only once when the node is created by the patch control.
/// </summary>
public void InitializeWith(SfcPatchControl sfcPatchControl, PatchEntity data, bool setMouseFilter)
public void InitializeWith(SfcPatchControl sfcPatchControl, PatchEntity data, bool isEditable)
{
SfcPatchControl = sfcPatchControl;
SetCellPosition(data.X, data.Y);
GetNode<SfcTransitionNode>("SfcTransition").Initialise();
GetNode<ActionEditorBox>("ActionEditorBox").InitializeWith(SfcPatchControl, isEditable);
Connect("mouse_entered", this, nameof(OnMouseEntered));
Connect("mouse_exited", this, nameof(OnMouseExited));
GetNode<Control>("MouseFilterEdit").Visible = setMouseFilter;
GetNode<Control>("MouseFilterEdit").Visible = !isEditable;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ anti_aliasing = false

[node name="ActionEditor" type="Control"]
anchor_right = 1.0
margin_right = 0.0
margin_bottom = 30.0
rect_min_size = Vector2( 200, 30 )
script = ExtResource( 1 )
Expand All @@ -47,7 +46,6 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 30.0
margin_top = 2.0
margin_right = 0.0
rect_min_size = Vector2( 0, 28 )
custom_styles/focus = SubResource( 2 )
custom_styles/normal = SubResource( 3 )
Expand Down Expand Up @@ -80,3 +78,6 @@ custom_colors/font_color_pressed = Color( 0, 0, 0, 1 )
shortcut_in_tooltip = false
text = "N"
flat = false
__meta__ = {
"_edit_use_anchors_": false
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=true
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
Expand Down
Loading

0 comments on commit 2b82f2d

Please sign in to comment.