Skip to content

Commit

Permalink
Adding Warp.World integration which can be setup and enabled from Set…
Browse files Browse the repository at this point in the history
…tings > Warp World Settings
  • Loading branch information
underscore-zi committed Aug 8, 2019
1 parent 0eed8c2 commit 206b2ae
Show file tree
Hide file tree
Showing 12 changed files with 678 additions and 41 deletions.
9 changes: 9 additions & 0 deletions MarioMaker2OCR/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
<setting name="NewVersionWarning" serializeAs="String">
<value>0.0.0</value>
</setting>
<setting name="WarpWorldUsername" serializeAs="String">
<value />
</setting>
<setting name="WarpWorldToken" serializeAs="String">
<value />
</setting>
<setting name="WarpWorldEnabled" serializeAs="String">
<value>False</value>
</setting>
</MarioMaker2OCR.Properties.Settings>
<WebcamOCR.Properties.Settings>
<setting name="OutputFolder" serializeAs="String">
Expand Down
103 changes: 63 additions & 40 deletions MarioMaker2OCR/Form1.Designer.cs

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions MarioMaker2OCR/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public string CurrentVersion
public Size SelectedResolution => (resolutionsCombobox.SelectedItem as dynamic)?.Value;

private FormPreview previewer = new FormPreview();
private FormWarpWorld warpworldForm = new FormWarpWorld();
private WarpWorldAPI WarpWorld;
private VideoProcessor processor;

private string jsonOutputFolder = "";
Expand Down Expand Up @@ -200,6 +202,14 @@ private void startButton_Click(object sender, EventArgs e)
log.Info(string.Format("Start Web Server on http://localhost:{0}/", SMMServer.port));
SMMServer.Start();

if (Properties.Settings.Default.WarpWorldEnabled)
{
WarpWorld = new WarpWorldAPI(Properties.Settings.Default.WarpWorldUsername, Properties.Settings.Default.WarpWorldToken);
} else
{
WarpWorld = null;
}

processor = new VideoProcessor(deviceComboBox.SelectedIndex, SelectedResolution);
processor.BlackScreen += VideoProcessor_BlackScreen;
processor.ClearScreen += VideoProcessor_ClearScreen;
Expand Down Expand Up @@ -302,6 +312,11 @@ private void VideoProcessor_ClearScreen(object sender, VideoProcessor.VideoEvent
}
}

if (Properties.Settings.Default.WarpWorldEnabled)
{
WarpWorld?.win();
}

// Read time from screen
string clearTime = OCRLibrary.GetClearTimeFromFrame(e.currentFrame);
SMMServer.BroadcastDataEvent("clear", clearTime);
Expand Down Expand Up @@ -375,6 +390,12 @@ private void VideoProcessor_BlackScreen(object sender, VideoProcessor.BlackScree
{
log.Info(String.Format("Detected {0} [{1}].", evt.Key, e.seconds));
SMMServer.BroadcastEvent(evt.Key);

// Even though this will get sent on exiting after a clear, it only matters if a entry is active, and after marking it as a win it goes inactive.
if(evt.Key == "exit" && Properties.Settings.Default.WarpWorldEnabled)
{
WarpWorld?.lose();
}
}
}
}
Expand Down Expand Up @@ -524,5 +545,15 @@ private void checkLatestVersion()
log.Error(e.Message);
}
}

private void WarpWorldSettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (warpworldForm.IsDisposed)
{
warpworldForm = new FormWarpWorld();
}
warpworldForm.Show();
warpworldForm.BringToFront();
}
}
}
143 changes: 143 additions & 0 deletions MarioMaker2OCR/FormWarpWorld.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions MarioMaker2OCR/FormWarpWorld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MarioMaker2OCR
{
public partial class FormWarpWorld : Form
{
public FormWarpWorld()
{
InitializeComponent();
txtUsername.Text = Properties.Settings.Default.WarpWorldUsername;
txtToken.Text = Properties.Settings.Default.WarpWorldToken;
txtWarpBarURL.Text = String.Format("https://warp.world/warpbar-queue?streamer={0}&key={1}", txtUsername.Text, txtToken.Text);
chkWarpWorld.Checked = Properties.Settings.Default.WarpWorldEnabled;

if(!chkWarpWorld.Checked)
{
txtWarpBarURL.Enabled = false;
}
}

private void TxtWarpBarURL_TextChanged(object sender, EventArgs e)
{
if (txtWarpBarURL.Text.Contains("streamer="))
{
txtUsername.Text = txtWarpBarURL.Text.Split(new String[] { "streamer=" }, StringSplitOptions.None)[1].Split('&')[0];
}

if (txtWarpBarURL.Text.Contains("key="))
{
txtToken.Text = txtWarpBarURL.Text.Split(new String[] { "key=" }, StringSplitOptions.None)[1].Split('&')[0];
}

// Possible the token size will change, but its a good validation for now
if(txtUsername.TextLength > 2 && txtToken.TextLength == 16)
{
Properties.Settings.Default.WarpWorldUsername = txtUsername.Text;
Properties.Settings.Default.WarpWorldToken = txtToken.Text;
Properties.Settings.Default.Save();

}
}

private void ChkWarpWorld_CheckedChanged(object sender, EventArgs e)
{
txtWarpBarURL.Enabled = chkWarpWorld.Checked;
Properties.Settings.Default.WarpWorldEnabled = chkWarpWorld.Checked;
Properties.Settings.Default.Save();
}
}
}
Loading

0 comments on commit 206b2ae

Please sign in to comment.