Crossfire JXClient, Trunk
AnimationMap.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.HashMap;
26 import java.util.HashSet;
27 import java.util.Map;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
36 public class AnimationMap {
37 
42  @NotNull
43  private final Map<Location, AnimationState> animations = new HashMap<>();
44 
48  public void clear() {
49  animations.clear();
50  }
51 
58  public void add(@NotNull final Location location, @NotNull final AnimationState animationState) {
59  freeAnimationState(animations.put(location, animationState), location);
60  animationState.allocate(location);
61  }
62 
67  public void remove(@NotNull final Location location) {
68  freeAnimationState(animations.remove(location), location);
69  }
70 
76  public void updateSpeed(@NotNull final Location location, final int speed) {
77  final AnimationState animationState = animations.get(location);
78  if (animationState == null) {
79  System.err.println("No animation at "+location+" to update animation speed.");
80  return;
81  }
82 
83  animationState.setSpeed(speed);
84  }
85 
93  public void scroll(final int dx, final int dy, final int width, final int height) {
94  final Iterable<AnimationState> tmp = new HashSet<>(animations.values());
95  animations.clear();
96  for (AnimationState animationState : tmp) {
97  animationState.scroll(dx, dy, width, height);
98  for (Location location : animationState) {
99  animations.put(location, animationState);
100  }
101  }
102  }
103 
110  private static void freeAnimationState(@Nullable final AnimationState animationState, @NotNull final Location location) {
111  if (animationState != null) {
112  animationState.free(location);
113  }
114  }
115 
116 }
com.realtime.crossfire.jxclient.map.AnimationMap.add
void add(@NotNull final Location location, @NotNull final AnimationState animationState)
Definition: AnimationMap.java:58
com.realtime.crossfire.jxclient.map.AnimationState.setSpeed
void setSpeed(final int speed)
Definition: AnimationState.java:120
com.realtime.crossfire.jxclient.map.AnimationMap
Definition: AnimationMap.java:36
com.realtime.crossfire.jxclient.map.AnimationMap.scroll
void scroll(final int dx, final int dy, final int width, final int height)
Definition: AnimationMap.java:93
com.realtime.crossfire.jxclient.map.Location
Definition: Location.java:32
com.realtime.crossfire.jxclient.map.AnimationMap.animations
final Map< Location, AnimationState > animations
Definition: AnimationMap.java:43
com.realtime.crossfire.jxclient.map.AnimationMap.clear
void clear()
Definition: AnimationMap.java:48
com.realtime.crossfire.jxclient.map.AnimationState
Definition: AnimationState.java:41
com.realtime.crossfire.jxclient.map.AnimationMap.freeAnimationState
static void freeAnimationState(@Nullable final AnimationState animationState, @NotNull final Location location)
Definition: AnimationMap.java:110
com.realtime.crossfire.jxclient.map.AnimationMap.updateSpeed
void updateSpeed(@NotNull final Location location, final int speed)
Definition: AnimationMap.java:76