me when i dont use vcs properly
This commit is contained in:
@@ -79,14 +79,13 @@ func CollectPacketInfo(versions []string) (packetInfos []PacketInfo, err error)
|
||||
}
|
||||
|
||||
func GeneratePacketInfoFile(versions []string) (err error) {
|
||||
var packetInfos []PacketInfo
|
||||
packetInfos, err = CollectPacketInfo(versions)
|
||||
packetInfos, err := CollectPacketInfo(versions)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f := NewFile("proto_generated")
|
||||
imports := []string{"reflect", "github.com/admin-else/strom/proto_base"}
|
||||
imports := []string{"github.com/admin-else/strom/proto_base"}
|
||||
for _, v := range versions {
|
||||
vUnderscore := strings.ReplaceAll(v, ".", "_")
|
||||
imports = append(imports, "github.com/admin-else/strom/proto_generated/v"+vUnderscore)
|
||||
@@ -109,8 +108,8 @@ func GeneratePacketInfoFile(versions []string) (err error) {
|
||||
packetId, _ := strconv.ParseInt(p.PacketId, 0, 32)
|
||||
protocolVersion, _ := strconv.Atoi(p.ProtocolVersion)
|
||||
|
||||
packetInfoExprs = append(packetInfoExprs, CompLit(Selector("proto_base", "PacketInfo"), []ast.Expr{
|
||||
KeyValueExpr(Ident("Type"), Call(Selector("reflect", "TypeOf"), CompLit(typeExpr, nil))),
|
||||
packetInfoExprs = append(packetInfoExprs, CompLit(nil, []ast.Expr{
|
||||
KeyValueExpr(Ident("Type"), AddrOf(CompLit(typeExpr, nil))),
|
||||
KeyValueExpr(Ident("Name"), StrLit(p.Name)),
|
||||
KeyValueExpr(Ident("Direction"), Selector("proto_base", p.Direction)),
|
||||
KeyValueExpr(Ident("State"), Selector("proto_base", p.State)),
|
||||
|
||||
+3
-20
@@ -28,10 +28,6 @@ type Protocol struct {
|
||||
Handshaking, Status, Login, Configuration, Play State
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
ReplaceWithTodoNames []string
|
||||
}
|
||||
|
||||
type ContainerStackEntry struct {
|
||||
Data []struct {
|
||||
Name string
|
||||
@@ -43,7 +39,6 @@ type ContainerStackEntry struct {
|
||||
|
||||
type Generator struct {
|
||||
// These persist the entire generate-call
|
||||
Settings Settings
|
||||
Natives map[string]ExprGeneratorFunc
|
||||
DecoderNatives map[string]FunctionGeneratorFunc
|
||||
EncoderNatives map[string]FunctionGeneratorFunc
|
||||
@@ -202,10 +197,6 @@ func (g *Generator) GenerateTypes(prefix string, types Types) (err error) {
|
||||
g.CurrentlyGeneratingTypesPrefix = prefix
|
||||
for _, k := range OrderedKeys(types.Types) {
|
||||
v := types.Types[k]
|
||||
if slices.Contains(g.Settings.ReplaceWithTodoNames, k) {
|
||||
v = "todo"
|
||||
}
|
||||
|
||||
g.Depth = 0
|
||||
e, err2 := g.VisitType(v)
|
||||
if errors.Is(err2, ToDoError) {
|
||||
@@ -232,9 +223,7 @@ func (g *Generator) GenerateTypes(prefix string, types Types) (err error) {
|
||||
s, err2 := g.VisitDecoder(retExpr, v, tName)
|
||||
if err2 != nil {
|
||||
s = ToDoStmts
|
||||
if !errors.Is(err2, ToDoError) {
|
||||
fmt.Println("failed to make decoder for", k, err2)
|
||||
}
|
||||
fmt.Println("failed to make decoder for", k, err2)
|
||||
}
|
||||
decodeFunction.Body = NewBlock(append(s, Return()))
|
||||
AppendDecl(g.File, decodeFunction)
|
||||
@@ -246,13 +235,10 @@ func (g *Generator) GenerateTypes(prefix string, types Types) (err error) {
|
||||
s, err2 = g.VisitEncoder(retExpr, v, tName)
|
||||
if err2 != nil {
|
||||
s = ToDoStmts
|
||||
if !errors.Is(err2, ToDoError) {
|
||||
fmt.Println("failed to make encoder for", k, err2)
|
||||
}
|
||||
fmt.Println("failed to make encoder for", k, err2)
|
||||
}
|
||||
encodeFunction.Body = NewBlock(append(s, Return()))
|
||||
AppendDecl(g.File, encodeFunction)
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -300,9 +286,6 @@ func Generate(version string, w io.Writer) (err error) {
|
||||
|
||||
g := &Generator{Protocol: protocol}
|
||||
|
||||
// These have annoying edge cases that would require me to implement a whole new compareTo parser
|
||||
g.Settings.ReplaceWithTodoNames = []string{}
|
||||
|
||||
g.File = NewFile("v" + strings.ReplaceAll(version, ".", "_"))
|
||||
AppendDecl(g.File, Import("encoding/binary", "io", "github.com/admin-else/strom/proto_base", "github.com/admin-else/strom/nbt", "github.com/google/uuid"))
|
||||
g.RegisterNatives()
|
||||
@@ -322,7 +305,7 @@ func generateVersion(v string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
f, err := os.Create("proto_generated/v" + vUnderscore + "/proto_base.go")
|
||||
f, err := os.Create("proto_generated/v" + vUnderscore + "/proto.go")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user