Skip to content

Reverting! ...for no reason, haha! #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 0 additions & 16 deletions data/AgcRequestCodes.properties

This file was deleted.

Binary file removed data/ExtraIcons/icon-144.png
Binary file not shown.
Binary file removed data/ExtraIcons/icon-36.png
Binary file not shown.
Binary file removed data/ExtraIcons/icon-48.png
Binary file not shown.
Binary file removed data/ExtraIcons/icon-72.png
Binary file not shown.
Binary file removed data/ExtraIcons/icon-96.png
Binary file not shown.
Binary file removed lib/udp.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.brahvim.androidgamecontroller.server;
package com.brahvim.androidgamecontroller;

class SineWave {
public class SineWave {
// #region Fields.
public float angleOffset, freqMult, freq;
public float endTime = Float.MAX_VALUE - 1, aliveTime;
Expand Down Expand Up @@ -111,8 +111,9 @@ public void extendEndByAngle(float p_angle) {
// #endregion

// #region Getters.
public float getStartTime() {
return Sketch.SKETCH.millis() - this.aliveTime;
public float getStartTime(int p_millis) {
// return Sketch.SKETCH.millis() - this.aliveTime;
return p_millis - this.aliveTime;
}

public float getTimeSinceStart() {
Expand All @@ -123,18 +124,18 @@ public float getEndTime() {
return this.endTime;
}

public float get() {
public float get(int p_frameTime) {
this.active = this.aliveTime <= this.endTime;

if (this.active)
this.aliveTime += Sketch.frameTime;
this.aliveTime += p_frameTime;
// ^^^ `frameTime` comes from "the Engine" by the way. (Hey - that's "Nerd"!)
else if (this.zeroWhenInactive)
return 0;

this.freq = this.aliveTime * this.freqMult + this.angleOffset;
return (float) Math.sin(this.freq);
// That looked like a matrix calculation LOL.
// That looks like a matrix calculation LOL.
}
// #endregion
}
46 changes: 21 additions & 25 deletions src/com/brahvim/androidgamecontroller/server/Forms.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ public static void init(UiBooster p_ui) {
Forms.ui = p_ui;
}

public static String getString(String p_key) {
String ret = StringTable.get(p_key);
if (ret == null)
System.err.printf("String table key `%s` not found!\n", p_key);
return ret;
}

// #region Form null-check methods:
public static boolean isFormOpen(Form p_form) {
// if (p_form == null)
// return false;
// else if (p_form.isClosedByUser())
// return false;
// else
// return true;
/*
* if (p_form == null)
* return false;
* else if (p_form.isClosedByUser())
* return false;
* else
* return true;
*/

return p_form == null ? false : p_form.isClosedByUser() ? false : true;
}

Expand Down Expand Up @@ -137,8 +133,8 @@ public void keyTyped(KeyEvent p_keyEvent) {
// #region Form creation...
public static WaitingDialog showFindingConnectionDialog() {
WaitingDialog ret = ui.showWaitingDialog(
Forms.getString("FindConnectionWaitBox.text"),
Forms.getString("FindConnectionWaitBox.title"));
StringTable.getString("FindConnectionWaitBox.text"),
StringTable.getString("FindConnectionWaitBox.title"));
findingDevicesDialog = ret;
return ret;
}
Expand Down Expand Up @@ -187,34 +183,34 @@ public void run() {
}

public static FormBuilder createSettingsForm() {
FormBuilder ret = ui.createForm(Forms.getString("SettingsForm.title"));
FormBuilder ret = ui.createForm(StringTable.getString("SettingsForm.title"));
WindowSetting win = ret.andWindow();
win.setSize(Forms.settingsWidth, Forms.settingsHeight);

ret.addButton(Forms.getString("SettingsForm.exitButton"), new Runnable() {
ret.addButton(StringTable.getString("SettingsForm.exitButton"), new Runnable() {
@Override
public void run() {
Sketch.agcExit();
}
});

ret.addButton(Forms.getString("SettingsForm.bansMenuButton"), new Runnable() {
ret.addButton(StringTable.getString("SettingsForm.bansMenuButton"), new Runnable() {
@Override
public void run() {
Forms.bansForm = Forms.showRichForm(Forms.bansForm, Forms.createBansForm());
}
});

ret.addSlider(Forms.getString("SettingsForm.timeoutSlider"), 2, 20, 2, 2, 0);
ret.addSlider(StringTable.getString("SettingsForm.timeoutSlider"), 2, 20, 2, 2, 0);

return Forms.settingsFormBuild = ret;
}

public static FormBuilder createBansForm() {
FormBuilder ret = Forms.ui.createForm(Forms.getString("BansForm.title"));
FormBuilder ret = Forms.ui.createForm(StringTable.getString("BansForm.title"));
ret.addLabel(Sketch.socket.bannedClients.size() == 0
? Forms.getString("BansForm.noBans")
: Forms.getString("BansForm.label"));
? StringTable.getString("BansForm.noBans")
: StringTable.getString("BansForm.label"));

/*
* for (int i = 0, max = Sketch.socket.bannedIpStrings.size(); i < max; i++) {
Expand Down Expand Up @@ -254,21 +250,21 @@ public void run() {

public static FormBuilder createUnbanForm(String p_clientName, String p_clientIp) {
FormBuilder ret = Forms.ui.createForm(
Forms.getString("UnbansForm.title")
StringTable.getString("UnbansForm.title")
.concat(" ")
.concat(p_clientName)
.concat("?"));

ret.addLabel(p_clientName.concat(" (IP: `").concat(p_clientIp).concat("`)"));

ret.addButton(Forms.getString("UnbansForm.unbanButton"), new Runnable() {
ret.addButton(StringTable.getString("UnbansForm.unbanButton"), new Runnable() {
@Override
public void run() {
Sketch.socket.unbanClient(p_clientName);
}
}).setID("btn_unban");

ret.addButton(Forms.getString("UnbansForm.permBanButton"), new Runnable() {
ret.addButton(StringTable.getString("UnbansForm.permBanButton"), new Runnable() {
@Override
public void run() {
// IP should be written to `AgcBannedClients.csv`
Expand Down
2 changes: 1 addition & 1 deletion src/com/brahvim/androidgamecontroller/server/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Sketch extends PApplet {
public static ConfigurationPacket myConfig; // The primary client's configuration.

public int bgColor = color(0, 150); // Exit fade animation, et cetera.
public static float frameStartTime, pframeTime, frameTime;
public static int frameStartTime, pframeTime, frameTime;
// #endregion

// #region Window coordinates and states.
Expand Down
23 changes: 12 additions & 11 deletions src/com/brahvim/androidgamecontroller/server/SketchWithScenes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.brahvim.androidgamecontroller.RequestCode;
import com.brahvim.androidgamecontroller.Scene;
import com.brahvim.androidgamecontroller.SineWave;
import com.brahvim.androidgamecontroller.render.ButtonRendererBase;
import com.brahvim.androidgamecontroller.render.DpadButtonRendererBase;
import com.brahvim.androidgamecontroller.render.TouchpadRendererBase;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void registerClientConfig(byte[] p_data, AgcClient p_client) {

@Override
public void setup() {
shownText = Forms.getString("AwaitingConnectionsScene.text");
shownText = StringTable.getString("AwaitingConnectionsScene.text");

/*
* // "Can you serialize enums?" YES!
Expand Down Expand Up @@ -154,11 +155,11 @@ public void confirmConnection(AgcClient p_client) {
// BlockingConfirmDialog.create(

Forms.ui.showConfirmDialog(
Forms.getString("ConfirmConnection.message")
StringTable.getString("ConfirmConnection.message")
.replace("<name>", p_client.getName())
.replace("<address>", p_client.getIp()),
// Window title:
Forms.getString("ConfirmConnection.windowTitle"),
StringTable.getString("ConfirmConnection.windowTitle"),
// If yes,
new Runnable() {
@Override
Expand All @@ -182,19 +183,19 @@ public void confirmRejection(AgcClient p_client) {
// Older stuff that used `.concat()`:
/*
* // Forms.ui.showConfirmDialog(
* // Forms.getString("RejectConnection.begin")
* // StringTable.getString("RejectConnection.begin")
* // .concat(" \"")
* // .concat(p_client.getName())
* // .concat("\" (IP: `")
* // .concat(p_client.getIp())
* // .concat("`)? "),
* // Forms.getString("RejectConnection.windowTitle"),
* // StringTable.getString("RejectConnection.windowTitle"),
*/

Forms.getString("RejectConnection.message")
StringTable.getString("RejectConnection.message")
.replace("<name>", p_client.getName()),

Forms.getString("RejectConnection.windowTitle"),
StringTable.getString("RejectConnection.windowTitle"),

new Runnable() {
@Override
Expand Down Expand Up @@ -267,7 +268,7 @@ public void run() {
Received a `%d`-byte long unrecognizzed sequence of bytes saying
\"%s\" from IP: `%s`, port: `%d`.\n""",
p_data.length, new String(p_data), p_ip, p_port);
break;
break;
}
}
};
Expand Down Expand Up @@ -461,7 +462,7 @@ public void setup() {
windowFadeWave.endWhenAngleIs(90);
windowFadeWave.start();

thankYouText = Forms.getString("ExitScene.text");
thankYouText = StringTable.getString("ExitScene.text");
socket.tellAllClients(RequestCode.SERVER_CLOSE);
socket.close();
}
Expand All @@ -476,8 +477,8 @@ public void draw() {
}

if (windowFadeWave != null) {
float wave = windowFadeWave.get();
if (wave == 0) {
float wave = windowFadeWave.get(frameTime);
if (wave == 0) { // I have no idea how, but it can and IS this perfect!
windowFadeWave.end();

while (!Forms.isFormClosed(Forms.settingsForm))
Expand Down
12 changes: 10 additions & 2 deletions src/com/brahvim/androidgamecontroller/server/StringTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ public class StringTable {
return parsedMap;
}

public static String get(String p_key) {
return StringTable.table.get(p_key);
public static synchronized String getString(String p_key) {
String ret = StringTable.table.get(p_key);

if (ret == null) {
System.err.printf("String for key `%s` not found!\n", p_key);
return "";
}

return ret;
}

}