Skip to content

Commit

Permalink
Equalization
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Nov 20, 2022
1 parent 091669c commit 1200817
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions TriviaMurderPartyModder/Files/Questions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ public class Questions : DataFile<Question> {

public Questions() : base("questions") { }

public void Equalize() {
bool wasChange = false;
for (int i = 0, c = Count; i < c; i++) {
int shouldBeCorrect = i % 4 + 1;
Question item = Items[i];
if (item.Correct != shouldBeCorrect) {
(item[item.Correct], item[shouldBeCorrect]) = (item[shouldBeCorrect], item[item.Correct]);
item.Correct = shouldBeCorrect;
wasChange = true;
}
}

// OnCollectionChanged
if (wasChange) {
Question[] changeds = this.ToArray();
Clear();
for (int i = 0; i < changeds.Length; i++) {
Add(changeds[i]);
}
}
}

protected override void Add(string fileName) {
string contents = File.ReadAllText(fileName);
int position = 0;
Expand Down
6 changes: 4 additions & 2 deletions TriviaMurderPartyModder/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
</Grid.ColumnDefinitions>
<DataGrid x:Name="questions" IsManipulationEnabled="True" PreviewKeyDown="MoveRight">
</DataGrid>
<GroupBox Grid.Column="1" Header="Data" Height="185" Margin="10,10,10,0" VerticalAlignment="Top">
<GroupBox Grid.Column="1" Header="Data" Height="210" Margin="10,10,10,0" VerticalAlignment="Top">
<Grid>
<Button Content="Import" Margin="10,10,10,0" VerticalAlignment="Top" Click="QuestionImport"/>
<Button x:Name="questionLast" Content="Import last save" Margin="10,35,10,0" VerticalAlignment="Top" Click="QuestionImportLastSave"/>
<Button Content="Merge" Margin="10,60,10,0" VerticalAlignment="Top" Click="QuestionMerge"/>
<Button Content="Save" Margin="10,85,10,0" VerticalAlignment="Top" Click="QuestionSave"/>
<Button Content="Save As..." Margin="10,110,10,0" VerticalAlignment="Top" Click="QuestionSaveAs"/>
<Button Content="Release Check" Margin="10,135,10,0" VerticalAlignment="Top" Click="QuestionReleaseCheck"/>
<Button Content="Equalize" Margin="10,160,10,0" VerticalAlignment="Top" Click="QuestionEqualize"
ToolTip="Make answers in different positions equally likely."/>
</Grid>
</GroupBox>
<GroupBox Grid.Column="1" Header="Selected question" Height="170" Margin="10,195,10,0" VerticalAlignment="Top">
<GroupBox Grid.Column="1" Header="Selected question" Height="170" Margin="10,220,10,0" VerticalAlignment="Top">
<Grid>
<GroupBox Header="Audio" Height="110" Margin="5,0,5,0" VerticalAlignment="Top">
<Grid>
Expand Down
1 change: 1 addition & 0 deletions TriviaMurderPartyModder/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void RemoveQuestionAudio(AudioType type) =>
void QuestionSave(object _, RoutedEventArgs e) => questionList.Save();
void QuestionSaveAs(object _, RoutedEventArgs e) => questionList.SaveAs();
void QuestionReleaseCheck(object _, RoutedEventArgs e) => ReleaseCheck(questionList);
void QuestionEqualize(object _, RoutedEventArgs e) => questionList.Equalize();
void QuestionAudio(object _, RoutedEventArgs e) => ImportQuestionAudio(AudioType.Q);
void QuestionIntroAudio(object _, RoutedEventArgs e) => ImportQuestionAudio(AudioType.Intro);
void RemoveIntroAudio(object _, RoutedEventArgs e) => RemoveQuestionAudio(AudioType.Intro);
Expand Down

0 comments on commit 1200817

Please sign in to comment.