Skip to content

Commit 80b1bfd

Browse files
committed
Parsed a start request!
1 parent 445c81e commit 80b1bfd

18 files changed

+1456
-12
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
src/*.cs
3+
src/Model/*.cs
4+
src/Network/*.cs

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python3 ~/Vale/release-unix/valec.py build atharia atharia:src rocketvale:~/RocketVale/src rocketvale:~/RocketVale/src/native/rust/target/debug/librocketvale.a valejson:~/ValeJSON/src stdlib:~/stdlib/src parseiter:~/ParseIter/src --output-dir build --add-exports-include-path --region-override resilient-v3

src/EditorServer.vale

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import stdlib.*;
2+
import rocketvale.*;
3+
import valejson.*;
4+
import stdlib.stringutils.*;
5+
6+
7+
struct Response {
8+
builder StringBuilder;
9+
}
10+
11+
fn jsonToNode(s StrSlice) Result<JsonNode, str> {
12+
iter = ParseIter(s, false);
13+
node_result = parseJson(&!iter);
14+
if (node_result.is_err()) {
15+
ret node_result;
16+
}
17+
if (iter.rest != "".slice()) {
18+
ret Err<JsonNode, str>("Still text at end of input: " + iter.rest);
19+
}
20+
ret node_result;
21+
}
22+
23+
struct StartRequest {
24+
screen_gw int;
25+
screen_gh int;
26+
}
27+
28+
fn handleStartRequest(response &!Response, start_request &StartRequest) Result<[], str> {
29+
response.builder!.print(
30+
"Starting game! screen_gw {start_request.screen_gw} screen_gh {start_request.screen_gh}");
31+
ret Ok<[], str>([]);
32+
}
33+
34+
fn expect_obj_member_str(obj &JsonObject, field_name StrSlice) Result<str, str> {
35+
maybe_request_type_node = obj.fields.get(field_name);
36+
if (maybe_request_type_node.isEmpty()) {
37+
ret Err<str, str>("Missing '{field_name}' field!");
38+
}
39+
request_type_node = maybe_request_type_node.get();
40+
maybe_request_type_str = request_type_node.as<JsonString>();
41+
if (maybe_request_type_str.is_err()) {
42+
ret Err<str, str>("Expected '{field_name}' field to be a string!");
43+
}
44+
ret Ok<str, str>(maybe_request_type_str.expect().value);
45+
}
46+
47+
fn expect_obj_member_int(obj &JsonObject, field_name StrSlice) Result<int, str> {
48+
maybe_request_type_node = obj.fields.get(field_name);
49+
if (maybe_request_type_node.isEmpty()) {
50+
ret Err<int, str>("Missing '{field_name}' field!");
51+
}
52+
request_type_node = maybe_request_type_node.get();
53+
maybe_request_type_str = request_type_node.as<JsonNumber>();
54+
if (maybe_request_type_str.is_err()) {
55+
ret Err<int, str>("Expected '{field_name}' field to be a number!");
56+
}
57+
ret Ok<int, str>(maybe_request_type_str.expect().value);
58+
}
59+
60+
fn handleRequest(response &!Response, node &JsonObject) Result<[], str> {
61+
maybe_request_type_str = expect_obj_member_str(node, "request".slice());
62+
if (maybe_request_type_str.is_err()) {
63+
ret Err<[], str>(maybe_request_type_str.expect_err());
64+
}
65+
request_type_str = maybe_request_type_str.expect();
66+
67+
if (request_type_str == "start") {
68+
maybe_screen_gw = expect_obj_member_int(node, "screenGW".slice());
69+
if (maybe_screen_gw.is_err()) {
70+
ret Err<[], str>(maybe_screen_gw.expect_err());
71+
}
72+
screen_gw = maybe_screen_gw.expect();
73+
74+
maybe_screen_gh = expect_obj_member_int(node, "screenGW".slice());
75+
if (maybe_screen_gh.is_err()) {
76+
ret Err<[], str>(maybe_screen_gh.expect_err());
77+
}
78+
screen_gh = maybe_screen_gh.expect();
79+
80+
request = StartRequest(screen_gw, screen_gh);
81+
ret handleStartRequest(response, &request);
82+
} else {
83+
ret Err<[], str>("Unknown request type: " + request_type_str);
84+
}
85+
}
86+
87+
struct MyRequestHandler {
88+
counter! int;
89+
}
90+
impl IRequestHandler for MyRequestHandler;
91+
fn handle(self &!MyRequestHandler impl IRequestHandler, request_path str, request_json str) str {
92+
maybe_request_root_node = jsonToNode(request_json.slice());
93+
if (maybe_request_root_node.is_err()) {
94+
ret "Couldn't parse request: " + maybe_request_root_node.expect_err();
95+
}
96+
request_root_node = (maybe_request_root_node).expect();
97+
98+
maybe_request_root_obj = request_root_node.as<JsonObject>();
99+
if (maybe_request_root_obj.is_err()) {
100+
ret "Request wasn't json object!";
101+
}
102+
request_root_obj = maybe_request_root_obj.expect();
103+
104+
response = Response(StringBuilder(List<StrSlice>()));
105+
result = handleRequest(&!response, &request_root_obj);
106+
107+
set self.counter = self.counter + 1;
108+
109+
if (result.is_ok()) {
110+
ret "Response: " + response.builder.assembleStr();
111+
} else {
112+
ret "Error: " + result.expect_err();
113+
}
114+
}
115+
116+
fn main() export {
117+
runServer(&MyRequestHandler(0));
118+
}

src/Model/InitialSymbol.vale

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// public enum OutlineMode {
2+
// NoOutline = 0,
3+
// OuterOutline = 1,
4+
// CenteredOutline = 2
5+
// }
6+
7+
fn NoOutline() int { 0 }
8+
fn OuterOutline() int { 1 }
9+
fn CenteredOutline() int { 2 }
10+
11+
12+
struct InitialSymbolGlyph imm {
13+
symbolId SymbolId;
14+
color IVec4iAnimation;
15+
}
16+
17+
struct InitialSymbolOutline imm {
18+
mode OutlineMode;
19+
color IVec4iAnimation;
20+
}
21+
22+
struct InitialSymbolSides imm {
23+
depthPercent int;
24+
color IVec4iAnimation;
25+
}
26+
27+
struct InitialSymbol imm {
28+
glyph InitialSymbolGlyph;
29+
outline InitialSymbolOutline;
30+
sides InitialSymbolSides;
31+
rotationDegrees int;
32+
sizePercent int;
33+
}

src/Model/InitialTile.vale

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
struct InitialTile imm {
3+
// elevationStepHeight float;
4+
// tileRotationDegrees float;
5+
// depth int; // basically elevation
6+
location Location;
7+
elevation int;
8+
topColor IVec4iAnimation;
9+
sideColor IVec4iAnimation;
10+
maybeOverlaySymbol InitialSymbol;
11+
maybeFeatureSymbol InitialSymbol;
12+
itemIdToSymbol List<(ulong, InitialSymbol)>;
13+
}

src/Model/InitialUnit.vale

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
struct InitialUnit {
3+
location Location;
4+
dominoSymbol InitialSymbol;
5+
faceSymbol InitialSymbol;
6+
idToDetailSymbol ImmList<[ulong, InitialSymbol]>;
7+
hpRatio float;
8+
mpRatio float;
9+
}

src/Model/Location.vale

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
struct Location imm {
3+
groupX int;
4+
groupY int;
5+
indexInGroup int;
6+
}
7+
8+
// using System;
9+
// using System.Collections;
10+
11+
// using System.Collections.Generic;
12+
13+
// namespace Geomancer.Model {
14+
// public class Location : IComparable<Location> {
15+
// public static readonly string NAME = "Location";
16+
// public class EqualityComparer : IEqualityComparer<Location> {
17+
// public bool Equals(Location a, Location b) {
18+
// return a.Equals(b);
19+
// }
20+
// public int GetHashCode(Location a) {
21+
// return a.GetDeterministicHashCode();
22+
// }
23+
// }
24+
// public class Comparer : IComparer<Location> {
25+
// public int Compare(Location a, Location b) {
26+
// return a.CompareTo(b);
27+
// }
28+
// }
29+
// private readonly int hashCode;
30+
// public readonly int groupX;
31+
// public readonly int groupY;
32+
// public readonly int indexInGroup;
33+
// public Location(
34+
// int groupX,
35+
// int groupY,
36+
// int indexInGroup) {
37+
// this.groupX = groupX;
38+
// this.groupY = groupY;
39+
// this.indexInGroup = indexInGroup;
40+
// int hash = 0;
41+
// hash = hash * 37 + groupX;
42+
// hash = hash * 37 + groupY;
43+
// hash = hash * 37 + indexInGroup;
44+
// this.hashCode = hash;
45+
46+
// }
47+
// public static bool operator==(Location a, Location b) {
48+
// if (object.ReferenceEquals(a, null))
49+
// return object.ReferenceEquals(b, null);
50+
// return a.Equals(b);
51+
// }
52+
// public static bool operator!=(Location a, Location b) {
53+
// if (object.ReferenceEquals(a, null))
54+
// return !object.ReferenceEquals(b, null);
55+
// return !a.Equals(b);
56+
// }
57+
// public override bool Equals(object obj) {
58+
// if (obj == null) {
59+
// return false;
60+
// }
61+
// if (!(obj is Location)) {
62+
// return false;
63+
// }
64+
// var that = obj as Location;
65+
// return true
66+
// && groupX.Equals(that.groupX)
67+
// && groupY.Equals(that.groupY)
68+
// && indexInGroup.Equals(that.indexInGroup)
69+
// ;
70+
// }
71+
// public override int GetHashCode() {
72+
// return GetDeterministicHashCode();
73+
// }
74+
// public int GetDeterministicHashCode() { return hashCode; }
75+
// public int CompareTo(Location that) {
76+
// if (groupX != that.groupX) {
77+
// return groupX.CompareTo(that.groupX);
78+
// }
79+
// if (groupY != that.groupY) {
80+
// return groupY.CompareTo(that.groupY);
81+
// }
82+
// if (indexInGroup != that.indexInGroup) {
83+
// return indexInGroup.CompareTo(that.indexInGroup);
84+
// }
85+
// return 0;
86+
// }
87+
// public override string ToString() { return DStr(); }
88+
// public string DStr() {
89+
// return "Location(" +
90+
// groupX + ", " +
91+
// groupY + ", " +
92+
// indexInGroup
93+
// + ")";
94+
95+
// }
96+
// public static Location Parse(ParseSource source) {
97+
// source.Expect(NAME);
98+
// source.Expect("(");
99+
// var groupX = source.ParseInt();
100+
// source.Expect(",");
101+
// var groupY = source.ParseInt();
102+
// source.Expect(",");
103+
// var indexInGroup = source.ParseInt();
104+
// source.Expect(")");
105+
// return new Location(groupX, groupY, indexInGroup);
106+
// }
107+
// }
108+
109+
// }

0 commit comments

Comments
 (0)