Crossfire JXClient, Trunk
AnimationSet.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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.map;
24 
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.Map;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
36 public class AnimationSet {
37 
42  @NotNull
43  private final Map<Integer, AnimationState> animations = new HashMap<>();
44 
51  public void add(final int tag, @NotNull final AnimationState animationState) {
52  freeAnimationState(animations.put(tag, animationState), tag);
53  animationState.allocate(tag);
54  }
55 
60  public void remove(final int tag) {
61  freeAnimationState(animations.remove(tag), tag);
62  }
63 
69  public void updateSpeed(final int tag, final int speed) {
70  final AnimationState animationState = animations.get(tag);
71  if (animationState == null) {
72  System.err.println("No animation at "+tag+" to update animation speed.");
73  return;
74  }
75 
76  animationState.setSpeed(speed);
77  }
78 
84  @NotNull
85  public Collection<AnimationState> getAllAnimationStates() {
86  return Collections.unmodifiableCollection(animations.values());
87  }
88 
95  private static void freeAnimationState(@Nullable final AnimationState animationState, final int tag) {
96  if (animationState != null) {
97  animationState.free(tag);
98  }
99  }
100 
101 }
com.realtime.crossfire.jxclient.map.AnimationState.setSpeed
void setSpeed(final int speed)
Definition: AnimationState.java:120
com.realtime.crossfire.jxclient.map.AnimationSet.add
void add(final int tag, @NotNull final AnimationState animationState)
Definition: AnimationSet.java:51
com.realtime.crossfire.jxclient.map.AnimationSet.getAllAnimationStates
Collection< AnimationState > getAllAnimationStates()
Definition: AnimationSet.java:85
com.realtime.crossfire.jxclient.map.AnimationSet.freeAnimationState
static void freeAnimationState(@Nullable final AnimationState animationState, final int tag)
Definition: AnimationSet.java:95
com.realtime.crossfire.jxclient.map.AnimationSet
Definition: AnimationSet.java:36
com.realtime.crossfire.jxclient.map.AnimationSet.animations
final Map< Integer, AnimationState > animations
Definition: AnimationSet.java:43
com.realtime.crossfire.jxclient.map.AnimationState
Definition: AnimationState.java:41
com.realtime.crossfire.jxclient.map.AnimationSet.updateSpeed
void updateSpeed(final int tag, final int speed)
Definition: AnimationSet.java:69