Skip to content

Commit

Permalink
refactor: Split project up into new frontend and backend modules
Browse files Browse the repository at this point in the history
  • Loading branch information
notmeta committed Oct 2, 2022
1 parent 0b34df4 commit 6477527
Show file tree
Hide file tree
Showing 131 changed files with 154 additions and 8,120 deletions.
9 changes: 9 additions & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
kotlin("jvm") version "1.7.10"
}

dependencies {
implementation("com.displee:disio:2.2")
implementation("com.displee:rs-cache-library:6.8.1")
implementation("org.apache.commons:commons-lang3:3.12.0")
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

import dawn.cs2.ast.*;
import dawn.cs2.util.FunctionDatabase;
import dawn.cs2.util.FunctionInfo;
import dawn.cs2.util.TextUtils;
import dawn.cs2.ast.*;
import dawn.cs2.util.FunctionInfo;

import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import static dawn.cs2.ast.LocalVariable.CHILD;
import static dawn.cs2.ast.LocalVariable._CHILD;
import static dawn.cs2.ast.LoopNode.LOOPTYPE_WHILE;

public class CS2ScriptParser {

private FunctionDatabase opcodesDatabase;
Expand Down Expand Up @@ -44,8 +41,8 @@ private CS2ScriptParser(String input, FunctionDatabase opcodesDatabase, Function
this.opcodesDatabase = opcodesDatabase;
this.scriptsDatabase = scriptsDatabase;
//TODO: Abstract LocalVariable away etc
declared.put("CHILD", CHILD);
declared.put("_CHILD", _CHILD);
declared.put("CHILD", LocalVariable.CHILD);
declared.put("_CHILD", LocalVariable._CHILD);
declared.put("_", Underscore.UNDERSCORE);
}

Expand Down Expand Up @@ -182,7 +179,7 @@ private FunctionInfo resolveCall(String name, List<ExpressionNode> args) {
// signature.addAll(Arrays.asList(((CallbackExpressionNode) arg).call.info.getArgumentTypes()));
// } else {
if (arg instanceof VariableLoadNode) {
if (((VariableLoadNode) arg).getVariable() == CHILD || ((VariableLoadNode) arg).getVariable() == _CHILD) {
if (((VariableLoadNode) arg).getVariable() == LocalVariable.CHILD || ((VariableLoadNode) arg).getVariable() == LocalVariable._CHILD) {
continue;
}
}
Expand Down Expand Up @@ -360,7 +357,7 @@ private AbstractCodeNode parseFlowConstruct() {
assert curr.equals(LEFT_PAREN);
ExpressionNode condition = parseExpression();
scope = new ScopeNode();
flow = new LoopNode(LOOPTYPE_WHILE, scope, condition);
flow = new LoopNode(LoopNode.LOOPTYPE_WHILE, scope, condition);
}
if (curr.equals("if")) {
advance();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dawn.cs2;

import dawn.cs2.ast.*;
import dawn.cs2.ast.*;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import dawn.cs2.ast.*;
import dawn.cs2.instructions.*;
import dawn.cs2.repo.DbTableTypeRepo;
import dawn.cs2.util.FunctionInfo;
import dawn.cs2.util.IOUtils;
import dawn.cs2.util.OpcodeUtils;
import kotlin.ranges.RangesKt;
import dawn.cs2.repo.DbTableTypeRepo;
import dawn.cs2.util.FunctionInfo;
import org.apache.commons.lang3.Range;

import java.io.*;
import java.time.temporal.ValueRange;
import java.util.*;

import static dawn.cs2.ast.LocalVariable.CHILD;
import static dawn.cs2.ast.LocalVariable._CHILD;
import static dawn.cs2.instructions.Opcodes.*;

public class FlowBlocksGenerator {
Expand Down Expand Up @@ -567,7 +563,7 @@ private int analyzeCall(FunctionInfo info, FlowBlock block, CS2Stack stack, int

ExpressionNode[] args = new ExpressionNode[info.getArgumentTypes().length + (objCall ? 1 : 0)];
if (objCall) {
args[info.getArgumentTypes().length] = new VariableLoadNode(useReg1 ? _CHILD : CHILD);
args[info.getArgumentTypes().length] = new VariableLoadNode(useReg1 ? LocalVariable._CHILD : LocalVariable.CHILD);
}
// objCall = false; //TODO: DISABLED THIS. not sure if its a good idea or not to have this. widget1.setText("test") vs setText("test", widget1) Should refactor this if gonna use this!
for (int i = info.getArgumentTypes().length - 1; i >= 0; i--) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dawn.cs2.ast;

import dawn.cs2.util.TextUtils;
import dawn.cs2.CS2Type;
import dawn.cs2.CodePrinter;
import dawn.cs2.util.TextUtils;

public class CharExpressionNode extends ExpressionNode implements IIntConstantNode {

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dawn.cs2.ast;

import dawn.cs2.CS2Type;
import dawn.cs2.DecompilerException;
import dawn.cs2.instructions.AbstractInstruction;
import dawn.cs2.instructions.IntInstruction;
import dawn.cs2.CS2Type;
import dawn.cs2.DecompilerException;
import dawn.cs2.instructions.Opcodes;

public class LocalVariable implements Variable {
Expand Down
File renamed without changes.
56 changes: 56 additions & 0 deletions backend/src/main/java/dawn/cs2/ast/Operator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dawn.cs2.ast;

public enum Operator {

PLUS("+", ExpressionNode.PRIORITY_ADDSUB, MathExpressionNode.class, 2),
MINUS("-", ExpressionNode.PRIORITY_ADDSUB, MathExpressionNode.class, 2),
MUL("*", ExpressionNode.PRIORITY_MULDIVREM, MathExpressionNode.class, 2),
DIV("/", ExpressionNode.PRIORITY_MULDIVREM, MathExpressionNode.class, 2),
REM("%", ExpressionNode.PRIORITY_MULDIVREM, MathExpressionNode.class, 2),
//TODO:
PLUSPREFIX("++", ExpressionNode.PRIORITY_PLUSMINUSPREFIXPOSTFIX, ExpressionNode.class, 1, true, false),
PLUSPOSTFIX("++", ExpressionNode.PRIORITY_PLUSMINUSPREFIXPOSTFIX, ExpressionNode.class, 1),
MINUSPREFIX("--", ExpressionNode.PRIORITY_PLUSMINUSPREFIXPOSTFIX, ExpressionNode.class, 1, true, false),
MINUSPOSTFIX("--", ExpressionNode.PRIORITY_PLUSMINUSPREFIXPOSTFIX, ExpressionNode.class, 1),
UNARYMINUS("-", ExpressionNode.PRIORITY_UNARYPLUSMINUS, ExpressionNode.class, 1, true, false),
UNARYPLUS("+", ExpressionNode.PRIORITY_UNARYPLUSMINUS, ExpressionNode.class, 1, true, false),
UNARYNOT("!", ExpressionNode.PRIORITY_UNARYLOGICALNOT, ExpressionNode.class, 1, true, false),
EQ("==", ExpressionNode.PRIORITY_EQNE, ConditionalExpressionNode.class, 2),
NEQ("!=", ExpressionNode.PRIORITY_EQNE, ConditionalExpressionNode.class, 2),
GT(">", ExpressionNode.PRIORITY_LELTGEGTINSTANCEOF, ConditionalExpressionNode.class, 2),
GE(">=", ExpressionNode.PRIORITY_LELTGEGTINSTANCEOF, ConditionalExpressionNode.class, 2),
LT("<", ExpressionNode.PRIORITY_LELTGEGTINSTANCEOF, ConditionalExpressionNode.class, 2),
LE("<=", ExpressionNode.PRIORITY_LELTGEGTINSTANCEOF, ConditionalExpressionNode.class, 2),
OR("||", ExpressionNode.PRIORITY_LOGICALOR, ConditionalExpressionNode.class, 2),
AND("&&", ExpressionNode.PRIORITY_LOGICALAND, ConditionalExpressionNode.class, 2),
ASSIGN("=", ExpressionNode.PRIORITY_ASSIGNMENT, VariableAssignationNode.class, 2, false, true),
//TODO: += etc

DUMMY_OP("", 99, ExpressionNode.class, 0);


public final String text;
public final int priority;
public final Class<? extends ExpressionNode> type;
public final int operands;
public boolean prefix;
public boolean assocRight;

Operator(String text, int prio, Class<? extends ExpressionNode> type, int operands) {
this(text, prio, type, operands, false, false);
}

Operator(String text, int prio, Class<? extends ExpressionNode> type, int operands, boolean prefix, boolean assocRight) {
this.text = text;
this.priority = prio;
this.type = type;
this.operands = operands;
this.prefix = prefix;
this.assocRight = assocRight;
}

@Override
public String toString() {
return text;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dawn.cs2.ast;

import dawn.cs2.util.TextUtils;
import dawn.cs2.CS2Type;
import dawn.cs2.CodePrinter;
import dawn.cs2.util.TextUtils;

public class StringExpressionNode extends ExpressionNode /*implements IIntConstantNode<String>*/ {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dawn.cs2.ast;

import dawn.cs2.instructions.IntInstruction;
import dawn.cs2.CS2Type;
import dawn.cs2.DecompilerException;
import dawn.cs2.instructions.AbstractInstruction;
import dawn.cs2.instructions.BooleanInstruction;
import dawn.cs2.instructions.IntInstruction;
import dawn.cs2.instructions.Opcodes;

public class Underscore implements Variable {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import dawn.cs2.CS2Type;
import dawn.cs2.CodePrinter;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class VariableAssignationNode extends ExpressionNode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dawn.cs2.instructions;

import dawn.cs2.util.FunctionInfo;

public class IntInstruction extends AbstractInstruction {

private int constant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dawn.cs2.util;

import dawn.cs2.CS2Type;
import dawn.cs2.ast.FunctionNode;
import dawn.cs2.CS2Type;

public class FunctionInfo {

Expand Down
File renamed without changes.
File renamed without changes.
72 changes: 25 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val javaVersion = JavaVersion.VERSION_17

plugins {
java
base
kotlin("jvm") version "1.7.10"
id("org.openjfx.javafxplugin") version "0.0.13"
}

group = "cs2-editor"
version = "1.5"

val gprUser: String? = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") ?: System.getenv("GITHUB_ACTOR")
val gprKey: String? = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") ?: System.getenv("GITHUB_TOKEN")
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/blurite/rscm-maven")
credentials {
username = gprUser
password = gprKey
allprojects {
group = "cs2-editor"
version = "1.5"
repositories {
mavenCentral()
}

plugins.withType<JavaPlugin> {
configure<JavaPluginExtension> {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
}
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("com.displee:disio:2.2")
implementation("com.displee:rs-cache-library:6.8.1")
if (gprUser != null) {
implementation("io.blurite:rscm:1.0")

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(javaVersion.toString().toInt())
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}
implementation("org.fxmisc.richtext:richtextfx:0.10.9")
implementation("com.google.code.gson:gson:2.9.0")
implementation("org.apache.commons:commons-lang3:3.12.0")
}

javafx {
modules = listOf("javafx.controls", "javafx.fxml")
}

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

destinationDirectory.set(file(rootDir))
manifest.attributes["Main-Class"] = "com.displee.editor.EditorKt"
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
42 changes: 42 additions & 0 deletions frontend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
kotlin("jvm") version "1.7.10"
id("org.openjfx.javafxplugin") version "0.0.13"
}

val gprUser: String? = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") ?: System.getenv("GITHUB_ACTOR")
val gprKey: String? = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") ?: System.getenv("GITHUB_TOKEN")

repositories {
maven {
url = uri("https://maven.pkg.github.com/blurite/rscm-maven")
credentials {
username = gprUser
password = gprKey
}
}
}

dependencies {
implementation(projects.backend)

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("com.displee:disio:2.2")
implementation("com.displee:rs-cache-library:6.8.1")
if (gprUser != null) {
implementation("io.blurite:rscm:1.0")
}
implementation("org.fxmisc.richtext:richtextfx:0.10.9")
implementation("com.google.code.gson:gson:2.9.0")
}

javafx {
modules = listOf("javafx.controls", "javafx.fxml")
}

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

destinationDirectory.set(file(rootDir))
manifest.attributes["Main-Class"] = "com.displee.editor.EditorKt"
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun setIcons(stage: Stage) {
}

// setting tray icon
val trayIcon = TrayIcon(image, "Cs2 Editor")
val trayIcon = TrayIcon(image, "Cs2 com.displee.editor.Editor")

// adjust to default size as per system recommendation
trayIcon.isImageAutoSize = true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "cs2-release"
rootProject.name = "cs2-editor"

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

include("frontend", "backend")
Loading

0 comments on commit 6477527

Please sign in to comment.