Search in sources :

Example 6 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project var3dframe by Var3D.

the class VDesktopLauncher method getPartialVariable.

// 用来获取actor的局部变量名,除非为匿名变量
private String getPartialVariable(VStage stage, Actor actor) {
    FileHandle fileHandle = getStageJavaFile(stage);
    if (fileHandle == null)
        fileHandle = getStageKotlinFile(stage);
    if (fileHandle == null)
        return null;
    String javaStr = fileHandle.readString();
    // 把代码按行号存放进数组中
    String[] javaStrLines = javaStr.split("\n");
    Data data = allDatas.get(actor);
    StackTraceElement[] elements = allStacks.get(actor);
    // 为null表示这是非UI类创建的控件,以后再实现非UI类创建的控件
    if (elements == null)
        return null;
    // 变量所在的类全名
    String str_class = elements[2].getClassName();
    if (str_class.equals(stage.getClass().getName())) {
        // 如果所在的类就是传入的这个Stage
        // 获取该变量调用初始化所在的行号
        int linNumber = elements[2].getLineNumber();
        Array<String> javaStrArr = new Array<>();
        int partNumber = 0;
        for (int i = linNumber - 1; i > 1; i--) {
            String javaStrLine = javaStrLines[i].trim();
            javaStrLine = javaStrLine.replaceAll(" +", " ");
            javaStrLine = javaStrLine.replaceAll(" \\.", ".");
            javaStrLine = javaStrLine.replaceAll("\\. ", ".");
            javaStrLine = javaStrLine.replaceAll(" ", "㜶");
            // 移除注释
            String noAnnotations = javaStrLine.replaceAll("\\/\\/[^\\n]*|\\/\\*([^\\*^\\/]*|[\\*^\\/*]*|[^\\**\\/]*)*\\*+\\/", "");
            if (noAnnotations.indexOf(";") != -1 || fileType == FileType.Kotlin) {
                partNumber++;
                if (partNumber == 2) {
                    int i1 = noAnnotations.lastIndexOf(";");
                    if (i1 == -1 && fileType == FileType.Kotlin)
                        i1 = noAnnotations.length() - 1;
                    javaStrArr.add(noAnnotations.substring(i1 + 1));
                    // javaStrLines[i] = noAnnotations.substring(0, i1);
                    break;
                } else {
                    javaStrArr.add(noAnnotations);
                }
            } else {
                javaStrArr.add(noAnnotations);
            // javaStrLines[i] = "";
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = javaStrArr.size - 1; i > -1; i--) {
            String strLine = javaStrArr.get(i);
            stringBuilder.append("㜶");
            stringBuilder.append(strLine);
        }
        String codeStr = stringBuilder.toString();
        int idex;
        if ((idex = codeStr.indexOf("=")) != -1) {
            String name = codeStr.substring(0, idex).replaceAll("㜶", " ").trim();
            name = name.replaceAll(" +", " ");
            idex = name.lastIndexOf(" ");
            if (idex != -1) {
                name = name.substring(name.lastIndexOf(" "));
            }
            return name.trim();
        } else {
            // 匿名变量
            return "?";
        }
    }
    return null;
}
Also used : IntArray(com.badlogic.gdx.utils.IntArray) Array(com.badlogic.gdx.utils.Array) StringBuilder(com.badlogic.gdx.utils.StringBuilder) FileHandle(com.badlogic.gdx.files.FileHandle) AttributedString(java.text.AttributedString) FreePaint(var3d.net.center.freefont.FreePaint)

Example 7 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project libgdx by libgdx.

the class OcclusionCullingTest method create.

@Override
public void create() {
    Gdx.input.setOnscreenKeyboardVisible(true);
    super.create();
    GLProfiler.enable();
    StringBuilder sb = new StringBuilder();
    sb.append("Swipe for next test\n");
    sb.append("Long press to toggle debug mode\n");
    sb.append("Ctrl+drag to rotate\n");
    sb.append("Scroll to zoom\n");
    sb.append("Tap to spawn dynamic entity, press\n");
    sb.append("'0' to spawn ").append(KEY_SPAWN_OCCLUDEE_AMOUNT).append(" static entities\n");
    sb.append("'1' to set normal/disabled/occlusion-culling\n");
    sb.append("'2' to change camera\n");
    sb.append("'3' to toggle camera movement\n");
    sb.append("'4' to cycle occlusion buffer sizes\n");
    sb.append("'5' to toggle occlusion buffer image\n");
    sb.append("'6' to toggle shadows\n");
    instructions = sb.toString();
    AssetManager assets = new AssetManager();
    disposables.add(assets);
    for (String modelName : OCCLUDEE_PATHS_DYNAMIC) assets.load(modelName, Model.class);
    assets.load(DEFAULT_TEX_PATH, Texture.class);
    Camera shadowCamera = ((DirectionalShadowLight) light).getCamera();
    shadowCamera.viewportWidth = shadowCamera.viewportHeight = 120;
    // User controlled camera
    overviewCam = camera;
    overviewCam.position.set(overviewCam.direction).nor().scl(-100);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = camera.far *= 2;
    overviewCam.update(true);
    // Animated frustum camera model
    frustumCam = new PerspectiveCamera(FRUSTUM_CAMERA_FOV, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = FRUSTUM_CAMERA_FAR;
    frustumCam.update(true);
    final Model frustumModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
    frustumModel.materials.first().set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
    disposables.add(frustumModel);
    frustumInstance = new ModelInstance(frustumModel);
    spriteBatch = new SpriteBatch();
    disposables.add(spriteBatch);
    shapeRenderer = new ShapeRenderer();
    disposables.add(shapeRenderer);
    oclBuffer = new OcclusionBuffer(OCL_BUFFER_EXTENTS[0], OCL_BUFFER_EXTENTS[0]);
    disposables.add(oclBuffer);
    occlusionCuller = new OcclusionCuller() {

        @Override
        public boolean isOccluder(btCollisionObject object) {
            return (object.getCollisionFlags() & CF_OCCLUDER_OBJECT) != 0;
        }

        @Override
        public void onObjectVisible(btCollisionObject object) {
            visibleEntities.add(world.entities.get(object.getUserValue()));
        }
    };
    disposables.add(occlusionCuller);
    // Add occluder walls
    final Model occluderModel = modelBuilder.createBox(OCCLUDER_DIM.x, OCCLUDER_DIM.y, OCCLUDER_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    disposables.add(occluderModel);
    world.addConstructor("wall", new BulletConstructor(occluderModel, 0, new btBoxShape(tmpV1.set(OCCLUDER_DIM).scl(0.5f))));
    float y = OCCLUDER_DIM.y * 0.5f;
    addOccluder("wall", 0, tmpV1.set(20, y, 0));
    addOccluder("wall", -60, tmpV1.set(10, y, 20));
    addOccluder("wall", 60, tmpV1.set(10, y, -20));
    addOccluder("wall", 0, tmpV1.set(-20, y, 0));
    addOccluder("wall", 60, tmpV1.set(-10, y, 20));
    addOccluder("wall", -60, tmpV1.set(-10, y, -20));
    // Add ground
    final Model groundModel = modelBuilder.createBox(GROUND_DIM.x, GROUND_DIM.y, GROUND_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    btCollisionShape groundShape = new btBoxShape(tmpV1.set(GROUND_DIM).scl(0.5f));
    world.addConstructor("big_ground", new BulletConstructor(groundModel, 0, groundShape));
    BulletEntity e = world.add("big_ground", 0, -GROUND_DIM.y * 0.5f, 0f);
    e.body.setFriction(1f);
    e.setColor(Color.FOREST);
    // Occludee entity constructors. Scale models uniformly and set a default diffuse texture.
    BoundingBox bb = new BoundingBox();
    assets.finishLoadingAsset(DEFAULT_TEX_PATH);
    TextureAttribute defaultTexture = new TextureAttribute(TextureAttribute.Diffuse, assets.get(DEFAULT_TEX_PATH, Texture.class));
    for (int i = 0; i < OCCLUDEE_PATHS_DYNAMIC.length; i++) {
        String modelPath = OCCLUDEE_PATHS_DYNAMIC[i];
        OCCLUDEE_PATHS_STATIC[i] = "static" + modelPath;
        assets.finishLoadingAsset(modelPath);
        Model model = assets.get(modelPath, Model.class);
        if (!model.materials.first().has(TextureAttribute.Diffuse))
            model.materials.first().set(defaultTexture);
        Vector3 dim = model.calculateBoundingBox(bb).getDimensions(tmpV1);
        float scaleFactor = OCCLUDEE_MAX_EXTENT / Math.max(dim.x, Math.max(dim.y, dim.z));
        for (Node node : model.nodes) node.scale.scl(scaleFactor);
        btCollisionShape shape = new btBoxShape(dim.scl(scaleFactor * 0.5f));
        world.addConstructor(modelPath, new BulletConstructor(model, 1, shape));
        world.addConstructor(OCCLUDEE_PATHS_STATIC[i], new BulletConstructor(model, 0, shape));
    }
    // Add occludees
    for (int i = 0; i < STARTING_OCCLUDEE_AMOUNT; i++) addRandomOccludee(false);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) StringBuilder(com.badlogic.gdx.utils.StringBuilder) Node(com.badlogic.gdx.graphics.g3d.model.Node) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Camera(com.badlogic.gdx.graphics.Camera) com.badlogic.gdx.physics.bullet.collision.btCollisionObject(com.badlogic.gdx.physics.bullet.collision.btCollisionObject) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) Model(com.badlogic.gdx.graphics.g3d.Model) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 8 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project var3dframe by Var3D.

the class VDesktopLauncher method saveUI.

// 保存编辑过的Actor
public void saveUI(VStage stage) {
    // 遍历stage中的actor,并找出该actor在stage初始化时的行号位置
    FileHandle fileHandle = getStageJavaFile(stage);
    if (fileHandle == null)
        fileHandle = getStageKotlinFile(stage);
    if (fileHandle == null)
        return;
    String javaStr = fileHandle.readString();
    // 把代码按行号存放进数组中
    String[] javaStrLines = javaStr.split("\n");
    for (final Actor actor : stage.getRoot().getChildren()) {
        Data data = allDatas.get(actor);
        if (data == null)
            return;
        if (data.isEdit) {
            StackTraceElement[] elements = allStacks.get(actor);
            if (elements == null)
                continue;
            String str_class = elements[2].getClassName();
            if (str_class.equals(stage.getClass().getName())) {
                int linNumber = elements[2].getLineNumber();
                int firstLinNumber = linNumber;
                Array<String> javaStrArr = new Array<>();
                int partNumber = 0;
                for (int i = linNumber - 1; i > 1; i--) {
                    String javaStrLine = javaStrLines[i].trim();
                    javaStrLine = javaStrLine.replaceAll(" +", " ");
                    javaStrLine = javaStrLine.replaceAll(" \\.", ".");
                    javaStrLine = javaStrLine.replaceAll("\\. ", ".");
                    javaStrLine = javaStrLine.replaceAll(" ", "㜶");
                    // 移除注释
                    String noAnnotations = javaStrLine.replaceAll("\\/\\/[^\\n]*|\\/\\*([^\\*^\\/]*|[\\*^\\/*]*|[^\\**\\/]*)*\\*+\\/", "");
                    if (noAnnotations.indexOf(";") != -1 || fileType == FileType.Kotlin) {
                        partNumber++;
                        if (partNumber == 2) {
                            int i1 = noAnnotations.lastIndexOf(";");
                            if (i1 == -1 && fileType == FileType.Kotlin)
                                i1 = noAnnotations.length() - 1;
                            javaStrArr.add(noAnnotations.substring(i1 + 1));
                            break;
                        } else {
                            javaStrArr.add(noAnnotations);
                            javaStrLines[i] = "";
                        }
                    } else {
                        javaStrArr.add(noAnnotations);
                        javaStrLines[i] = "";
                    }
                }
                firstLinNumber -= javaStrArr.size - 1;
                StringBuilder stringBuilder = new StringBuilder();
                for (int len = javaStrArr.size - 1, i = len; i > -1; i--) {
                    String strLine = javaStrArr.get(i).trim();
                    stringBuilder.append("㜶");
                    stringBuilder.append(strLine);
                }
                String codeStr = stringBuilder.toString().replaceAll("㜶+", "㜶");
                if (codeStr.startsWith("㜶")) {
                    codeStr = codeStr.substring(1);
                }
                // Gdx.app.log("aaaaaa", codeStr);
                String floatNumberSuffix = "";
                if (fileType == FileType.Kotlin)
                    floatNumberSuffix = "f";
                int idex;
                if ((idex = codeStr.lastIndexOf("setPosition(")) != -1) {
                    // 说明拥有setPosition方法
                    String s1 = codeStr.substring(idex);
                    s1 = s1.substring(0, s1.indexOf(")") + 1);
                    codeStr = codeStr.replace(s1, "setPosition(" + (int) actor.getX() + floatNumberSuffix + "," + (int) actor.getY() + floatNumberSuffix + ")");
                } else {
                    // 如果没有setPosition方法,那么去定位show,getActor()
                    idex = codeStr.lastIndexOf(".show(");
                    if (idex == -1)
                        idex = codeStr.lastIndexOf(".getActor(");
                    // 接着把字符分为两段
                    String s1 = codeStr.substring(0, idex);
                    String s2 = codeStr.substring(idex);
                    codeStr = s1 + ".setPosition(" + (int) actor.getX() + floatNumberSuffix + "," + (int) actor.getY() + floatNumberSuffix + ")" + s2;
                }
                List<String> listStr = new ArrayList<String>();
                String subStr, prefStr = "";
                int prefIndex = 0, width = 90;
                for (int i = 0; ; i++) {
                    int index = codeStr.indexOf(".", i);
                    if (index == -1) {
                        listStr.add(prefStr + codeStr.substring(prefIndex));
                        break;
                    }
                    subStr = codeStr.substring(prefIndex, index);
                    if (prefStr.length() + subStr.length() > width) {
                        listStr.add(prefStr);
                        prefIndex = index;
                        prefStr = subStr;
                    } else {
                        prefStr += subStr;
                        prefIndex = index;
                    }
                }
                StringBuilder out = new StringBuilder();
                for (int i = 0; i < listStr.size(); i++) {
                    out.append("        ");
                    // Gdx.app.log("bbbbbb", listStr.get(i));
                    String sline = listStr.get(i).replaceAll("㜶", " ");
                    // Gdx.app.log("cccccc", sline);
                    sline = sline.replaceAll(" \\.", ".");
                    sline = sline.replaceAll("\\. ", ".");
                    out.append(sline);
                    if (i < listStr.size() - 1)
                        out.append("\n");
                }
                javaStrLines[firstLinNumber] = out.toString();
            // Gdx.app.log("bbbbbb", out.toString());
            }
        }
    }
    // 重新组装java代码
    StringBuilder out = new StringBuilder();
    boolean prefLineIsNull = false;
    for (int i = 0; i < javaStrLines.length; i++) {
        String thisline = javaStrLines[i];
        boolean nowNull = thisline.replaceAll(" ", "").length() == 0;
        if (prefLineIsNull && nowNull) {
            prefLineIsNull = nowNull;
            continue;
        } else {
            prefLineIsNull = nowNull;
        }
        out.append(javaStrLines[i]);
        out.append("\n");
    }
    // 保存java代码
    fileHandle.writeString(out.toString(), false);
    // 关闭窗口
    Gdx.app.exit();
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder) FileHandle(com.badlogic.gdx.files.FileHandle) ArrayList(java.util.ArrayList) AttributedString(java.text.AttributedString) FreePaint(var3d.net.center.freefont.FreePaint) IntArray(com.badlogic.gdx.utils.IntArray) Array(com.badlogic.gdx.utils.Array) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 9 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project Eidolons by IDemiurge.

the class DC_LogManager method logBattleJoined.

public void logBattleJoined(List<Unit> newUnits) {
    StringBuilder text = new StringBuilder();
    text.append("Battle joined by: ");
    newUnits.forEach(unit -> {
        text.append(unit.getNameIfKnown() + ", ");
    });
    text.delete(text.length() - 2, text.length());
    String message = text.toString();
    SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.MAIN, message);
    SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.COMBAT, message);
    log(message);
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder)

Example 10 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project Eidolons by IDemiurge.

the class SpecialLogger method checkAppendToSpecialLog.

public void checkAppendToSpecialLog(LOG_CHANNEL channel, String text) {
    for (SPECIAL_LOG sub : SPECIAL_LOG.values()) {
        if (sub.getChannels().contains(channel)) {
            appendSpecialLog(sub, text);
            break;
        }
    }
    StringBuilder builder = channelMap.get(channel);
    if (builder != null) {
        String string = builder.toString();
        writeLog(channel.name(), builder, string, true, false);
    }
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder)

Aggregations

StringBuilder (com.badlogic.gdx.utils.StringBuilder)10 FileHandle (com.badlogic.gdx.files.FileHandle)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Array (com.badlogic.gdx.utils.Array)2 IntArray (com.badlogic.gdx.utils.IntArray)2 AttributedString (java.text.AttributedString)2 FreePaint (var3d.net.center.freefont.FreePaint)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 Camera (com.badlogic.gdx.graphics.Camera)1 Color (com.badlogic.gdx.graphics.Color)1 Mesh (com.badlogic.gdx.graphics.Mesh)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1