Skip to content

Commit

Permalink
buncha stuff (also python works? i have no idea)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNTFryingPan committed Aug 8, 2022
1 parent 5c27b68 commit 09d06b5
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 43 deletions.
30 changes: 28 additions & 2 deletions build.hxp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hxp.*;
import haxe.Timer;

class Build extends Script {
public function new() {
Expand All @@ -7,14 +8,17 @@ class Build extends Script {
switch command {
case 'build':
command_build();
Log.info('Task completed.');
case 'buildall':
command_buildAll();
Log.info('Task completed.');
case 'test':
command_test();
case 'run':
command_run();
default:
command_build();
Log.info('Task completed.');
}
}

Expand All @@ -29,48 +33,63 @@ class Build extends Script {
return;
}

var hasAny = false;

if (flags.get('cpp') || flags.get('c++') || flags.get('cplusplus')) {
build_cpp();
hasAny = true;
}

if (flags.get('cs') || flags.get('csharp')) {
build_csharp();
hasAny = true;
}

if (flags.get('hl') || flags.get('hashlink')) {
build_hashlink();
hasAny = true;
}

if (flags.get('java')) {
build_java();
hasAny = true;
}

if (flags.get('node') || flags.get('js') || flags.get('nodejs')) {
build_nodejs();
hasAny = true;
}

if (flags.get('jvm')) {
build_jvm();
hasAny = true;
}

if (flags.get('neko')) {
build_neko();
hasAny = true;
}

if (flags.get('py') || flags.get('python')) {
build_python();
hasAny = true;
}

if (!hasAny) {
Log.error('No targets specified.');
}
}

function command_buildAll() {
Log.info('Building all targets');
build_cpp();
build_csharp();
build_hashlink();
build_java();
//build_nodejs(); // hxnodejs doesnt support threads
build_jvm();
build_neko();
//build_python(); // python compiles... with a syntax error...
build_python();
}

function createBaseHXML():HXML {
Expand Down Expand Up @@ -110,9 +129,11 @@ class Build extends Script {
}

function build_cpp() {
Log.info('Building C++');
var hxml = createBaseHXML();
hxml.cpp = './build/cpp/';
hxml.build();


var executablePath = './build/cpp/Main';
if (flags.get('debug')) executablePath += '-debug';
Expand All @@ -126,6 +147,7 @@ class Build extends Script {
}

function build_csharp() {
Log.info('Building C#');
var hxml = createBaseHXML();
hxml.cs = './build/csharp/';
hxml.build();
Expand All @@ -143,6 +165,7 @@ class Build extends Script {
}

function build_hashlink() {
Log.info('Building Hashlink');
var hxml = createBaseHXML();
hxml.hl = './build/hashlink/Cuttlefish.hl';
hxml.build();
Expand All @@ -153,6 +176,7 @@ class Build extends Script {
}

function build_jvm() {
Log.info('Building JVM Bytecode');
var hxml = createBaseHXML();
hxml.java = './build/jvm/';
hxml.define('jvm', true);
Expand All @@ -168,6 +192,7 @@ class Build extends Script {
}

function build_java() {
Log.info('Building Java');
var hxml = createBaseHXML();
hxml.java = './build/java/';
hxml.build();
Expand All @@ -178,6 +203,7 @@ class Build extends Script {
}

function build_neko() {
Log.info('Building Neko');
var hxml = createBaseHXML();
hxml.neko = './build/neko/Cuttlefish.n';
hxml.build();
Expand All @@ -188,7 +214,7 @@ class Build extends Script {
}

function build_python() {
Log.warn('Python does not currently work, but it does compile!');
Log.info('Building Python');
var hxml = createBaseHXML();
hxml.python = './build/python/Cuttlefish.py';
hxml.build();
Expand Down
57 changes: 50 additions & 7 deletions src/Chat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ enum HoverEvent {

class ChatComponent {
public static final LEGACY_COLOR_CHARACTER = '§';
public var isBold:Bool = false;
public var isItalic:Bool = false;
public var isUnderlined:Bool = false;
public var isStrikethrough:Bool = false;
public var isObfuscated:Bool = false;
public var usedFont:Identifier = new Identifier('minecraft', 'default');
public var usedColor:Color;
public var isBold:Null<Bool> = null;
public var isItalic:Null<Bool> = null;
public var isUnderlined:Null<Bool> = null;
public var isStrikethrough:Null<Bool> = null;
public var isObfuscated:Null<Bool> = null;
public var usedFont:Null<Identifier> = null;
public var usedColor:Null<Color> = null;
public var onInsertion:Null<String>;
public var clickEvent:Null<ClickEvent>;
public var hoverEvent:Null<HoverEvent>;
public var extras:Null<Array<ChatComponent>> = null;

public function new() {

Expand Down Expand Up @@ -118,6 +119,48 @@ class ChatComponent {
this.usedColor = col;
return this;
}

public function extra(component:ChatComponent):ChatComponent {
if (this.extras == null) this.extras = [];
this.extras.push(component);
return this;
}

public function serialize():String {
var json = '{';
if (this.isBold != null) json += '"bold":$isBold,';
if (this.isItalic != null) json += '"italic":$isItalic,';
if (this.isUnderlined != null) json += '"underlined":$isUnderlined,';
if (this.isStrikethrough != null) json += '"strikethrough":$isStrikethrough,';
if (this.isObfuscated != null) json += '"obfuscated":$isObfuscated,';
if (this.usedColor != null) json += '"color":"${ChatComponent.serializeColor(this.usedColor)}",';

return json.substr(0, json.length - 2) + '}';
}

public static function serializeColor(col:Color):String {
return switch col {
case Black: 'black';
case DarkBlue: 'dark_blue';
case DarkGreen: 'dark_green';
case DarkCyan: 'dark_aqua';
case DarkRed: 'dark_red';
case DarkPurple: 'dark_purple';
case Gold: 'gold';
case LightGray: 'gray';
case DarkGray: 'dark_gray';
case LightBlue: 'blue';
case LightGreen: 'green';
case LightCyan: 'aqua';
case LightRed: 'red';
case LightPurple: 'light_purple';
case Yellow: 'yellow';
case White: 'white';
case Reset: 'reset';
case Legacy(code): code;
case Hex(code): '#$code';
}
}
}

class StringComponent extends ChatComponent {
Expand Down
14 changes: 10 additions & 4 deletions src/Connection.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import packet.clientbound.PlayLoginPacket;
import haxe.Exception;
import haxe.io.Bytes;
import game.BlockLocation;
Expand Down Expand Up @@ -44,7 +45,7 @@ class Connection {
}

public function hasPlayer():Bool {
return player != null;
return _player != null;
}

var socketConnected = true;
Expand Down Expand Up @@ -77,7 +78,10 @@ class Connection {
trace('eof, stopping thread');
return;
} catch (e:Exception) {
trace(e.stack.toString());
Sys.stderr().writeString(e.details());
Sys.stderr().flush();
//trace('uncaught exception: ${e.toString()}');
//trace(e.details());
}
}
}
Expand Down Expand Up @@ -105,9 +109,11 @@ class Connection {
packet;
case Login:
var packet = LoginStartPacket.read(this);
this._player = new Player(Uuid.v3(packet.name, 'OfflinePlayer'), packet.name);
new LoginSuccessPacket().send(this, UUID.fromString(player.uuid), player.name);
var namespace = Bytes.ofString('OfflinePlayer').toHex();
this._player = new Player(Uuid.v3(packet.name, namespace), packet.name);
new LoginSuccessPacket().send(this, Uuid.parse(player.uuid), player.name);
state = Play;
//new PlayLoginPacket().send(this);
packet;
case Play:
null;
Expand Down
69 changes: 68 additions & 1 deletion src/NBT.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import haxe.io.Output;
import haxe.io.Input;
import haxe.io.Bytes;
import haxe.Int64;
Expand All @@ -24,9 +25,75 @@ enum Tag {
}

class NBT {
public static function writeToStream(out:Output, tag:Tag, inList=false) {
function writeName() {
out.writeInt8(tag.getParameters()[0].length);
out.writeString(tag.getParameters()[0]);
}
switch tag {
case TAG_End:
if (!inList) out.writeByte(0);
case TAG_Byte(_, data):
if (!inList) out.writeByte(1);
if (!inList) writeName();
out.writeByte(data);
case TAG_Short(_, data):
if (!inList) out.writeByte(2);
if (!inList) writeName();
out.writeInt16(data);
case TAG_Int(_, data):
if (!inList) out.writeByte(3);
if (!inList) writeName();
out.writeInt32(data);
case TAG_Long(_, data):
if (!inList) out.writeByte(4);
if (!inList) writeName();
out.writeInt64(data);
case TAG_Float(_, data):
if (!inList) out.writeByte(5);
if (!inList) writeName();
out.writeFloat(data);
case TAG_Double(_, data):
if (!inList) out.writeByte(6);
if (!inList) writeName();
out.writeDouble(data);
case TAG_Byte_Array(_, data):
if (!inList) out.writeByte(7);
if (!inList) writeName();
out.writeByte(data.length);
out.write(data);
case TAG_String(_, data):
if (!inList) out.writeByte(8);
if (!inList) writeName();
out.writeInt8(data.length);
out.writeString(data);
case TAG_List(_, data, type):
if (!inList) out.writeByte(9);
if (!inList) writeName();
out.writeByte(type);
out.writeInt32(data.length);
for (entry in data) writeToStream(out, entry, true);
case TAG_Compound(_, data):
if (!inList) out.writeByte(10);
if (!inList) writeName();
for (entry in data) writeToStream(out, entry, false);
writeToStream(out, TAG_End, false);
case TAG_Int_Array(_, data):
if (!inList) out.writeByte(11);
if (!inList) writeName();
out.writeInt32(data.length);
for (entry in data) out.writeInt32(entry);
case TAG_Long_Array(_, data):
if (!inList) out.writeByte(12);
if (!inList) writeName();
out.writeInt32(data.length);
for (entry in data) out.writeInt64(entry);
}
}

public static function readFromStream(input:Input, inList=false, ?type:Int):Tag {
var tagType = input.readByte();
var tagName;
var tagName = '';
if (!inList && tagType != 0) {
var nameLen = input.readInt8();
tagName = input.readString(nameLen);
Expand Down
13 changes: 9 additions & 4 deletions src/UUID.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class UUID {
var upper:Int64;

public function new(upper:Int64, lower:Int64) {
trace('new');
this.upper = upper;
this.lower = lower;
}
Expand Down Expand Up @@ -42,10 +43,14 @@ class UUID {
}

public static function fromString(str:String) {
var bytes = Uuid.parse(str, '');
var upper = bytes.getInt64(0);
trace('creating uuid from $str');
/*var bytes = Uuid.parse(str, '-');
trace(bytes.getData());
var upper = bytes.(0);
trace('${upper.high.hex()}${upper.low.hex()}');
var lower = bytes.getInt64(64);
trace(upper.high.hex, upper.low.hex);
return new UUID(upper, lower);
trace(lower);
//trace(upper.high.hex, upper.low.hex);
return new UUID(upper, lower);*/
}
}
5 changes: 5 additions & 0 deletions src/game/Enchantment.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package game;

class Enchantment {

}
Loading

0 comments on commit 09d06b5

Please sign in to comment.