Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustdustinthewind committed Mar 7, 2020
2 parents bc077bf + 010cae5 commit 6981f9d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 104 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.3-alpha] - 2020-03-07

### Added
- Random song selection. Press F2 in the song select to choose a random song.

## [1.4.2-alpha] - 2020-03-02

### Added
Expand Down
108 changes: 22 additions & 86 deletions CODESTYLE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code Style
# Code Style

The following is a general guide of how to structure your code. When contributing to Pulsarc it is preferrable that your code follows these guidelines.

Expand All @@ -19,54 +19,22 @@ This guide is heavily inspired by [Quaver's Code Style Guide](https://github.com
### Braces
**DO** place open and closed braces on a new line.

**DO** ignore braces on single-statement blocks, unless it is to remove confusion in reading and to keep code-execution safe.
**DO NOT** ignore braces on single-statement blocks.

**Good Example**
```cs
// Braces on separate lines
if (someExpression)
{
DoSomething();
DoAnotherThing();
}
// Braces to separate the inner else-statement from the outer else-statement
else if (anotherExpression)
{
// No braces for single-statements that are easy to read.
if (yetAnotherExpression)
DoSomethingElse();
else
DoSomethingElseEntirely();
}
// No braces for single-statements
else
DoSomethingIGuess();
```
**DO NOT** use one-liners, exception for Guard Clauses.

**DO NOT** use one-liners.
**DO NOT** put braces on the same line as a expression, exception for Guard Clauses.

**DO NOT** put braces on the same line as a expression.
### Guard Clauses
**DO** use guard clauses over nested condtionals. More info [Here](https://www.refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html)

**DO NOT** be inconsistent with your brace usage.

**Bad Example:**
**Example**
```cs
// Opening Brace on same line as expression
if (someExpression) {
DoSomething();
DoAnotherThing();
}
// Inconsistent use of braces within this block
// No braces causes confusion between the inner else-statement and the outer else-statement
else if (anotherExpression)
// Doesn't need braces a single-statement instead.
if (yetAnotherExpression) {
DoSomethingElse();
// Closing brace on same line as expresssion
} else
DoSomethingElseEntirely();
// One liner
else { DoSomethingIGuess(); }
if (!condition) { return; }

...

if (!secondCondtion) { return; }
```

### Switches
Expand All @@ -86,44 +54,8 @@ switch (someExpression)
}
```

### Single Statements
**DO** ignore braces for single statement blocks following ``for``, ``foreach``, ``if``, ``do``, etc.

**DO** put the single statement on a new line and indent by four spaces.

**Good Example:**
```cs
for (int i = 0; i < 100; ++i)
DoSomething(i);

foreach (Item item in list)
UseItem(item);
```

**DO NOT** ignore braces for single statement blocks that may be confusing to understand otherwise.

If you find yourself in a position where you don't know whether to include braces or not, use them anyway.

**Bad Example:**
```cs
// This chain could be easier to read with clarifying braces.
for (int i = 0; i < 100; i++)
for (int j = 0; j < 200; j++)
if (someExpression)
if (anotherExpression)
foreach (Item item in list)
DoSomethingWeird(item, i * j);
else
{
DoSomething(j);
DoSomethingElse(i);
}
else if (yetAnotherExpression)
DoSomethingPlease(j / i);
```

### Single line Property Statements
Single line property statements can have braces that begin and end on the same line. This should only be used for simple property statements. Add a single space before and after the braces.
Single line property statements can have braces that begin and end on the same line. Add a single space before and after the braces.

**Example:**
```cs
Expand Down Expand Up @@ -242,21 +174,25 @@ for (int i=0 ; i<100 ; ++i) // Wrong
```

## `var` vs Type
**DO** use the variable type.
**DO** use the variable type in most cases.

**DO NOT** use `var`
**DO NOT** use `var`, unless the type of the var is explicitly labeled on the right side during assignment.

## Naming
camelCasing - First word all lowercase, following words initial uppercase.

PascalCasing - All words initial uppercase.

Follow all [.NET Framework Design Guidelines](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/) for both internal and external members. Highlights of these include:
ALL\_CAPS - All letters are uppercase, underscore (_) between words

* **DO NOT** use the Hungarian notation (including the type of the variable in the name)
* **DO** use camelCasing for private member variables. Underscore prefixing (e.g. ``_foo``) is allowed, but not required
* **DO** use camelCasing for other member variables
* **DO** use camelCasing for private member variables.
* **DO** use camelCasing for parameters.
* **DO** use camelCasing for local variables
* **DO** use PascalCasing for method, property, event, and class names.
* **DO** use PascalCasing for protected member variables.
* **DO** Use ALL_CAPS for static variables.
* **DO** prefix interface names with ``I``
* **DO NOT** prefix enums, classes, or delegates with any letter.

Follow the [.NET Framework Design Guidelines](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/) for anything not covered.
4 changes: 2 additions & 2 deletions Pulsarc/Pulsarc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AssemblyName>Pulsarc</AssemblyName>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<StartupObject></StartupObject>
<AssemblyVersion>1.4.2.0</AssemblyVersion>
<FileVersion>1.4.2.0</FileVersion>
<AssemblyVersion>1.4.3.0</AssemblyVersion>
<FileVersion>1.4.3.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions Pulsarc/UI/Screens/SongSelect/SongSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public override void Init()
base.Init();

RefreshBeatmaps();

SelectRandomCard();
}

/// <summary>
Expand Down Expand Up @@ -179,6 +181,20 @@ public List<Beatmap> SortBeatmaps(List<Beatmap> beatmaps, string sort, bool asce
}
}

public void SelectRandomCard()
{
if (Cards.Count <= 0) { return; }

Random rd = new Random();

FocusedCard?.SetClicked(false);

FocusedCard = Cards[rd.Next(0, Cards.Count)];
FocusedCard.OnClick();

GetSongSelectionView().FocusCard(FocusedCard);
}

public void DeleteMap(in BeatmapCard card)
{
AudioManager.Stop();
Expand Down Expand Up @@ -261,16 +277,17 @@ private void HandleKeyboardPresses()
// If the backspace is pressed, delete the last character
case Keys.Back:
// If there's nothing in the box, don't do anything
if (GetSongSelectionView().SearchBox.GetText().Length <= 0)
{
break;
}
if (GetSongSelectionView().SearchBox.GetText().Length <= 0) { break; }

// Reset the timer
RestartSearchBoxKeyPressTimer = true;

GetSongSelectionView().SearchBox.DeleteLastCharacter();
break;
// If the random key is pressed, choose a random song
case Keys.F2:
SelectRandomCard();
break;
// If none of the above, type into the search bar
// TODO? Ignore keypresses unless clicked on
default:
Expand Down
17 changes: 5 additions & 12 deletions Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ public SongSelectionView(Screen screen, List<Beatmap> beatmaps, string search =
cards.Add(new BeatmapCard(beatmaps[i], i));
}

// Select a random map by default in the song selection.
if (cards.Count > 0)
{
Random rd = new Random();

songSelectScreen.FocusedCard = cards[rd.Next(0, cards.Count)];
songSelectScreen.FocusedCard.OnClick();
FocusCard(songSelectScreen.FocusedCard);
}

Anchor searchBoxAnchor = GetSkinnablePropertyAnchor("SearchBarAnchor");
Vector2 searchBarStartPosition = Skin.GetConfigStartPosition("song_select", "Properties", "SearchBarStartPos");

Expand Down Expand Up @@ -252,13 +242,16 @@ public override void Update(GameTime gameTime)
if (Math.Round(currentFocus, 2) != Math.Round(songSelectScreen.SelectedFocus, 2))
{
currentFocus = PulsarcMath.Lerp(
currentFocus, songSelectScreen.SelectedFocus, (float)PulsarcTime.DeltaTime / 100f);
currentFocus, songSelectScreen.SelectedFocus,
(float)PulsarcTime.DeltaTime / 100f);

float diff = lastFocus - currentFocus;
lastFocus = currentFocus;

for (int i = 0; i < cards.Count; i++)
{
cards[i].Move(new Vector2(0, BeatmapCard.TotalHeight * diff));
}
}

// Go back if the back button was clicked.
Expand Down

0 comments on commit 6981f9d

Please sign in to comment.