Crossfire JXClient, Trunk  R20561
GaugeUpdaterParser.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.skin.io;
23 
33 import java.io.IOException;
34 import org.jetbrains.annotations.NotNull;
35 
40 public class GaugeUpdaterParser {
41 
45  @NotNull
46  private final Stats stats;
47 
51  @NotNull
52  private final ItemSet itemSet;
53 
57  @NotNull
58  private final SkillSet skillSet;
59 
66  public GaugeUpdaterParser(@NotNull final Stats stats, @NotNull final ItemSet itemSet, @NotNull final SkillSet skillSet) {
67  this.stats = stats;
68  this.itemSet = itemSet;
69  this.skillSet = skillSet;
70  }
71 
79  @NotNull
80  public GaugeUpdater parseGaugeUpdater(@NotNull final String name, @NotNull final ExperienceTable experienceTable) throws IOException {
81  try {
82  return new StatGaugeUpdater(experienceTable, StatsParser.parseStat(name), stats, itemSet);
83  } catch (final IllegalArgumentException ignored) {
84  // ignore
85  }
86 
87  if (name.startsWith("SKILL_")) {
88  return new SkillGaugeUpdater(experienceTable, skillSet.getNamedSkill(name.substring(6).replaceAll("_", " "), -1));
89  }
90 
91  if (name.startsWith("ACTIVE_SKILL_")) {
92  return new ActiveSkillGaugeUpdater(experienceTable, name.substring(13).replaceAll("_", " "), stats);
93  }
94 
95  throw new IOException("invalid stat name: "+name);
96  }
97 
98 }
Skill getNamedSkill(@NotNull final String skillName, final int face)
Returns the skill instance for a given skill name.
Definition: SkillSet.java:141
final SkillSet skillSet
The SkillSet for looking up skill names.
GaugeUpdaterParser(@NotNull final Stats stats, @NotNull final ItemSet itemSet, @NotNull final SkillSet skillSet)
Creates a new instance.
Utility class to parse stat names.
Creates GaugeUpdater instances from string representations.
GaugeUpdater parseGaugeUpdater(@NotNull final String name, @NotNull final ExperienceTable experienceTable)
Parses a gauge updater value.
Updates the displayed values in a GUIGauge.
Model class maintaining the CfItems known to the player.
Definition: ItemSet.java:43
This is the representation of all the statistics of a player, like its speed or its experience...
Definition: Stats.java:43
Maintain the set of skills as sent by the server.
Definition: SkillSet.java:38
static int parseStat(@NotNull final String name)
Converts a stat name into a stat index.
A GaugeUpdater which monitors a stat value.