Skip to content

Commit

Permalink
Merge branch 'master' of https://git.lexteam.xyz/lex-game/Game
Browse files Browse the repository at this point in the history
oh god noooooo! bloody merges :(
  • Loading branch information
UnkDevE committed Feb 14, 2016
2 parents 609151b + 5a84df1 commit a3efe11
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 1 deletion.
54 changes: 54 additions & 0 deletions Core/src/main/java/xyz/lexteam/ygd/core/LexGame.java
@@ -0,0 +1,54 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core;

import org.slf4j.Logger;
import xyz.lexteam.ygd.core.service.ServiceManager;

import java.io.File;

/**
* Static access to {@link Game}.
*
* @author Jamie Mansfield
*/
public class LexGame {

private static final Game GAME = null;

public static Game getGame() {
return GAME;
}

/**
* @see Game#getServiceManager()
*/
public static ServiceManager getServiceManager() {
return GAME.getServiceManager();
}

/**
* @see Game#getSettings()
*/
public static GameSettings getSettings() {
return GAME.getSettings();
}

/**
* @see Game#getLogger()
*/
public static Logger getLogger() {
return GAME.getLogger();
}

/**
* @see Game#getDirectory()
*/
public static File getDirectory() {
return GAME.getDirectory();
}
}
@@ -0,0 +1,18 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core.event.module;

import xyz.lexteam.ygd.core.event.Event;

/**
* The event that is called to enable modules.
*
* @author Jamie Mansfield
*/
public class ModulesEnableEvent implements Event {

}
21 changes: 21 additions & 0 deletions Core/src/main/java/xyz/lexteam/ygd/core/module/Module.java
@@ -0,0 +1,21 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core.module;

/**
* This annotation will be used by modules.
*
* @author Jamie Mansfield
*/
public @interface Module {

String id();

String name();

String version();
}
@@ -0,0 +1,23 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core.module;

/**
* Wrapper around classes with the {@link Module} annotation.
*
* @author Jamie Mansfield
*/
public interface ModuleContainer {

String getId();

String getName();

String getVersion();

Object getInstance();
}
@@ -0,0 +1,39 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core.service.module;

import xyz.lexteam.ygd.core.module.ModuleContainer;

import java.io.File;
import java.util.Set;

/**
* The module service.
*
* @author Jamie Mansfield
*/
public interface ModuleService {

/**
* Loads all the modules from the given directory.
*
* @param directory The directory.
*/
void loadModules(File directory);

/**
* Enables all the loaded modules.
*/
void enableModules();

/**
* Gets all the loaded modules.
*
* @return The loaded modules.
*/
Set<ModuleContainer> getModules();
}
@@ -0,0 +1,46 @@
/*
* This file is part of lex-game, licensed All Rights Reserved.
*
* Copyright (c) 2015-2016, Lexteam <http://www.lexteam.xyz/>
* All Rights Reserved.
*/
package xyz.lexteam.ygd.core.service.module;

import com.google.common.collect.Sets;
import xyz.lexteam.ygd.core.event.module.ModulesEnableEvent;
import xyz.lexteam.ygd.core.module.ModuleContainer;
import xyz.lexteam.ygd.core.service.event.Events;

import java.io.File;
import java.io.FileFilter;
import java.util.Set;
import java.util.jar.JarFile;

/**
* A simple implementation of {@link ModuleService}.
*
* @author Jamie Mansfield
*/
public class SimpleModuleService implements ModuleService {

private Set<ModuleContainer> modules = Sets.newHashSet();

@Override
public void loadModules(File directory) {
for (File f : directory.listFiles(pathname -> {
return pathname.getName().endsWith(".jar");
})) {
// TODO:
}
}

@Override
public void enableModules() {
Events.post(new ModulesEnableEvent());
}

@Override
public Set<ModuleContainer> getModules() {
return this.modules;
}
}
Expand Up @@ -12,7 +12,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class GameEvents {
public final class GameEvents {

public static void initialise(IEventBus eventBus) throws NoSuchFieldException, IllegalAccessException {
Field field = Events.class.getDeclaredField("EVENT_BUS");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/xyz/lexteam/ygd/game/GameLaunch.java
Expand Up @@ -12,6 +12,7 @@
import xyz.lexteam.eventbus.SimpleEventBus;
import xyz.lexteam.ygd.core.Game;
import xyz.lexteam.ygd.core.service.ProviderExistsException;
import xyz.lexteam.ygd.core.service.event.Events;
import xyz.lexteam.ygd.game.impl.meta.builder.tool.ToolAddConectionMetaBuilder;
import xyz.lexteam.ygd.game.impl.meta.builder.tool.ToolChangeDurationMetaBuilder;
import xyz.lexteam.ygd.game.impl.meta.processor.tool.ToolAddConnectionMetaProcessor;
Expand All @@ -24,6 +25,9 @@
import xyz.lexteam.meta.api.builder.Builders;
import xyz.lexteam.meta.api.value.ValueRegistry;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public final class GameLaunch {

private static Game game;
Expand All @@ -40,6 +44,7 @@ public static void main(String[] args) throws NoSuchFieldException, IllegalAcces
registerProcessors();
registerManipulatorBuilders();
registerValueProcessors();
initialiseLexGame();

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "lex-game v" + Game.VERSION;
Expand All @@ -52,6 +57,17 @@ public static Game getGame() {
return game;
}

public static void initialiseLexGame() throws IllegalAccessException, NoSuchFieldException {
Field field = xyz.lexteam.ygd.core.LexGame.class.getDeclaredField("GAME");
field.setAccessible(true);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

field.set(null, game);
}

private static void registerServices() throws ProviderExistsException {
getGame().getServiceManager().setProvider(IEventBus.class, new SimpleEventBus());
}
Expand Down

0 comments on commit a3efe11

Please sign in to comment.