Skip to content

Commit

Permalink
Merge remote-tracking branch 'BenjaminAmos/de-duplicate-assets' into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
Cervator committed Oct 31, 2021
2 parents e726c36 + 23f598e commit eca02c8
Show file tree
Hide file tree
Showing 23 changed files with 224 additions and 40 deletions.
17 changes: 9 additions & 8 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ buildscript {
classpath 'dom4j:dom4j:1.6.1'

// HACK: Needed for NUI and gestalt entity-component reflections
classpath group: 'org.terasology.nui', name: 'nui', version: '2.0.0-SNAPSHOT'
classpath group: 'org.terasology.nui', name: 'nui', version: '3.1.0-SNAPSHOT'
classpath group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
classpath group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.0.6-SNAPSHOT'
classpath group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.2.0-SNAPSHOT'
}
}

Expand All @@ -42,10 +42,10 @@ dependencies {
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"

api(group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.0.6-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.0.6-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.0.6-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-util', version: '7.0.6-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-util', version: '7.2.0-SNAPSHOT')

api group: 'org.terasology.nui', name: 'nui', version: nuiVersion
api group: 'org.terasology.nui', name: 'nui-libgdx', version: nuiVersion
Expand Down Expand Up @@ -82,15 +82,16 @@ task cacheReflections {
configurations."${sourceSets.main.runtimeClasspathConfigurationName}"

outputs.upToDateWhen {classes.state.upToDate}
outputs.file("$buildDir/classes/reflections.cache")
outputs.file("$buildDir/resources/main/org/destinationsol/reflections.cache")
dependsOn classes

doLast {
// Without the .mkdirs() we might hit a scenario where the classes dir doesn't exist yet
Reflections reflections = new Reflections(new ConfigurationBuilder()
.addUrls(inputs.files.collect { it.toURI().toURL() })
.filterInputsBy({ it.startsWith("org.destinationsol") || it.startsWith("org.terasology.nui") })
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()))
reflections.save("$buildDir/classes/reflections.cache")
reflections.save("$buildDir/resources/main/org/destinationsol/reflections.cache")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package org.destinationsol.assets.music;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.assets.format.AbstractAssetFileFormat;
import org.terasology.gestalt.assets.format.AssetDataFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class AndroidOggMusicFileFormat extends AbstractAssetFileFormat<OggMusicData> {
Expand All @@ -33,15 +31,26 @@ public AndroidOggMusicFileFormat() {
@Override
public OggMusicData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
// HACK: LibGDX will only accept an AndroidFileHandle (it casts to one internally). The class has a private
// constructor, so we cannot use the same workaround as with AssetDataFileHandle. The only plausible way
// to do this appears to be to save the data out to a file and point LibGDX at that.
// constructor, so we cannot use the same workaround as with AssetDataFileHandle.
// Android also doesn't seem to support playing media directly form InputStreams directly either.
// The only way I've found to get around this is to bypass gestalt using the information it provides
// on the source path for the asset.
// Android will be forced to use directory modules exclusively because of this.
AssetDataFile asset = inputs.get(0);
FileHandle outFile = Gdx.files.local("music/" + urn.toString().replace(":", "_") + "." + inputs.get(0).getFileExtension());
if (!outFile.exists()) {
InputStream fileStream = asset.openStream();
outFile.write(fileStream, false);

StringBuilder pathStringBuilder = new StringBuilder();
if (urn.getModuleName().compareTo("engine") != 0) {
pathStringBuilder.append("modules/");
}
pathStringBuilder.append(urn.getModuleName());
pathStringBuilder.append("/");

for (int pathNo = 0; pathNo < asset.getPath().size(); pathNo++) {
pathStringBuilder.append(asset.getPath().get(pathNo));
pathStringBuilder.append('/');
}
pathStringBuilder.append(asset.getFilename());

return new OggMusicData(Gdx.audio.newMusic(outFile));
return new OggMusicData(Gdx.audio.newMusic(Gdx.files.internal(pathStringBuilder.toString())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package org.destinationsol.assets.sound;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.assets.format.AbstractAssetFileFormat;
import org.terasology.gestalt.assets.format.AssetDataFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class AndroidOggSoundFileFormat extends AbstractAssetFileFormat<OggSoundData> {
Expand All @@ -33,15 +31,26 @@ public AndroidOggSoundFileFormat() {
@Override
public OggSoundData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
// HACK: LibGDX will only accept an AndroidFileHandle (it casts to one internally). The class has a private
// constructor, so we cannot use the same workaround as with AssetDataFileHandle. The only plausible way
// to do this appears to be to save the data out to a file and point LibGDX at that.
// constructor, so we cannot use the same workaround as with AssetDataFileHandle.
// Android also doesn't seem to support playing media directly form InputStreams directly either.
// The only way I've found to get around this is to bypass gestalt using the information it provides
// on the source path for the asset.
// Android will be forced to use directory modules exclusively because of this.
AssetDataFile asset = inputs.get(0);
FileHandle outFile = Gdx.files.local("sound/" + urn.toString().replace(":", "_") + "." + inputs.get(0).getFileExtension());
if (!outFile.exists()) {
InputStream fileStream = asset.openStream();
outFile.write(fileStream, false);

StringBuilder pathStringBuilder = new StringBuilder();
if (urn.getModuleName().compareTo("engine") != 0) {
pathStringBuilder.append("modules/");
}
pathStringBuilder.append(urn.getModuleName());
pathStringBuilder.append("/");

for (int pathNo = 0; pathNo < asset.getPath().size(); pathNo++) {
pathStringBuilder.append(asset.getPath().get(pathNo));
pathStringBuilder.append('/');
}
pathStringBuilder.append(asset.getFilename());

return new OggSoundData(Gdx.audio.newSound(outFile));
return new OggSoundData(Gdx.audio.newSound(Gdx.files.internal(pathStringBuilder.toString())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public float getMass() {
}

@Override
public void copy(BodyLinked other) {
public void copyFrom(BodyLinked other) {
this.mass = other.getMass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setDurability(float durability) {
}

@Override
public void copy(Durability other) {
public void copyFrom(Durability other) {
this.durability = other.durability;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package org.destinationsol.game.console.adapter;

import org.terasology.gestalt.module.sandbox.API;

@API
public interface ParameterAdapter<T> {
T parse(String raw);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.destinationsol.SolApplication;
import org.destinationsol.game.console.commands.PositionCommandHandler;
import org.destinationsol.game.ship.hulls.HullConfig;
import org.terasology.gestalt.module.sandbox.API;

import java.util.Map;

@API
public class ParameterAdapterManager {
private final Map<Class<?>, ParameterAdapter> adapters = Maps.newHashMap();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2021 The Terasology Foundation
*
* 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.
*/
@API package org.destinationsol.game.console.annotations;

import org.terasology.gestalt.module.sandbox.API;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2021 The Terasology Foundation
*
* 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.
*/
@API package org.destinationsol.game.console.suggesters;

import org.terasology.gestalt.module.sandbox.API;
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import org.destinationsol.game.SolObject;
import org.destinationsol.game.drawables.DrawableLevel;
import org.destinationsol.game.drawables.RectSprite;
import org.terasology.gestalt.module.sandbox.API;

/**
* AnimatedRectSprites are a specialised variant of RectSprites that can play a single animation, based off a sprite-sheet texture
*/
@API
public class AnimatedRectSprite extends RectSprite {
private Animation<TextureAtlas.AtlasRegion> spriteAnimation;
private float animationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class Health implements Component<Health> {
public float currentHealth = 30;

@Override
public void copy(Health other) {
public void copyFrom(Health other) {
this.maxHealth = other.maxHealth;
this.currentHealth = other.currentHealth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Angle implements Component<Angle> {
private float angle;

@Override
public void copy(Angle other) {
public void copyFrom(Angle other) {
this.angle = other.angle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Position implements Component<Position> {
public Vector2 position = new Vector2();

@Override
public void copy(Position other) {
public void copyFrom(Position other) {
position = other.position.cpy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Velocity implements Component<Velocity> {
public Vector2 velocity = new Vector2();

@Override
public void copy(Velocity other) {
public void copyFrom(Velocity other) {
velocity = other.velocity.cpy();
}
}
40 changes: 37 additions & 3 deletions engine/src/main/java/org/destinationsol/modules/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,34 @@ public class ModuleManager {
"com.badlogic.gdx.graphics.g2d",
// The hull config exposes a box2d body instance
"com.badlogic.gdx.physics",
"com.badlogic.gdx.physics.box2d"
"com.badlogic.gdx.physics.box2d",
// NUI doesn't use gestalt's @API annotations anymore, so they are replicated here
"org.terasology.input",
"org.terasology.input.device",
"org.terasology.input.device.nulldevices",
"org.terasology.nui",
"org.terasology.nui.asset",
"org.terasology.nui.asset.font",
"org.terasology.nui.canvas",
"org.terasology.nui.databinding",
"org.terasology.nui.events",
"org.terasology.nui.itemRendering",
"org.terasology.nui.layouts",
"org.terasology.nui.layouts.miglayout",
"org.terasology.nui.layouts.relative",
"org.terasology.nui.properties",
"org.terasology.nui.reflection",
"org.terasology.nui.skin",
"org.terasology.nui.translate",
"org.terasology.nui.util",
"org.terasology.nui.widgets",
"org.terasology.nui.widgets.treeView",
"org.terasology.nui.widgets.types",
"org.terasology.nui.widgets.types.builtin",
"org.terasology.nui.widgets.types.builtin.object",
"org.terasology.nui.widgets.types.builtin.util",
"org.terasology.nui.widgets.types.math",
"org.terasology.reflection.metadata"
};
protected static final Class<?>[] CLASS_WHITELIST = new Class<?>[]{
InvocationTargetException.class,
Expand Down Expand Up @@ -162,7 +189,14 @@ public class ModuleManager {
org.terasology.gestalt.entitysystem.entity.EntityManager.class,
org.terasology.gestalt.entitysystem.event.EventResult.class,
org.terasology.gestalt.entitysystem.event.ReceiveEvent.class,
org.terasology.gestalt.entitysystem.prefab.GeneratedFromRecipeComponent.class
org.terasology.gestalt.entitysystem.prefab.Prefab.class,
org.terasology.gestalt.entitysystem.prefab.GeneratedFromRecipeComponent.class,
/* NUI classes */
org.terasology.input.device.InputDevice.class,
org.terasology.input.device.KeyboardDevice.class,
org.terasology.input.device.MouseDevice.class,
org.terasology.reflection.MappedContainer.class,
org.terasology.reflection.TypeInfo.class
};

protected static ModuleEnvironment environment;
Expand Down Expand Up @@ -229,7 +263,7 @@ public void loadEnvironment(Set<Module> modules) {
scanner.scan(reflections);
Policy.setPolicy(new ModuleSecurityPolicy());
System.setSecurityManager(new ModuleSecurityManager());
environment = new ModuleEnvironment(modules,permissionFactory);
environment = new ModuleEnvironment(modules, permissionFactory);
}

public ModuleEnvironment getEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class Renderable implements Component<Renderable> {
public boolean isInvisible;

@Override
public void copy(Renderable other) {
public void copyFrom(Renderable other) {
ArrayList<RenderableElement> newElements = new ArrayList<>();
for (int index = 0; index < other.elements.size(); index++) {
RenderableElement data = new RenderableElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Size implements Component<Size> {
public float size;

@Override
public void copy(Size other) {
public void copyFrom(Size other) {
this.size = other.size;
}
}
18 changes: 18 additions & 0 deletions engine/src/main/java/org/destinationsol/ui/nui/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2021 The Terasology Foundation
*
* 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.
*/
@API package org.destinationsol.ui.nui;

import org.terasology.gestalt.module.sandbox.API;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2021 The Terasology Foundation
*
* 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.
*/
@API package org.destinationsol.ui.nui.screens;

import org.terasology.gestalt.module.sandbox.API;
Loading

0 comments on commit eca02c8

Please sign in to comment.