Skip to content

Commit

Permalink
Support for Artemis ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin.sciesinski committed Feb 1, 2021
1 parent dba1278 commit c09ccec
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 2 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {
apply plugin: "maven-publish"

group = "com.gempukku.libgdx.lib"
version = '0.1.12'
version = '0.1.13'
ext {
appName = "Libgdx Graph"
gdxVersion = '1.9.12'
Expand Down Expand Up @@ -72,6 +72,19 @@ project(":libgdx-gemp-lib-ashley") {
}
}

project(":libgdx-gemp-lib-artemis") {
apply plugin: "java-library"

dependencies {
implementation project(":libgdx-gemp-lib")
api 'com.roundtriangles.games:gdx-artemis:0.5'

testImplementation 'junit:junit:4.13'
testImplementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
testImplementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}

project(":libgdx-gemp-lib-test") {
apply plugin: "java-library"

Expand Down
82 changes: 82 additions & 0 deletions libgdx-gemp-lib-artemis/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apply plugin: "java"
apply plugin: "maven"
apply plugin: "signing"
apply plugin: "maven-publish"

sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = ["src/"]
sourceSets.main.resources.srcDirs = ["resources/"]
sourceSets.test.java.srcDirs = ["test/"]
sourceSets.test.resources.srcDirs = ["test-resources/"]


sourceSets.main.java.srcDirs = ["src/"]

archivesBaseName = "libgdx-gemp-lib-artemis"

eclipse.project.name = "libgdx-gemp-lib-artemis"

task javadocJar(type: Jar) {
classifier 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = "libgdx-graph"
description = "libGDX utility library"
url = "https://github.com/MarcinSc/libgdx-gemp-lib"
licenses {
license {
name = "The MIT License (MIT)"
url = "https://mit-license.org/"
}
}
developers {
developer {
id = "MarcinSc"
name = "Marcin Sciesinski"
email = "[email protected]"
}
}
scm {
connection = "[email protected]:MarcinSc/libgdx-gemp-lib.git"
developerConnection = "[email protected]:MarcinSc/libgdx-gemp-lib.git"
url = "https://github.com/MarcinSc/libgdx-gemp-lib"
}
}

from components.java
artifact javadocJar
artifact sourcesJar
}
}

repositories {
maven {
name = "OSSRH"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}

signing {
sign publishing.publications
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN"
"http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
<module>
<source path="lib/template/artemis"/>
<extend-configuration-property name="gdx.reflect.include"
value="com.gempukku.libgdx.lib.template.artemis.EntityDef"/>
<extend-configuration-property name="gdx.reflect.include" value="com.artemis.Component"/>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.gempukku.libgdx.lib.template.artemis;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.JsonWriter;
import com.gempukku.libgdx.lib.template.JsonTemplateLoader;

public class ArtemisTemplateEntityLoader {
public static EntityDef loadTemplate(String file, Json json, FileHandleResolver resolver) {
JsonValue jsonValue = JsonTemplateLoader.loadTemplateFromFile(file, resolver);
return convertToArtemis(jsonValue, json);
}

public static EntityDef loadTemplate(FileHandle fileHandle, Json json, FileHandleResolver resolver) {
JsonValue jsonValue = JsonTemplateLoader.loadTemplateFromFile(fileHandle, resolver);
return convertToArtemis(jsonValue, json);
}

public static EntityDef convertToArtemis(JsonValue jsonValue, Json json) {
JsonValue artemisJson = convertToArtemisEntityJson(jsonValue);
if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG)
Gdx.app.debug("ArtemisTemplate", artemisJson.toJson(JsonWriter.OutputType.json));
return json.readValue(EntityDef.class, artemisJson);
}

public static JsonValue convertToArtemisEntityJson(JsonValue value) {
JsonValue result = new JsonValue(JsonValue.ValueType.object);
JsonValue componentsArray = new JsonValue(JsonValue.ValueType.array);
JsonValue lastChild = null;
for (JsonValue jsonValue : value) {
String name = jsonValue.name();
jsonValue.addChild("class", new JsonValue(name));
if (lastChild == null) {
lastChild = jsonValue;
componentsArray.addChild(lastChild);
} else {
lastChild.next = jsonValue;
jsonValue.parent = result;
lastChild = jsonValue;
}
}
componentsArray.size = value.size;
result.addChild("components", componentsArray);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gempukku.libgdx.lib.template.artemis;

import com.artemis.Component;
import com.artemis.World;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonWriter;
import com.badlogic.gdx.utils.reflect.ClassReflection;

public class ArtemisWorldJson extends Json {
private World world;

public ArtemisWorldJson(World world) {
this.world = world;
}

public ArtemisWorldJson(JsonWriter.OutputType outputType, World world) {
super(outputType);
this.world = world;
}

@Override
protected Object newInstance(Class type) {
if (ClassReflection.isAssignableFrom(Component.class, type))
return world.createComponent(type);
return super.newInstance(type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gempukku.libgdx.lib.template.artemis;

import com.artemis.Component;
import com.badlogic.gdx.utils.Array;

public class EntityDef {
private Array<Component> components;

public Array<Component> getComponents() {
return components;
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include 'libgdx-gemp-lib', 'libgdx-gemp-lib-ashley', 'libgdx-gemp-lib-test'
include 'libgdx-gemp-lib', 'libgdx-gemp-lib-ashley', 'libgdx-gemp-lib-artemis', 'libgdx-gemp-lib-test'

0 comments on commit c09ccec

Please sign in to comment.