20 package net.sf.gridarta.model.gameobject;
22 import java.awt.Dimension;
23 import java.io.BufferedReader;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.LineNumberReader;
28 import java.io.Reader;
35 import org.apache.log4j.Category;
36 import org.apache.log4j.Logger;
37 import org.jetbrains.annotations.NotNull;
55 public static final int Y_DIM = 16;
83 public void load(@NotNull
final ErrorView errorView, @NotNull
final URL url) {
87 try (InputStream inputStream = url.openStream()) {
89 try (BufferedReader bufferedReader =
new BufferedReader(reader)) {
90 try (LineNumberReader lnr =
new LineNumberReader(bufferedReader)) {
94 boolean hasErrors =
false;
96 final String inputLine = lnr.readLine();
97 if (inputLine == null) {
100 final String line = inputLine.trim();
101 if (line.isEmpty() || line.startsWith(
"#")) {
109 if (numbers.length != 2) {
114 final Dimension d =
new Dimension();
117 d.width = Integer.parseInt(numbers[0]);
118 }
catch (
final NumberFormatException ignored) {
125 d.height = Integer.parseInt(numbers[1]);
126 }
catch (
final NumberFormatException ignored) {
135 if (yp < Y_DIM && !hasErrors) {
140 if (LOG.isInfoEnabled()) {
141 LOG.info(
"Loaded multi-part position data from '" + url +
"'");
147 }
catch (
final IOException ex) {
161 public int getXOffset(
final int shapeID,
final int positionID) {
163 return entry == null ? 0 : entry.
getXOffset(positionID);
175 public int getYOffset(
final int shapeID,
final int positionID) {
177 return entry == null ? 0 : entry.
getYOffset(positionID);
187 return entry == null ? 0 : entry.
getWidth();
197 return entry == null ? 0 : entry.
getHeight();
MultiPositionData(@NotNull final IsoMapSquareInfo isoMapSquareInfo)
Creates a new instance.
Utility class for string manipulation.
int getWidth()
Returns the total width of a multi-square image.
int getYOffset(final int shapeID, final int positionID)
Calculate the y-offset from the topmost pixel of the big face image and the default y-position (The d...
Convenience class for adding messages to a ErrorView instance using a fixed category name...
static final String MAP_ENCODING
Encoding to use for maps and other data.
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
static final int Y_DIM
Number of rows in the array.
static final Category LOG
The Logger for printing log messages.
static final Pattern PATTERN_SPACE
The pattern that matches a single space.
Defines possible error categories for ErrorView instances.
Interface for classes displaying error messages.
Base package of all Gridarta classes.
int getWidth(final int shapeID)
Returns the total width for a multi-square image.
Utility-class for Gridarta's I/O.
Encapsulated information about a multi-square image.
The MultiPositionData class stores an array of numbers which is required in order to calculate displa...
void load(@NotNull final ErrorView errorView, @NotNull final URL url)
Load the array-data from file.
final MultiPositionEntry [] data
Array with position data.
int getHeight()
Returns the total height of a multi-square image.
final IsoMapSquareInfo isoMapSquareInfo
The IsoMapSquareInfo to use.
int getXOffset(final int positionID)
Returns the x offset from the left-most pixel of the multi-square image and the default x position...
Provides information about isometric map squares.
int getYOffset(final int positionID)
Returns the y offset from the left-most pixel of the multi-square image and the default y position...
void addError(@NotNull final ErrorViewCategory category)
Adds an error message.
int getXOffset(final int shapeID, final int positionID)
Calculate the x-offset from the leftmost pixel of the big face image and the default x-position (The ...
int getHeight(final int shapeID)
Returns the total height for a multi-square image.