mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-27 20:26:34 +00:00
feat[gdscript]: gdscript compatible field support
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
*/
|
||||
public class GdCharSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public String fieldType(Field field, IFieldRegistration fieldRegistration) {
|
||||
return "String";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTabAscii(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeChar({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTabAscii(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readChar()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.zfoo.protocol.registration.field.MapField;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.enhance.EnhanceObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.*;
|
||||
import com.zfoo.protocol.serializer.typescript.GenerateTsUtils;
|
||||
import com.zfoo.protocol.util.ClassUtils;
|
||||
import com.zfoo.protocol.util.FileUtils;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
@@ -169,13 +170,9 @@ public abstract class GenerateGdUtils {
|
||||
var fieldType = gdSerializer(fieldRegistration.serializer()).fieldType(field, fieldRegistration);
|
||||
// 生成类型的注释
|
||||
gdBuilder.append(StringUtils.format("var {}: {}", fieldName, fieldType));
|
||||
if (fieldRegistration instanceof MapField) {
|
||||
var mapField = (MapField) fieldRegistration;
|
||||
var mapKeyRegistration = mapField.getMapKeyRegistration();
|
||||
var keyType = gdSerializer(mapKeyRegistration.serializer()).fieldType(field, mapKeyRegistration);
|
||||
var mapValueRegistration = mapField.getMapValueRegistration();
|
||||
var valueType = gdSerializer(mapValueRegistration.serializer()).fieldType(field, mapValueRegistration);
|
||||
gdBuilder.append(StringUtils.format(" # Dictionary<{}, {}>", keyType, valueType));
|
||||
if (fieldType.equals("Dictionary") || fieldType.equals("Array")) {
|
||||
var typeNote = GenerateTsUtils.toTsClassName(field.getGenericType().toString());
|
||||
gdBuilder.append(StringUtils.format(TAB_ASCII + "# {}", typeNote));
|
||||
}
|
||||
gdBuilder.append(LS);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,6 @@ public abstract class GenerateTsUtils {
|
||||
typeName = typeName.replaceAll("java.util.|java.lang.", StringUtils.EMPTY);
|
||||
typeName = typeName.replaceAll("[a-zA-Z0-9_.]*\\.", StringUtils.EMPTY);
|
||||
|
||||
// CSharp不适用基础类型的泛型,会影响性能
|
||||
switch (typeName) {
|
||||
case "boolean":
|
||||
case "Boolean":
|
||||
|
||||
Reference in New Issue
Block a user