Commit 4e3db0c3 authored by v.tarantik's avatar v.tarantik

#40 Encyclopedia content parsing with Jackson

parent 719c19f8
......@@ -59,10 +59,13 @@ allprojects {
sqlDroidVersion = '1.0.3'
sqlLiteJdbcVersion = '3.8.10.1'
guavaVersion = '18.0'
gsonVersion = '2.3.1'
jacksonVersion = '2.6.1'
}
repositories {
mavenCentral()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
......@@ -119,6 +122,31 @@ task prepareSoundAssets(dependsOn: prepareAssets) {
}
}
task prepareJsonAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")
doLast {
new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
sectionDir.eachDir() { atlasDir ->
task("${name}_" + atlasDir.name + "_" + langDir.name, type: Copy) {
from atlasDir
into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
include '**/*.json'
includeEmptyDirs false
eachFile { FileCopyDetails fcd ->
fcd.setPath(fcd.getRelativePath().toString().replace(File.separator, '.'))
}
}.execute()
}
}
}
}
}
task prepareGraphicAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
......@@ -147,7 +175,7 @@ task prepareGraphicAssets(dependsOn: prepareAssets) {
}
}
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJsonAssets]) {
doLast {
new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->
......@@ -341,8 +369,13 @@ project(":core") {
compile "net.engio:mbassador:$mbassadorVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.google.guava:guava:$guavaVersion"
compile "com.google.code.gson:gson:$gsonVersion"
compile "com.fasterxml.jackson.core:jackson-core:2.6.1"
compile "com.fasterxml.jackson.core:jackson-annotations:2.6.1"
compile "com.fasterxml.jackson.core:jackson-databind:2.6.1"
testCompile "junit:junit:4.11"
testCompile "junit:junit:4.11"
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
......
[
{"cz.nic.tablexia.screen.encyclopedia.content.model.TextContent":{"value":"Serialita....."}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.Hint":{"value":{"key":{"value":"image2.png"},"value":{"value":"Zkuste si..."},"full":true,"empty":false}}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.ImageContent":{"value":"image.png"}},
]
[
{"cz.nic.tablexia.screen.encyclopedia.content.model.TextContent":{"value":"Serialita....."}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.Hint":{"value":{"key":{"value":"image2.png"},"value":{"value":"Zkuste si..."}}}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.ImageContent":{"value":"image.png"}}
]
[
{"cz.nic.tablexia.screen.encyclopedia.content.model.TextContent":{"value":"Serialita....."}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.Hint":{"value":{"key":{"value":"image2.png"},"value":{"value":"Zkuste si..."}}}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.ImageContent":{"value":"image.png"}}
]
[
{"cz.nic.tablexia.screen.encyclopedia.content.model.TextContent":{"value":"Serialita....."}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.Hint":{"value":{"key":{"value":"image2.png"},"value":{"value":"Zkuste si..."}}}},
{"cz.nic.tablexia.screen.encyclopedia.content.model.ImageContent":{"value":"image.png"}}
]
......@@ -610,6 +610,10 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
return ApplicationFontManager.getInstance().getDefaultApplicationBoldFont();
}
public FileHandle getFile(String fileName) {
return TablexiaAbstractFileManager.getFileStoragePathFileHandle(storageType, screenAssetsPath + Utility.transformLocalAssetsPath(fileName));
}
public String getFormattedText(String key, Object... args) {
return textManager.getResult().format(key, args);
}
......
package cz.nic.tablexia.screen.encyclopedia.assets;
/**
* Created by Václav Tarantík on 25.8.15.
*/
public class EncyclopediaAssets {
public static final String ASSET_PREFIX = "screen_encyclopedia_";
public static final String BOOKMARK = ASSET_PREFIX +"bookmark";
}
package cz.nic.tablexia.screen.encyclopedia.content;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.screen.encyclopedia.content.model.Content;
/**
* Created by Václav Tarantík on 2.9.15.
*/
public class ContentParser {
public static List<Content> parseEncyclopediaPageContent(String jsonLine) {
ObjectMapper mapper = new ObjectMapper();
List<Content> list = null;
try {
list = mapper.readValue(jsonLine,new TypeReference<List<Content>>(){});
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
}
package cz.nic.tablexia.screen.encyclopedia.content.model;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* Created by Václav Tarantík on 3.9.15.
*/
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_OBJECT, property="@class")
public interface Content<T> {
public void setValue(T value);
public T getValue();
}
package cz.nic.tablexia.screen.encyclopedia.content.model;
import net.dermetfan.utils.Pair;
import cz.nic.tablexia.screen.encyclopedia.content.model.Content;
/**
* Created by Václav Tarantík on 3.9.15.
*/
public class Hint implements Content<Pair> {
private Pair<ImageContent,TextContent> contentPair;
public Hint(){
//nothing here
}
public Hint(Pair<ImageContent,TextContent> contentPair){
this.contentPair = contentPair;
}
@Override
public void setValue(Pair value) {
contentPair = value;
}
@Override
public Pair getValue() {
return contentPair;
}
}
package cz.nic.tablexia.screen.encyclopedia.content.model;
/**
* Created by Václav Tarantík on 3.9.15.
*/
public class ImageContent implements Content<String> {
private String image;
public ImageContent(){
//nothing here
}
public ImageContent(String image){
this.image = image;
}
@Override
public void setValue(String value) {
image = value;
}
@Override
public String getValue() {
return image;
}
}
package cz.nic.tablexia.screen.encyclopedia.content.model;
import cz.nic.tablexia.screen.encyclopedia.content.model.Content;
/**
* Created by Václav Tarantík on 3.9.15.
*/
public class TextContent implements Content<String> {
private String text;
public TextContent(){
//nothing here
}
public TextContent(String text){
this.text = text;
}
@Override
public void setValue(String value) {
text = value;
}
@Override
public String getValue() {
return text;
}
}
package cz.nic.tablexia.screen.encyclopedia.menu;
/**
* Created by Václav Tarantík on 24.8.15.
*/
public enum MenuItem {
ABOUT_ENCYCLOPEDIA("encyclopedia_intro","about"),
DYSGRAPHIA("encyclopedia_dysgraphia","dysgraphia"),
DYSLEXIA("encyclopedia_dyslexia","dyslexia"),
DYSORTHOGRAPHIA("encyclopedia_dysorthographia","dysorthographia"),
MEMORY("encyclopedia_memory","memory"),
SPATIAL_ORIENTATION("encyclopedia_spatial_orientation","spatial orientation"),
SERIALITY("encyclopedia_seriality","seriality"),
FAMOUS_DYSLECTICS("encyclopedia_famous_dyslectics","famous dyslectics"),
AUDITORY_DISTINCTION("encyclopedia_auditory_distinction","auditory distinction"),
SPECIFIC_LEARNING_DISABILITIES("encyclopedia_learning_disabilities","specific_learning disabilities"),
VISUAL_DISTINCTION("encyclopedia_visual_distinction","visual distinction");
private String title;
private String resourcePage;
MenuItem(String title, String resourcePage){
this.title = title;
this.resourcePage = resourcePage;
}
public String getResourcePageName() {
return resourcePage;
}
public String getTitle() {
return title;
}
}
package cz.nic.tablexia.screen.encyclopedia.menu;
/**
* Created by Václav Tarantík on 25.8.15.
*/
public enum MenuItemType {
ENCYCLOPEDIA()
}
package cz.nic.tablexia.screen.encyclopedia.menu;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.SnapshotArray;
import cz.nic.tablexia.game.games.pursuit.model.Point;
import cz.nic.tablexia.screen.encyclopedia.widget.ResizableVerticalGroup;
/**
* Created by Václav Tarantík on 26.8.15.
*/
public class MenuWidget extends VerticalGroup {
private Array<MenuItem> menuItems;
private Drawable selectionDrawable;
private BitmapFont font;
private OnMenuItemClickListener onItemClickListener;
public MenuWidget(Point size, Array<MenuItem> menuItems, Drawable selectionDrawable, BitmapFont font, OnMenuItemClickListener onItemClickListener) {
this.menuItems = menuItems;
this.selectionDrawable = selectionDrawable;
selectionDrawable.setMinWidth(size.x);
this.onItemClickListener = onItemClickListener;
this.font = font;
initItems();
}
private void initItems(){
for (final MenuItem item: menuItems){
//TODO change shown text to resource
final TextButton menuItem = new TextButton(item.getResourcePageName(),createMenuItemStyle());
menuItem.removeListener(menuItem.getClickListener());
menuItem.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
for (Actor child : getChildren()) {
TextButton childButton = (TextButton)child;
if (childButton!=menuItem) {
childButton.setChecked(false);
}
}
if(!menuItem.isChecked()){
menuItem.setChecked(true);
onItemClickListener.onMenuItemClicked(item);
}
}
});
addActor(menuItem);
}
}
private TextButton.TextButtonStyle createMenuItemStyle(){
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(null,null,selectionDrawable,font);
style.fontColor = Color.BLACK;
return style;
}
public interface OnMenuItemClickListener{
void onMenuItemClicked(MenuItem clickedMenuItem);
}
}
package cz.nic.tablexia.screen.encyclopedia.widget;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import cz.nic.tablexia.game.games.pursuit.model.Point;
/**
* Created by Václav Tarantík on 24.8.15.
*/
public class ResizableHorizontalGroup extends HorizontalGroup{
private Point size;
public ResizableHorizontalGroup(Point size){
this.size = size;
}
@Override
public float getPrefWidth() {
return size.x;
}
@Override
public float getPrefHeight() {
return size.y;
}
}
package cz.nic.tablexia.screen.encyclopedia.widget;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import cz.nic.tablexia.game.games.pursuit.model.Point;
/**
* Created by Václav Tarantík on 25.8.15.
*/
public class ResizableList extends List {
private Point size;
public ResizableList(Point size, ListStyle style){
super(style);
// setSize(size.x,size.y);
}
}
package cz.nic.tablexia.screen.encyclopedia.widget;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
/**
* Created by Václav Tarantík on 25.8.15.
*/
public class ResizableScrollPane extends ScrollPane {
public ResizableScrollPane(Actor widget) {
super(widget);
}
@Override
public float getPrefWidth() {
return getWidth();
}
@Override
public float getPrefHeight() {
return getHeight();
}
}
......@@ -9,7 +9,7 @@ import cz.nic.tablexia.util.Log;
* Created by Václav Tarantík on 21.8.15.
*/
public class ResizableVerticalGroup extends VerticalGroup {
private Point size;
protected Point size;
public ResizableVerticalGroup(Point size){
this.size = size;
......
package cz.nic.tablexia.screen.encyclopedia.widget;
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
import cz.nic.tablexia.game.games.pursuit.model.Point;
/**
* Created by Václav Tarantík on 24.8.15.
*/
public class ResizableWidgetGroup extends WidgetGroup {
@Override
public float getPrefWidth() {
return getWidth();
}
@Override
public float getPrefHeight() {
return getHeight();
}
}
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