【重构】提取 cfg code_python_27和 code_python_3 关于vector定义的公共字符串。不再重复出现。

【重构】删除 proto typescript 生成代码中行末的';'
main
walon 2021-06-29 17:59:07 +08:00
parent 260a1a84a3
commit 9e32c2f4fd
2 changed files with 93 additions and 144 deletions

View File

@ -151,7 +151,7 @@ namespace Luban.Job.Cfg
errMsg = "--output_data_resource_list_file missing";
return false;
}
if (genTypes.Contains("data_json_monolithic") && string.IsNullOrWhiteSpace(options.OutputDataJsonMonolithicFile))
if (genTypes.Contains("output_data_json_monolithic_file") && string.IsNullOrWhiteSpace(options.OutputDataJsonMonolithicFile))
{
errMsg = "--output_data_json_monolithic_file missing";
return false;
@ -660,60 +660,7 @@ export class Vector2 {
{
var fileContent = new List<string>
{
@"
class Vector2:
def __init__(self, x, y):
self.x = x
self.y = y
self.a = Vector4(1,2,3,4)
def __str__(self):
return '{%g,%g}' % (self.x, self.y)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
if (x == None or y == None):
raise Exception()
return Vector2(x, y)
class Vector3:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __str__(self):
return '{%f,%f,%f}' % (self.x, self.y, self.z)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
if (x == None or y == None or z == None):
raise Exception()
return Vector3(x, y, z)
class Vector4:
def __init__(self, x, y, z, w):
self.x = x
self.y = y
self.z = z
self.w = w
def __str__(self):
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
w = _json_['w']
if (x == None or y == None or z == None or w == None):
raise Exception()
return Vector4(x, y, z, w)
"
PYTHON_VECTOR_DEFINES
};
foreach (var type in exportTypes)
@ -775,60 +722,8 @@ class Vector4:
@"
from enum import Enum
import abc
class Vector2:
def __init__(self, x, y):
self.x = x
self.y = y
self.a = Vector4(1,2,3,4)
def __str__(self):
return '{%g,%g}' % (self.x, self.y)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
if (x == None or y == None):
raise Exception()
return Vector2(x, y)
class Vector3:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __str__(self):
return '{%f,%f,%f}' % (self.x, self.y, self.z)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
if (x == None or y == None or z == None):
raise Exception()
return Vector3(x, y, z)
class Vector4:
def __init__(self, x, y, z, w):
self.x = x
self.y = y
self.z = z
self.w = w
def __str__(self):
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
w = _json_['w']
if (x == None or y == None or z == None or w == None):
raise Exception()
return Vector4(x, y, z, w)
"
",
PYTHON_VECTOR_DEFINES,
};
foreach (var type in exportTypes)
@ -913,7 +808,7 @@ class Vector4:
tasks.Add(Task.Run(() =>
{
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CS);
var file = RenderFileUtil.GetDefTypePath(c.FullName, ELanguage.GO);
var file = RenderFileUtil.GetDefTypePath(c.FullName, ELanguage.CS);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
genCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
}));
@ -1096,5 +991,59 @@ class Vector4:
agent.Session.ReplyRpc<GenJob, GenJobArg, GenJobRes>(rpc, res);
}
private const string PYTHON_VECTOR_DEFINES = @"
class Vector2:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return '{%g,%g}' % (self.x, self.y)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
if (x == None or y == None):
raise Exception()
return Vector2(x, y)
class Vector3:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __str__(self):
return '{%f,%f,%f}' % (self.x, self.y, self.z)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
if (x == None or y == None or z == None):
raise Exception()
return Vector3(x, y, z)
class Vector4:
def __init__(self, x, y, z, w):
self.x = x
self.y = y
self.z = z
self.w = w
def __str__(self):
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
@staticmethod
def fromJson(_json_):
x = _json_['x']
y = _json_['y']
z = _json_['z']
w = _json_['w']
if (x == None or y == None or z == None or w == None):
raise Exception()
return Vector4(x, y, z, w)
";
}
}

View File

@ -179,11 +179,11 @@ export abstract class Protocol implements ISerializable {
}
export class Vector2 {
x: number;
y: number;
x: number
y: number
constructor(x: number, y: number) {
this.x = x;
this.y = y;
this.x = x
this.y = y
}
to(_buf_: Bright.Serialization.ByteBuf) {
@ -192,21 +192,21 @@ export class Vector2 {
}
static from(_buf_: Bright.Serialization.ByteBuf): Vector2 {
let x = _buf_.ReadFloat();
let y = _buf_.ReadFloat();
return new Vector2(x, y);
let x = _buf_.ReadFloat()
let y = _buf_.ReadFloat()
return new Vector2(x, y)
}
}
export class Vector3 {
x: number;
y: number;
z: number;
x: number
y: number
z: number
constructor(x: number, y: number, z: number) {
this.x = x;
this.y = y;
this.z = z;
this.x = x
this.y = y
this.z = z
}
to(_buf_: Bright.Serialization.ByteBuf) {
@ -216,23 +216,23 @@ export class Vector2 {
}
static from(_buf_: Bright.Serialization.ByteBuf): Vector3 {
let x = _buf_.ReadFloat();
let y = _buf_.ReadFloat();
let z = _buf_.ReadFloat();
return new Vector3(x, y, z);
let x = _buf_.ReadFloat()
let y = _buf_.ReadFloat()
let z = _buf_.ReadFloat()
return new Vector3(x, y, z)
}
}
export class Vector4 {
x: number;
y: number;
z: number;
w: number;
x: number
y: number
z: number
w: number
constructor(x: number, y: number, z: number, w: number) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.x = x
this.y = y
this.z = z
this.w = w
}
to(_buf_: Bright.Serialization.ByteBuf) {
@ -243,11 +243,11 @@ export class Vector2 {
}
static from(_buf_: Bright.Serialization.ByteBuf): Vector4 {
let x = _buf_.ReadFloat();
let y = _buf_.ReadFloat();
let z = _buf_.ReadFloat();
let w = _buf_.ReadFloat();
return new Vector4(x, y, z, w);
let x = _buf_.ReadFloat()
let y = _buf_.ReadFloat()
let z = _buf_.ReadFloat()
let w = _buf_.ReadFloat()
return new Vector4(x, y, z, w)
}
}