Commit c7e592ee authored by Lukas Marik's avatar Lukas Marik

#940 create descriptor for wall object, prepare points detection

parent d78793ec
Subproject commit 5afacc743c05cc8a95df68a91f13ceb93d8ba0e2
Subproject commit 45782042c558fff143a6b7a4c9b00a1a664a1532
......@@ -50,6 +50,7 @@ import cz.nic.tablexia.game.games.protocol.controller.PositionCounter;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObject;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.ObjectModel;
import cz.nic.tablexia.game.games.protocol.gameobjects.descriptors.WallObjectDescriptor;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
import cz.nic.tablexia.game.games.protocol.model.CardsWidget;
import cz.nic.tablexia.game.games.protocol.model.RoomGroup;
......@@ -526,9 +527,9 @@ public class ProtocolGame extends AbstractTablexiaGame<ProtocolGameState> {
addGameObjectToRoom(object, xPosition, yPosition, new PositionTransfer(RoomPosition.FURNITURE, furnitureType, null));
} else if (positionPairs.get(0).getObjectType() instanceof WallType) {
WallType wallType = (WallType) positionPairs.get(0).getObjectType();
WallType.WallObjectPosition position = WallType.WallObjectPosition.getWallObjectPositionByType(objectType);
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(objectType);
float[] fixRatio = position.getWallRatio(getGameDifficulty(), wallType);
float[] fixRatio = descriptor.getFixRatio(wallType);
float xPosition = roomGroup.getWidth() * fixRatio[0] - object.getWallPoint().x;
float yPosition = roomGroup.getHeight() * fixRatio[1] - object.getWallPoint().y;
......
......@@ -30,6 +30,7 @@ import com.badlogic.gdx.utils.Align;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.games.protocol.ProtocolGame;
import cz.nic.tablexia.game.games.protocol.controller.RoomPosition;
import cz.nic.tablexia.game.games.protocol.gameobjects.descriptors.WallObjectDescriptor;
import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.Furniture;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
import cz.nic.tablexia.game.games.protocol.utils.ProtocolDragListener;
......@@ -83,6 +84,11 @@ public class GameObject extends ObjectModel {
private WallType wallPositionType;
private Vector2 positionBeforeScale;
//Wall control points;
private Vector2 rBPoint;
private Vector2 lBPoint;
private Vector2 lTPoint;
private Vector2 rTPoint;
private TablexiaLabel descriptionLabel;
private TextureRegion cardDrawable;
......@@ -123,14 +129,25 @@ public class GameObject extends ObjectModel {
float[] pointRatio = type.getPutRatio();
float minWidth = objectImage.getDrawable().getMinWidth();
float minHeight = objectImage.getDrawable().getMinHeight();
if(pointRatio != null) {
putPoint = new Vector2(objectImage.getDrawable().getMinWidth() * pointRatio[0], objectImage.getDrawable().getMinHeight() * pointRatio[1]);
putPoint = new Vector2(minWidth * pointRatio[0], minHeight * pointRatio[1]);
}
float[] wallRatio = type.getWallRatio();
if(wallRatio != null){
wallPoint = new Vector2(objectImage.getDrawable().getMinWidth() * wallRatio[0], objectImage.getDrawable().getMinHeight() * wallRatio[1]);
wallPoint = new Vector2(minWidth * wallRatio[0], minHeight * wallRatio[1]);
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(type);
rBPoint = new Vector2(minWidth * descriptor.getrBRatio()[0], minHeight * descriptor.getrBRatio()[1]);
rTPoint = new Vector2(minWidth * descriptor.getrTRatio()[0], minHeight * descriptor.getrTRatio()[1]);
lBPoint = new Vector2(minWidth * descriptor.getlBRatio()[0], minHeight * descriptor.getlBRatio()[1]);
lTPoint = new Vector2(minWidth * descriptor.getlTRatio()[0], minHeight * descriptor.getlTRatio()[1]);
}
}
......
/*
* Copyright (C) 2018 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.game.games.protocol.gameobjects.descriptors;
import java.util.Arrays;
import java.util.List;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
public enum WallObjectDescriptor {
//TODO upravit fixni body pro kazdou zed
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, WallType.LEFT_WALL, new float[]{0.06f, 0.98f}, new float[]{0.1f, 0.04f}, new float[]{0.92f, 0.97f}, new float[]{0.93f, 0.03f}, Arrays.asList( new float[]{0.044f, 0.55f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, WallType.LEFT_WALL, new float[]{0.15f, 0.94f}, new float[]{0.04f, 0.31f}, new float[]{0.92f, 0.68f}, new float[]{0.78f, 0.04f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
LANDSCAPE (GameObjectType.LANDSCAPE, WallType.RIGHT_WALL, new float[]{0.07f, 0.62f}, new float[]{0.1f, 0.05f}, new float[]{0.88f, 0.93f}, new float[]{0.94f, 0.38f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
MIRROR (GameObjectType.MIRROR, WallType.RIGHT_WALL, new float[]{0.08f, 0.83f}, new float[]{0.28f, 0.03f}, new float[]{0.8f, 0.97f}, new float[]{0.94f, 0.18f}, Arrays.asList( new float[]{0.08f, 0.52f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.52f}));
private GameObjectType objectType;
private WallType wallOrientation;
private float[] rBRatio; //blue
private float[] lBRatio; //red
private float[] rTRatio; //yellow
private float[] lTRatio; //green
private List<float[]> wallFixRatio;
WallObjectDescriptor(GameObjectType objectType, WallType wallOrientation, float[] rBRatio, float[]lBRatio, float[]rTRatio, float[] lTRatio, List<float[]> wallFixRatio){
this.objectType = objectType;
this.wallOrientation = wallOrientation;
this.rBRatio = rBRatio;
this.lBRatio = lBRatio;
this.rTRatio = rTRatio;
this.lTRatio = lTRatio;
this.wallFixRatio = wallFixRatio;
}
public static WallObjectDescriptor getDescriptorByType(GameObjectType objectType){
for (WallObjectDescriptor descriptor: values()){
if(descriptor.objectType == objectType)
return descriptor;
}
throw new RuntimeException("Couldn't get wall descriptor for object: " + objectType);
}
public WallType getWallOrientation() {
return wallOrientation;
}
public float[] getFixRatio(WallType wallType){
return wallFixRatio.get(wallType.getOriginType());
}
public float[] getrBRatio() {
return rBRatio;
}
public float[] getlBRatio() {
return lBRatio;
}
public float[] getrTRatio() {
return rTRatio;
}
public float[] getlTRatio() {
return lTRatio;
}
}
......@@ -23,59 +23,19 @@ import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.TypeObjectDescriptor;
import java.util.Arrays;
import java.util.List;
/**
* Created by lmarik on 18.8.17.
*/
public enum WallType implements TypeObjectDescriptor{
LEFT_WALL (new Color(0xff0000ff), new float[]{0.08f, 0.66f}, new float[]{0.3f, 0.82f}),
MIDDLE_WALL (new Color(0xff00ffff), new float[]{0.5f, 0.80f}, new float[]{0.5f, 0.82f}),
RIGHT_WALL (new Color(0x00ffffff), new float[]{0.92f, 0.65f}, new float[]{0.91f, 0.5f});
public enum WallObjectPosition{
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
LANDSCAPE (GameObjectType.LANDSCAPE, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
MIRROR (GameObjectType.MIRROR, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f}));
private GameObjectType objectType;
private List<float[]> fixMediumRatio;
private List<float[]> fixHardRatio;
WallObjectPosition(GameObjectType objectType, List<float[]> fixMediumRatio, List<float[]> fixHardRatio){
this.objectType = objectType;
this.fixMediumRatio = fixMediumRatio;
this.fixHardRatio = fixHardRatio;
}
public float[] getWallRatio(GameDifficulty difficulty, WallType wallType){
int index = wallType.getOriginType();
return difficulty == GameDifficulty.MEDIUM ? fixMediumRatio.get(index) : fixHardRatio.get(index);
}
public static WallObjectPosition getWallObjectPositionByType(GameObjectType objectType) {
for (WallObjectPosition objectPosition: values()){
if(objectPosition.objectType == objectType)
return objectPosition;
}
throw new RuntimeException("Couldn't get wall position for object: " + objectType);
}
}
LEFT_WALL (new Color(0xff0000ff)),
MIDDLE_WALL (new Color(0xff00ffff)),
RIGHT_WALL (new Color(0x00ffffff));
private Color wallColor;
private float[] testMediumRatio;
private float[] testHardRatio;
WallType(Color wallColor, float[] testMediumRatio, float[] testHardRatio){
WallType(Color wallColor){
this.wallColor = wallColor;
this.testMediumRatio = testMediumRatio;
this.testHardRatio = testHardRatio;
}
public static WallType getWallTypeByGameObjectType(GameObjectType objectType) {
......@@ -97,11 +57,6 @@ public enum WallType implements TypeObjectDescriptor{
return null;
}
public float[] getTestRatio(GameDifficulty difficulty) {
return difficulty == GameDifficulty.MEDIUM ? testMediumRatio : testHardRatio;
}
@Override
public int getOriginType() {
return ordinal();
......
......@@ -40,6 +40,7 @@ import cz.nic.tablexia.game.games.protocol.controller.PositionPair;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObject;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.TypeObjectDescriptor;
import cz.nic.tablexia.game.games.protocol.gameobjects.descriptors.WallObjectDescriptor;
import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.Furniture;
import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.FurnitureType;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
......@@ -58,7 +59,6 @@ import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.resolvers.ProtocolScoreResolver;
import cz.nic.tablexia.testing.games.AbstractTestGame;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.button.GameImageTablexiaButton;
import cz.nic.tablexia.util.ui.button.TablexiaButton;
......@@ -298,7 +298,8 @@ public class TestGameProtocol extends AbstractTestGame {
correct();
}
float[] fixRatio = wallType.getTestRatio(difficulty);
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(gameObject.getType());
float[] fixRatio = descriptor.getFixRatio(wallType);
float xPosition = roomGroup.getX() + roomGroup.getWidth() * fixRatio[0]/* - gameObject.getCenterPosition().x*/;
float yPosition = roomGroup.getY() + roomGroup.getHeight() * fixRatio[1]/* - gameObject.getCenterPosition().y*/;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment