Search in sources :

Example 1 with Context

use of com.b3dgs.lionengine.Context in project lionengine by b3dgs.

the class Loader method handle.

/**
 * Handle the sequence with its screen until no more sequence to run.
 *
 * @param config The configuration used.
 * @param sequenceClass The the next sequence to start.
 * @param arguments The sequence arguments list if needed by its constructor.
 * @throws LionEngineException If an exception occurred.
 */
private static void handle(Config config, Class<? extends Sequencable> sequenceClass, Object... arguments) {
    final Screen screen = Graphics.createScreen(config);
    try {
        screen.start();
        screen.awaitReady();
        final Context context = new ContextWrapper(screen);
        Sequencable nextSequence = UtilSequence.create(sequenceClass, context, arguments);
        while (nextSequence != null) {
            final Sequencable sequence = nextSequence;
            final String sequenceName = sequence.getClass().getName();
            Verbose.info(SEQUENCE_START, sequenceName);
            sequence.start(screen);
            Verbose.info(SEQUENCE_END, sequenceName);
            nextSequence = sequence.getNextSequence();
            sequence.onTerminated(nextSequence != null);
        }
    } finally {
        screen.dispose();
        config.getDevices().forEach(InputDevice::close);
    }
}
Also used : Context(com.b3dgs.lionengine.Context) InputDevice(com.b3dgs.lionengine.InputDevice) Screen(com.b3dgs.lionengine.graphic.Screen)

Example 2 with Context

use of com.b3dgs.lionengine.Context in project lionengine by b3dgs.

the class WorldTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Context() {

        @Override
        public int getX() {
            return 0;
        }

        @Override
        public int getY() {
            return 0;
        }

        @Override
        public int getWidth() {
            return 0;
        }

        @Override
        public int getHeight() {
            return 0;
        }

        @Override
        public <T extends InputDevice> T getInputDevice(Class<T> type) {
            return null;
        }

        @Override
        public Config getConfig() {
            return config;
        }
    });
    services.add(new SourceResolutionProvider() {

        @Override
        public int getWidth() {
            return output.getWidth();
        }

        @Override
        public int getHeight() {
            return output.getHeight();
        }

        @Override
        public int getRate() {
            return output.getRate();
        }
    });
    services.add(new Sequencer() {

        @Override
        public void end(Class<? extends Sequencable> nextSequenceClass, Object... arguments) {
        // Mock
        }

        @Override
        public void end() {
        // Mock
        }

        @Override
        public void load(Class<? extends Sequencable> nextSequenceClass, Object... arguments) {
        // Mock
        }

        @Override
        public void setSystemCursorVisible(boolean visible) {
        // Mock
        }
    });
    services.add(new Rasterbar() {

        @Override
        public void setRasterbarY(int y1, int y2) {
        // Mock
        }

        @Override
        public void setRasterbarOffset(int offsetY, int factorY) {
        // Mock
        }

        @Override
        public void renderRasterbar() {
        // Mock
        }

        @Override
        public void clearRasterbarColor() {
        // Mock
        }

        @Override
        public void addRasterbarColor(ImageBuffer buffer) {
        // Mock
        }
    });
}
Also used : Context(com.b3dgs.lionengine.Context) Sequencer(com.b3dgs.lionengine.graphic.engine.Sequencer) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Config(com.b3dgs.lionengine.Config) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) Rasterbar(com.b3dgs.lionengine.graphic.engine.Rasterbar) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Context

use of com.b3dgs.lionengine.Context in project lionengine by b3dgs.

the class DeviceControllerConfig method create.

/**
 * Create device controller from configuration.
 *
 * @param services The services reference (must not be <code>null</code>).
 * @param media The media configuration (must not be <code>null</code>).
 * @return The created controller.
 * @throws LionEngineException If unable to read node.
 */
public static DeviceController create(Services services, Media media) {
    final Context context = services.get(Context.class);
    final DeviceController controller = new DeviceControllerModel();
    final Collection<DeviceControllerConfig> configs = DeviceControllerConfig.imports(services, media);
    for (final DeviceControllerConfig config : configs) {
        final InputDevice device = context.getInputDevice(config.getDevice());
        if (device instanceof DevicePush) {
            final DevicePush push = (DevicePush) device;
            config.getHorizontal().forEach(h -> controller.addHorizontal(push, new DeviceActionModel(h, push)));
            config.getVertical().forEach(v -> controller.addVertical(push, new DeviceActionModel(v, push)));
            config.getFire().entrySet().forEach(e -> e.getValue().forEach(c -> controller.addFire(device, e.getKey(), new DeviceActionModel(c, push))));
        }
        if (device instanceof DevicePointer) {
            final DevicePointer pointer = (DevicePointer) device;
            controller.addHorizontal(pointer, () -> pointer.getMoveX());
            controller.addVertical(pointer, () -> -pointer.getMoveY());
        }
        if (config.isDisabled()) {
            controller.setDisabled(device.getName(), true, true);
        }
    }
    return controller;
}
Also used : Context(com.b3dgs.lionengine.Context) DevicePush(com.b3dgs.lionengine.io.DevicePush) LionEngineException(com.b3dgs.lionengine.LionEngineException) DevicePointer(com.b3dgs.lionengine.io.DevicePointer) DevicePush(com.b3dgs.lionengine.io.DevicePush) Collection(java.util.Collection) Check(com.b3dgs.lionengine.Check) Set(java.util.Set) HashMap(java.util.HashMap) DeviceControllerModel(com.b3dgs.lionengine.io.DeviceControllerModel) DeviceController(com.b3dgs.lionengine.io.DeviceController) Configurer(com.b3dgs.lionengine.game.Configurer) DeviceMapper(com.b3dgs.lionengine.io.DeviceMapper) ArrayList(java.util.ArrayList) InputDevice(com.b3dgs.lionengine.InputDevice) HashSet(java.util.HashSet) Constant(com.b3dgs.lionengine.Constant) Context(com.b3dgs.lionengine.Context) DeviceAxis(com.b3dgs.lionengine.io.DeviceAxis) List(java.util.List) XmlReader(com.b3dgs.lionengine.XmlReader) Services(com.b3dgs.lionengine.game.feature.Services) Map(java.util.Map) Media(com.b3dgs.lionengine.Media) DeviceActionModel(com.b3dgs.lionengine.io.DeviceActionModel) DeviceControllerModel(com.b3dgs.lionengine.io.DeviceControllerModel) InputDevice(com.b3dgs.lionengine.InputDevice) DeviceController(com.b3dgs.lionengine.io.DeviceController) DevicePointer(com.b3dgs.lionengine.io.DevicePointer) DeviceActionModel(com.b3dgs.lionengine.io.DeviceActionModel)

Aggregations

Context (com.b3dgs.lionengine.Context)3 InputDevice (com.b3dgs.lionengine.InputDevice)2 Check (com.b3dgs.lionengine.Check)1 Config (com.b3dgs.lionengine.Config)1 Constant (com.b3dgs.lionengine.Constant)1 LionEngineException (com.b3dgs.lionengine.LionEngineException)1 Media (com.b3dgs.lionengine.Media)1 XmlReader (com.b3dgs.lionengine.XmlReader)1 Configurer (com.b3dgs.lionengine.game.Configurer)1 Services (com.b3dgs.lionengine.game.feature.Services)1 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)1 Screen (com.b3dgs.lionengine.graphic.Screen)1 Rasterbar (com.b3dgs.lionengine.graphic.engine.Rasterbar)1 Sequencer (com.b3dgs.lionengine.graphic.engine.Sequencer)1 SourceResolutionProvider (com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider)1 DeviceActionModel (com.b3dgs.lionengine.io.DeviceActionModel)1 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)1 DeviceController (com.b3dgs.lionengine.io.DeviceController)1 DeviceControllerModel (com.b3dgs.lionengine.io.DeviceControllerModel)1 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)1