Skip to content

Commit

Permalink
feat(#267): Fixed type names in dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Sep 4, 2024
1 parent 23fe9f1 commit 87f07b5
Show file tree
Hide file tree
Showing 13 changed files with 355 additions and 15 deletions.
28 changes: 28 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/achievements.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class AchievementDict(TypedDict):
title: str
desc: str


class Achievement:
def __init__(
self,
title: str,
desc: str
):
self.title: str = title
self.desc: str = desc

@classmethod
def from_dict(cls, _d: AchievementDict | None) -> "Achievement" | None:
if _d is None:
return None
return cls(
title=_d["title"],
desc=_d["desc"],
)
36 changes: 36 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/items.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class ItemDict(TypedDict):
pretty_name: str
desc: str
price: int
fn: str | None


class Item:
def __init__(
self,
pretty_name: str,
desc: str,
price: int,
fn: str | None
):
self.pretty_name: str = pretty_name
self.desc: str = desc
self.price: int = price
self.fn: str | None = fn

@classmethod
def from_dict(cls, _d: ItemDict | None) -> "Item" | None:
if _d is None:
return None
return cls(
pretty_name=_d["pretty_name"],
desc=_d["desc"],
price=_d["price"],
fn=_d.get("fn", None),
)
32 changes: 32 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/natures.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class NatureDict(TypedDict):
esc: str
atc: float
def: float


class Nature:
def __init__(
self,
esc: str,
atc: float,
def: float
):
self.esc: str = esc
self.atc: float = atc
self.def: float = def

@classmethod
def from_dict(cls, _d: NatureDict | None) -> "Nature" | None:
if _d is None:
return None
return cls(
esc=_d["esc"],
atc=_d["atc"],
def=_d["def"],
)
108 changes: 108 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/poke.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class BaseIcoDict(TypedDict):
txt: str
esc: str | None


class BaseIco:
def __init__(
self,
txt: str,
esc: str | None
):
self.txt: str = txt
self.esc: str | None = esc

@classmethod
def from_dict(cls, _d: BaseIcoDict | None) -> "BaseIco" | None:
if _d is None:
return None
return cls(
txt=_d["txt"],
esc=_d.get("esc", None),
)


class PokeDict(TypedDict):
name: str
hp: int
arc: int
defense: int
attacks: list[str]
pool: list[str]
miss_chance: int
desc: str
lose_xp: int
rarity: int
types: list[str]
evolve_poke: str
evolve_lvl: int
initiative: int
night_active: bool | None
ico: list["BaseIcoDict"]


class Poke:
def __init__(
self,
name: str,
hp: int,
arc: int,
defense: int,
attacks: list[str],
pool: list[str],
miss_chance: int,
desc: str,
lose_xp: int,
rarity: int,
types: list[str],
evolve_poke: str,
evolve_lvl: int,
initiative: int,
night_active: bool | None,
ico: list["BaseIco"]
):
self.name: str = name
self.hp: int = hp
self.arc: int = arc
self.defense: int = defense
self.attacks: list[str] = attacks
self.pool: list[str] = pool
self.miss_chance: int = miss_chance
self.desc: str = desc
self.lose_xp: int = lose_xp
self.rarity: int = rarity
self.types: list[str] = types
self.evolve_poke: str = evolve_poke
self.evolve_lvl: int = evolve_lvl
self.initiative: int = initiative
self.night_active: bool | None = night_active
self.ico: list["BaseIco"] = ico

@classmethod
def from_dict(cls, _d: PokeDict | None) -> "Poke" | None:
if _d is None:
return None
return cls(
name=_d["name"],
hp=_d["hp"],
arc=_d["arc"],
defense=_d["defense"],
attacks=_d["attacks"],
pool=_d["pool"],
miss_chance=_d["miss_chance"],
desc=_d["desc"],
lose_xp=_d["lose_xp"],
rarity=_d["rarity"],
types=_d["types"],
evolve_poke=_d["evolve_poke"],
evolve_lvl=_d["evolve_lvl"],
initiative=_d["initiative"],
night_active=_d.get("night_active", None),
ico=[BaseIco.from_dict(i) for i in _d["ico"]],
)
32 changes: 32 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/types.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class TypeDict(TypedDict):
effective: list[str]
ineffective: list[str]
color: list[str]


class Type:
def __init__(
self,
effective: list[str],
ineffective: list[str],
color: list[str]
):
self.effective: list[str] = effective
self.ineffective: list[str] = ineffective
self.color: list[str] = color

@classmethod
def from_dict(cls, _d: TypeDict | None) -> "Type" | None:
if _d is None:
return None
return cls(
effective=_d["effective"],
ineffective=_d["ineffective"],
color=_d["color"],
)
28 changes: 28 additions & 0 deletions Buf/github.com/lxgr-linux/pokete/resources/base/weather.pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <[email protected]>
from typing import TypedDict


class WeatherDict(TypedDict):
info: str
effected: dict[str, float]


class Weather:
def __init__(
self,
info: str,
effected: dict[str, float]
):
self.info: str = info
self.effected: dict[str, float] = effected

@classmethod
def from_dict(cls, _d: WeatherDict | None) -> "Weather" | None:
if _d is None:
return None
return cls(
info=_d["info"],
effected=_d["effected"],
)
41 changes: 26 additions & 15 deletions pkg/resources_python/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"fmt"
"log/slog"

//"fmt"
Expand Down Expand Up @@ -57,28 +58,28 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) error {
return nil
}

//slog.Warn(fmt.Sprintf("%+v", m))

filename := file.GeneratedFilenamePrefix + suffixFlag
g := gen.NewGeneratedFile(filename, file.GoImportPath)

tmpl, err := template.New("file").Parse(fileTmpl)
if err != nil {
return err
}

_, err = tmpl.New("field").Parse(fieldTmpl)
if err != nil {
return err
}
slog.Warn(fmt.Sprintf(
"%s, %s, %s, %s, %s",
file.GeneratedFilenamePrefix,
file.GoPackageName,
file.GoImportPath,
file.Desc.FullName(), file.Desc.Path()),
)
g := gen.NewGeneratedFile(filename, file.GoImportPath)

_, err = tmpl.Funcs(template.FuncMap{
tmpl, err := template.New("file").Funcs(template.FuncMap{
"fieldWithVar": func(field producer.Field, v string) producer.FieldWithVar {
return producer.FieldWithVar{Field: field, Var: v}
},
"pythonTypeWithVar": func(pythonType producer.MappedType, v string) producer.PythonTypeWithVar {
return producer.PythonTypeWithVar{MappedType: pythonType, Var: v}
},
"pythonTypeAsBaseType": func(pythonType producer.PythonTypeWithVar) producer.MappedType {
pythonType.MappedType.IsRepeated = false
return pythonType.MappedType
},
"get": func(field producer.FieldWithVar) string {
t, _ := template.New("").Parse(`
{{- if .PythonType.Optional -}}
Expand All @@ -87,13 +88,23 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) error {
{{ .Var }}["{{ .Name }}"]
{{- end -}}`)
var buf bytes.Buffer
err = t.Execute(&buf, field)
err := t.Execute(&buf, field)
if err != nil {
slog.Warn(err.Error())
}
return buf.String()
},
}).New("unmarshall").Parse(unmarshallTmpl)
}).Parse(fileTmpl)
if err != nil {
return err
}

_, err = tmpl.New("field").Parse(fieldTmpl)
if err != nil {
return err
}

_, err = tmpl.New("unmarshall").Parse(unmarshallTmpl)
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions proto/resources/base/achievements.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package pokete.resources.base;

message Achievement {
string Title = 1;
string Desc = 2;
}
9 changes: 9 additions & 0 deletions proto/resources/base/items.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package pokete.resources.base;

message Item {
string PrettyName = 1;
string Desc = 2;
int32 Price = 3;
optional string Fn = 4;
}
8 changes: 8 additions & 0 deletions proto/resources/base/natures.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
package pokete.resources.base;

message Nature {
string Esc = 1;
float Atc = 2;
float Def = 3;
}
26 changes: 26 additions & 0 deletions proto/resources/base/poke.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package pokete.resources.base;

message BaseIco {
string Txt = 1;
optional string Esc = 2;
}

message Poke {
string Name = 1;
int32 Hp = 2;
int32 Arc = 3;
int32 Defense = 4;
repeated string Attacks = 5;
repeated string Pool = 6;
int32 MissChance = 7;
string Desc = 8;
int32 LoseXp = 9;
int32 Rarity = 10;
repeated string Types = 11;
string EvolvePoke = 12;
int32 EvolveLvl = 13;
int32 initiative = 14;
optional bool NightActive = 15;
repeated BaseIco ico = 16;
}
Loading

0 comments on commit 87f07b5

Please sign in to comment.