Skip to content

Commit

Permalink
key info on pause, css fixes, icon
Browse files Browse the repository at this point in the history
  • Loading branch information
edeetee committed Jun 18, 2019
1 parent d5ae913 commit 21de362
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>
<form id="connect">
<a id="header" href="https://github.com/edeetee/pictocraft">Pictocraft Project Info</a>
<a id="header" href="https://github.com/edeetee/pictocraft/blob/master/README.md">What is Pictocraft?</a>
<h1>Pictocraft</h1>
<label for="key" >Key:</label>
<input type="text" maxlength="4" id="key" name="key">
Expand Down
11 changes: 6 additions & 5 deletions docs/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ body{
}

#message .material-icons{
margin: 10px;
padding: 5px 10px;
font-size: 40px;
/* font-size: 8vw; */
cursor: pointer;
Expand All @@ -35,9 +35,11 @@ body{
margin-left: auto;
}

/* #message .picto {
height: 80px;
} */
#message .picto {
width: 0;
flex-grow: 1;
max-width: 80px;
}

#input{
display: flex;
Expand Down Expand Up @@ -76,7 +78,6 @@ body{
.picto {
margin: 1%;
width: 80px;
height: 80px;
object-fit: contain;

flex-shrink: 1;
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ yarn_mappings=1.14.2+build.7
loader_version=0.4.8+build.155

# Mod Properties
mod_version = 1.0.0
maven_group = net.fabricmc
archives_base_name = mc-fabric-mod
mod_version = 0.2
maven_group = edeetee
archives_base_name = pictocraft

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
Expand Down
46 changes: 0 additions & 46 deletions package-lock.json

This file was deleted.

27 changes: 27 additions & 0 deletions src/main/java/edeetee/pictocraft/InfoRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edeetee.pictocraft;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.Font;
import net.minecraft.client.font.TextRenderer;

public class InfoRenderer {
static final TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
static final float padding = 10;
static final float scale = 1.5f;
static final String webMessage = "AAC input: https://edeetee.github.io/pictocraft/";
static final String connectedText = PictoInputReceiver.key + " - CONNECTED!";

public static void render(){
// Font
RenderUtil.push();

RenderUtil.translate(padding, padding);
renderer.draw(webMessage, 0, 0, -1);

RenderUtil.scale(scale, scale);
RenderUtil.translate(0, padding);
renderer.draw("Key: " + (PictoInputReceiver.isConnected() ? connectedText : PictoInputReceiver.key), 0, 0, -1);

RenderUtil.pop();
}
}
2 changes: 1 addition & 1 deletion src/main/java/edeetee/pictocraft/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void onInitialize() {
System.out.println("Hello Fabric world!");
ItemSearch.generateMap();

new PictoInputReciever(sentence -> {
new PictoInputReceiver(sentence -> {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if(player != null)
player.sendChatMessage(sentence);
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/edeetee/pictocraft/PictoInputReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import java.net.SocketException;
import java.util.Collections;
import java.util.Random;
import java.util.Timer;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;

class PictoInputReciever {
public class PictoInputReceiver {
//uses https://httprelay.io

static final String BaseUrl = "https://httprelay.io/link/pictocraft";
Expand All @@ -22,9 +24,16 @@ interface MessageCallback {
void gotMessage(String sentence);
}

static final String key = getKey();
public static final String key = getKey();

PictoInputReciever(MessageCallback callback) {
// static StopWatch countdown;
static Long lastMessage;
static final long timeout = 5*60*1000;
public static boolean isConnected(){
return lastMessage != null && (System.currentTimeMillis()-lastMessage) < timeout;
}

PictoInputReceiver(MessageCallback callback) {
System.out.println("INPUT KEY: " + key);

// HttpClient httpclient = HttpClients.createDefault();
Expand All @@ -40,6 +49,7 @@ public void run() {
while(true){
HttpResponse resp = HttpClients.createDefault().execute(post);
System.out.println("responded to connect request");
lastMessage = System.currentTimeMillis();
}
} catch(IOException e){
e.printStackTrace();
Expand All @@ -57,6 +67,7 @@ public void run() {
String text = PictoToText.getText(body);
System.out.println("RECEIVED: " + text);
callback.gotMessage(text);
lastMessage = System.currentTimeMillis();
}
} catch(IOException e){
e.printStackTrace();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/edeetee/pictocraft/mixin/LoginInfoMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edeetee.pictocraft.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.gui.screen.PauseScreen;
import edeetee.pictocraft.InfoRenderer;

@Mixin(PauseScreen.class)
public abstract class LoginInfoMixin {

@Inject(method = "render", at = @At("RETURN"))
public void renderInfo(int x, int y, float float_1, CallbackInfo info) {
InfoRenderer.render();
}
}
Binary file modified src/main/resources/assets/modid/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"sources": "https://github.com/edeetee/pictocraft"
},

"contact": {
"homepage": "https://github.com/edeetee/pictocraft/blob/master/README.md",
"issues": "https://github.com/edeetee/pictocraft/issues"
},

"license": "CC0-1.0",
"icon": "assets/modid/icon.png",

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/modid.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
],
"client": [
"DrawChatMixin",
"MessageMixin"
"MessageMixin",
"LoginInfoMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 21de362

Please sign in to comment.