Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDK UI project #18

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e6db48f
Squashed 'MDK-SE/' content from commit 4817233
kristian-softtech Apr 29, 2019
d348c56
Merge commit 'e6db48fe401a681bb8c2e961b50a8924bb3e312d' as 'MDK-SE'
kristian-softtech Apr 29, 2019
451afad
Created MDK-UI.
kristian-softtech Apr 29, 2019
c982ab4
Merged master into mockup-ui
kristian-softtech Apr 29, 2019
edb8638
Work in progress.
kristian-softtech May 2, 2019
6281467
Merge branch 'master' into mockup-ui
kristian-softtech May 3, 2019
d9e5b73
Merge branch 'master' into mockup-ui
kristian-softtech May 3, 2019
a7c54e2
Fixed another broken Debugger attribute.
kristian-softtech May 3, 2019
3880cac
Merge branch 'master' into mockup-ui
kristian-softtech May 3, 2019
f0f3cf9
Merge branch 'master' into mockup-ui
kristian-softtech May 3, 2019
1f05f14
Add files via upload
kwilliams1987 May 3, 2019
7be68a1
Merge pull request #1 from kwilliams1987/master
kwilliams1987 May 3, 2019
7a44d33
Update README.md
kwilliams1987 May 3, 2019
619bc68
Started framework for code based template and runtime event handling.
kristian-softtech May 3, 2019
58d4166
Merge branch 'mockup-ui' of https://github.com/kwilliams1987/MDK-Mock…
kristian-softtech May 3, 2019
17e06ef
Reorganise files.
kristian-softtech May 3, 2019
f29a6c4
- Started implementing runtime emulation.
kristian-softtech May 3, 2019
54109f9
Removed unnecessary usings.
kristian-softtech May 6, 2019
b78c939
Merge branch 'master' of https://github.com/malware-dev/MDK-Mockups i…
kristian-softtech May 6, 2019
e1d7158
Merge pull request #14 from kwilliams1987/mockup-ui
kwilliams1987 May 6, 2019
6e86d83
Update Getting-Started-Contribute.md
kwilliams1987 May 8, 2019
d489d2f
Update Getting-Started-Contribute.md
kwilliams1987 May 8, 2019
0d96b72
Update Getting-Started-Contribute.md
kwilliams1987 May 8, 2019
c885f6d
Create Example-Mock-Class.md
kwilliams1987 May 8, 2019
9675d36
Update Getting-Started-Contribute.md
kwilliams1987 May 8, 2019
5eef267
Updated existing mocks to match contribution guidelines.
kristian-softtech May 8, 2019
d95e665
Initial presentation UI implementation.
kristian-softtech May 13, 2019
84b5d8e
Removed unnecessary usings.
kristian-softtech May 13, 2019
20a501c
- Implemented metadata as part of MDK-Mockups project.
kristian-softtech May 14, 2019
bd10f1f
- Marked several text panel methods as obsolete.
kristian-softtech May 15, 2019
061f3a5
Grouped `IMyTextSurface` proxy methods.
kristian-softtech May 15, 2019
bb0c593
Merge pull request #19 from malware-dev/mockup-ui-presentation
kwilliams1987 May 15, 2019
a466e5b
Added default SpaceEngineers.paths.props file.
kristian-softtech May 15, 2019
3ae618a
Implemented `INotifyPropertyChanged` to most mocked terminal blocks.
kristian-softtech May 20, 2019
47900fb
Finished implementing INotifyPropertyChanged on existing mocked blocks.
kristian-softtech May 20, 2019
35557f2
Optimised the property changed event handler a bit.
kristian-softtech May 23, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ _vti_pvt/
#Ignore private folder
/Private/
/Source/UpgradeLog.htm
/MDK-UI/SpaceEngineers.paths.props
Binary file added Docs/Assets/mdk-ui.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions Docs/Example-Metadata-Class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Here is an example template for decorating a mocked ingame block.

```cs
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using IngameScript.Mockups.Base;
using Sandbox.ModAPI.Interfaces;
using SpaceEngineers.Game.ModAPI.Ingame;

namespace IngameScript.Mockups.Blocks
{
#if !MOCKUP_DEBUG
[System.Diagnostics.DebuggerNonUserCode]
#endif
// Decorate the class with a DisplayName attribute to have it visible in the block picker.
[DisplayName("Air Vent")]
public partial class MockAirVent : MockFunctionalBlock, IMyAirVent
{
// Decorate a property with a DisplayName attribute to have it visible in the block details screen.
// Add Range and ReadOnly attributes when appropriate to control how the property is rendered.
[DisplayName("Oxygen Level"), Range(0, 1)]
public virtual float OxygenLevel { get; set; } = 0;

[DisplayName("Can Pressurize")]
public virtual bool CanPressurize { get; set; } = true;

[DisplayName("Is Depressurizing"), ReadOnly(true)]
public virtual bool IsDepressurizing => Enabled && (Status == VentStatus.Depressurizing || Status == VentStatus.Depressurized);

[DisplayName("De-pressurize")]
public virtual bool Depressurize { get; set; } = false;

[DisplayName("Status")]
public virtual VentStatus Status { get; set; }

public virtual bool PressurizationEnabled { get; } = true;

protected override IEnumerable<ITerminalProperty> CreateTerminalProperties()
{
return base.CreateTerminalProperties().Concat(new[]
{
new MockTerminalProperty<IMyAirVent, bool>("Depressurize", b => b.Depressurize, (b, v) => b.Depressurize = v)
});
}

// Decorate methods with a DisplayName attribute to add them to the list of actions in the block details screen.
[DisplayName("Get Oxygen Level")]
public virtual float GetOxygenLevel() => OxygenLevel;

public virtual bool IsPressurized() => PressurizationEnabled && (Status == VentStatus.Pressurized || Status == VentStatus.Pressurizing);
}
}
```

Additional things to consider:
* Space Engineers only supports C# 6.0, do not use any language features from higher versions (the TestScript will help confirm this).
* Do not create `private` properties unless they are only required for your specific implementation, these classes should be easily extendable.
62 changes: 62 additions & 0 deletions Docs/Example-Mock-Class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Here is an example template for mocking an ingame block.

```cs
// Usings outside the namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IngameScript.Mockups.Base;
using Sandbox.ModAPI.Interfaces;
using SpaceEngineers.Game.ModAPI.Ingame;

// Always implement with this namespace.
namespace IngameScript.Mockups.Blocks
{
// Always include this conditional (to allow testing with the TestScript project
#if !MOCKUP_DEBUG
// Force step through for users including the shared project.
[System.Diagnostics.DebuggerNonUserCode]
#endif
// Always declare as public and partial.
// Extend from MockFunctionalBlock if the interface implements IMyFunctionalBlock, otherwise extend from MockTerminalBlock
public partial class MockAirVent : MockFunctionalBlock, IMyAirVent
{
// Implement in-game default values where possible.
// Mark properties as virtual for MDK-UI overrides.
public virtual float OxygenLevel { get; set; } = 0;

public virtual bool CanPressurize { get; set; } = true;

// Implement sensible auto-compute values where possible.
// Mark these as virtual for MDK-UI overrides.
public virtual bool IsDepressurizing => Enabled && (Status == VentStatus.Depressurizing || Status == VentStatus.Depressurized);

public virtual bool Depressurize { get; set; } = false;

public virtual VentStatus Status { get; set; }

// Implement in-game default values for properties when possible.
public bool PressurizationEnabled { get; } = true;

// Implement an override of CreateTerminalProperties() to include the extra properties exposed by the legacy GetProperties() method.
protected override IEnumerable<ITerminalProperty> CreateTerminalProperties()
{
return base.CreateTerminalProperties().Concat(new[]
{
new MockTerminalProperty<IMyAirVent, bool>("Depressurize", b => b.Depressurize, (b, v) => b.Depressurize = v)
});
}

// Implement public backing properties for methods to allow mocking of return values.
// Mark custom methods as virtual in case MDK-UI needs to override them.
public virtual float GetOxygenLevel() => OxygenLevel;

public virtual bool IsPressurized() => PressurizationEnabled && (Status == VentStatus.Pressurized || Status == VentStatus.Pressurizing);
}
}
```

Additional things to consider:
* Space Engineers only supports C# 6.0, do not use any language features from higher versions (the TestScript will help confirm this).
* Do not create `private` properties unless they are only required for your specific implementation, these classes should be easily extendable.
68 changes: 59 additions & 9 deletions Docs/Getting-Started-Contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## Overview

* [Downloading The Repository](#downloading-the-repository)
* [Rules and Etiquette](#rules-and-etiquette)

* [Rules and Etiquette: General](#rules-and-etiquette-general)
* [Rules and Etiquette: MDK Mockups](#rules-and-etiquette-mdk-mockups)
* [Rules and Etiquette: MDK UI](#rules-and-etiquette-mdk-ui)
* [None Version-Controlled Configuration](#none-version-controlled-configuration)



Expand All @@ -18,16 +20,64 @@ Once you've made a change you wish to share, you will need to [create a pull req




## Rules and Etiquette

* _All_ `.cs` files **must** end with the suffix `.debug.cs`, not just `.cs`. This is so MDK can exclude these files when deploying a script.
* All mockup classes should be _public_.
* Do not make your mockups work via nonstandard behavior. It should replicate game behavior or not at all.
* While there's **no requirement** to completely finish every single feature of a block, please make sure the parts you _do not_ include throws `NotImplementedException`. Obviously, the more you complete before creating your pull request, the better.
## Rules and Etiquette: General
* It's considered courteous to follow the coding standards. There is a risk that your pull request might be rejected if it deviates too far from the standards.
* Everything is open for contribution, including this documentation. This is the reason it's stored directly in the repository rather than the wiki. The better documentation, the easier for people to get started, the more people we get contributing.
* Make sure your contributions do not break something. If it does, and you think your change is important, make contact with one of the project administrators - either via the Issues or via Keen's Discord, and argue your case.
* Make sure your contributions are flexible. Others may want to expand on it.
* Comment your contributions (documentation comments is fair enough) and make sure your code is readable.
* **This project relies on cooperation.** It will fall apart if we do not, so we will not tolerate bad behavior.



## Rules and Etiquette: MDK-Mockups

* In-game scripts are locked to C# 6.0. Do not use features from newer versions, even if your IDE is recommending you do so.
* _All_ `.cs` files **must** end with the suffix `.debug.cs`, not just `.cs`. This is so MDK can exclude these files when deploying a script.
* All mockup classes should be _public_ and _partial_.
* All mockup classes should be decorated with the following:
* This will allow debuggers to interact with them the same as they would native game implementations.
```cs
#if !MOCKUP_DEBUG
[System.Diagnostics.DebuggerNonUserCode]
#endif
```
* Mockup properties and methods should _virtual_ whenever possible.
* Do not make your mockups work via nonstandard behavior. It should replicate game behavior or not at all.
* While there's **no requirement** to completely finish every single feature of a block, please make sure the parts you _do not_ include throws `NotImplementedException`. Obviously, the more you complete before creating your pull request, the better.

* Example mock implementation. [MockAirVent.cs](Example-Mock-Class.md)


## Rules and Etiquette: MDK-UI

* To implement editable property support to a Mocked block, the block type must be decorated with the `DisplayNameAttribute`.
* Editable properties must also be decorated with the `DisplayNameAttribute`.
* Properties which are locked between two values must be decorated with the `RangeAttribute`.
* Properties which are not editable must be decorated with the `ReadOnlyAttribute`.
* To implement methods which are executable via the interface should be decorate with a `DisplayNameAttribute`.
* Methods which accept arguments are not yet supported.
* Methods which return a value are output to a MessageBox.
* MDK-UI specific code must be part of the MDK-UI project, and not implemented within MDK-Mockups
* Mockups should be implemented by creating a new _partial_ component and implementing the new functionality.
* Mockup classes which support realtime runtime updates (such as doors and lights) must implement the `IMockupRuntimeProvider` interface.
* If a mockup's existing implementation must be changed to facilty UI interaction (for example by replacing an already mocked method), the mockup class should be marked with the `[MockOverridden]` attribute and a sub-class created.


* Example metadata implementation. [MockAirVentMetadata.cs](Example-Metadata-Class.md)


### None Version-Controlled Configuration

The MDK-UI project has a none-version controlled file `SpaceEngineers.paths.prop` which must be manually included for the project to build.

Here is the default template for a standard game install, be sure to modify the directory if you have the game installed elsewhere.

```
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SpaceEngineersGameBin>c:\program files (x86)\steam\SteamApps\common\SpaceEngineers\Bin64</SpaceEngineersGameBin>
</PropertyGroup>
</Project>
```
1 change: 1 addition & 0 deletions MDK-Mockups.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Mockups\Base\MockTextSurface.consts.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\Blocks\MockMotorRotor.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\Blocks\MockMotorStator.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\MockBlockGroup.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\MockTerminalProperty.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\Asserts\AssertionException.debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mockups\Asserts\Assert.debug.cs" />
Expand Down
15 changes: 15 additions & 0 deletions MDK-Mockups.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestScript", "TestScript\Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataExtractor", "DataExtractor\DataExtractor.csproj", "{E55E7DF9-048F-4B6A-8D1B-231011AD8461}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDK-UI", "MDK-UI\MDK-UI.csproj", "{31426581-B705-4B88-B3C9-64F3C5D9BF95}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SteamAndSE", "MDK-SE\Source\SteamAndSE\SteamAndSE.shproj", "{9E28967B-803C-4CF2-9A9C-B8135C85266B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
MDK-Mockups.projitems*{31426581-b705-4b88-b3c9-64f3c5d9bf95}*SharedItemsImports = 4
MDK-SE\Source\SteamAndSE\SteamAndSE.projitems*{31426581-b705-4b88-b3c9-64f3c5d9bf95}*SharedItemsImports = 4
MDK-Mockups.projitems*{33863c91-80f6-4abc-a735-3934a61d494c}*SharedItemsImports = 13
MDK-SE\Source\SteamAndSE\SteamAndSE.projitems*{9e28967b-803c-4cf2-9a9c-b8135c85266b}*SharedItemsImports = 13
MDK-Mockups.projitems*{a89397ec-fbe6-47e0-8651-c45b0a4e8a24}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -36,6 +43,14 @@ Global
{E55E7DF9-048F-4B6A-8D1B-231011AD8461}.Release|Any CPU.Build.0 = Release|Any CPU
{E55E7DF9-048F-4B6A-8D1B-231011AD8461}.Release|x64.ActiveCfg = Release|Any CPU
{E55E7DF9-048F-4B6A-8D1B-231011AD8461}.Release|x64.Build.0 = Release|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Debug|x64.ActiveCfg = Debug|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Debug|x64.Build.0 = Debug|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Release|Any CPU.Build.0 = Release|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Release|x64.ActiveCfg = Release|Any CPU
{31426581-B705-4B88-B3C9-64F3C5D9BF95}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
63 changes: 63 additions & 0 deletions MDK-SE/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
Loading