Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions C7/AnimationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,29 @@ public IniData getUnitINIData(string unitTypeName) {
}

public string getUnitFlicFilepath(UnitPrototype unit, MapUnit.AnimatedAction action) {
string directory = String.Format("Art/Units/{0}", unit.name);
IniData ini = getUnitINIData(unit.name);
string name = unit.name == "Army" ? "Army Ancient Times" : unit.name; // TODO: workaround for age specific army flic
string directory = String.Format("Art/Units/{0}", name);
IniData ini = getUnitINIData(name);
string filename = getFlicFileName(ini, action);
return directory.PathJoin(filename);
}

// The flic loading code parses the animations into a 2D array, where each row is an animation
// corresponding to a tile direction. flicRowToAnimationDirection maps row number -> direction.
private static TileDirection flicRowToAnimationDirection(int row) {
switch (row) {
case 0: return TileDirection.SOUTHWEST;
case 1: return TileDirection.SOUTH;
case 2: return TileDirection.SOUTHEAST;
case 3: return TileDirection.EAST;
case 4: return TileDirection.NORTHEAST;
case 5: return TileDirection.NORTH;
case 6: return TileDirection.NORTHWEST;
case 7: return TileDirection.WEST;
}
// TODO: I wanted to add a TileDirection.INVALID enum value when implementing this,
// but adding an INVALID value broke stuff: https://github.com/C7-Game/Prototype/issues/397
return TileDirection.NORTH;
return row switch {
0 => TileDirection.SOUTHWEST,
1 => TileDirection.SOUTH,
2 => TileDirection.SOUTHEAST,
3 => TileDirection.EAST,
4 => TileDirection.NORTHEAST,
5 => TileDirection.NORTH,
6 => TileDirection.NORTHWEST,
7 => TileDirection.WEST,
_ => TileDirection.NORTH,
};
}

public static void loadFlicAnimation(string path, string name, ref SpriteFrames frames, ref SpriteFrames tint) {
Expand All @@ -123,10 +124,9 @@ public static void loadFlicAnimation(string path, string name, ref SpriteFrames
}
}

public static void loadCursorAnimation(string path, ref SpriteFrames frames) {
public static void loadCursorAnimation(string path, string name, ref SpriteFrames frames) {
Flic flic = Util.LoadFlic(path);
int row = 0;
string name = "cursor";
frames.AddAnimation(name);

for (int col = 0; col < flic.Images.GetLength(1); col++) {
Expand Down Expand Up @@ -247,4 +247,8 @@ public double getDuration() {
double frameCount = flicSheet.indices.GetWidth() / flicSheet.spriteWidth;
return frameCount / 20.0; // Civ 3 anims often run at 20 FPS TODO: Do they all? How could we tell? Is it exactly 20 FPS?
}

public override string ToString() {
return $"{unit.name}: {action}";
}
}
25 changes: 11 additions & 14 deletions C7/AnimationTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public struct ActiveAnimation {

public Dictionary<string, ActiveAnimation> activeAnims = new Dictionary<string, ActiveAnimation>();

public long getCurrentTimeMS()
{
return DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
public long getCurrentTimeMS() => DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

private string getTileID(Tile tile)
{
Expand Down Expand Up @@ -58,7 +55,7 @@ private void startAnimation(string id, C7Animation anim, AutoResetEvent completi

public void startAnimation(MapUnit unit, MapUnit.AnimatedAction action, AutoResetEvent completionEvent, AnimationEnding ending)
{
startAnimation(unit.guid, civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
startAnimation(unit.id.ToString(), civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
}

public void startAnimation(Tile tile, AnimatedEffect effect, AutoResetEvent completionEvent, AnimationEnding ending)
Expand All @@ -69,16 +66,16 @@ public void startAnimation(Tile tile, AnimatedEffect effect, AutoResetEvent comp
public void endAnimation(MapUnit unit)
{
ActiveAnimation aa;
if (activeAnims.TryGetValue(unit.guid, out aa)) {
if (activeAnims.TryGetValue(unit.id.ToString(), out aa)) {
if (aa.completionEvent != null)
aa.completionEvent.Set();
activeAnims.Remove(unit.guid);
activeAnims.Remove(unit.id.ToString());
}
}

public bool hasCurrentAction(MapUnit unit)
{
return activeAnims.ContainsKey(unit.guid);
return activeAnims.ContainsKey(unit.id.ToString());
}

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(string id)
Expand All @@ -100,7 +97,7 @@ public bool hasCurrentAction(MapUnit unit)

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(MapUnit unit)
{
return getCurrentActionAndProgress(unit.guid);
return getCurrentActionAndProgress(unit.id.ToString());
}

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(Tile tile)
Expand All @@ -110,19 +107,19 @@ public bool hasCurrentAction(MapUnit unit)

public void update()
{
long currentTimeMS = (! endAllImmediately) ? getCurrentTimeMS() : long.MaxValue;
long currentTimeMS = !endAllImmediately ? getCurrentTimeMS() : long.MaxValue;
var keysToRemove = new List<string>();
foreach (var guidAAPair in activeAnims.Where(guidAAPair => guidAAPair.Value.endTimeMS <= currentTimeMS)) {
var (id, aa) = (guidAAPair.Key, guidAAPair.Value);
if (aa.completionEvent != null) {
if (aa.completionEvent is not null) {
aa.completionEvent.Set();
aa.completionEvent = null; // So event is only triggered once
}
if (aa.ending == AnimationEnding.Stop)
if (aa.ending == AnimationEnding.Stop) {
keysToRemove.Add(id);
}
}
foreach (var key in keysToRemove)
activeAnims.Remove(key);
keysToRemove.ForEach(key => activeAnims.Remove(key));
}

public MapUnit.Appearance getUnitAppearance(MapUnit unit)
Expand Down
2 changes: 1 addition & 1 deletion C7/Art/Title_Screen.jpg.import
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://ds3dwrouk7g55"
uid="uid://bkxkefpbld468"
path="res://.godot/imported/Title_Screen.jpg-067f940f7a89fae79632e2159c786062.ctex"
metadata={
"vram_texture": false
Expand Down
10 changes: 10 additions & 0 deletions C7/C7.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\.editorconfig = ..\.editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decompress", "..\_Console\Decompress\Decompress.csproj", "{B4174519-FD71-4CCD-842F-D9FC282551D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -114,6 +116,14 @@ Global
{8053F185-AA52-4876-8CF4-D08907FCA61A}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
{8053F185-AA52-4876-8CF4-D08907FCA61A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8053F185-AA52-4876-8CF4-D08907FCA61A}.Release|Any CPU.Build.0 = Release|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4174519-FD71-4CCD-842F-D9FC282551D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 13 additions & 2 deletions C7/C7Game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,17 @@ libraries = {
[connection signal="ShowSpecificAdvisor" from="." to="CanvasLayer/Advisor" method="OnShowSpecificAdvisor"]
[connection signal="TurnEnded" from="." to="CanvasLayer/Control/GameStatus" method="OnTurnEnded"]
[connection signal="TurnStarted" from="." to="CanvasLayer/Control/GameStatus" method="OnTurnStarted"]
[connection signal="BlinkyEndTurnButtonPressed" from="CanvasLayer/GameStatus" to="." method="OnPlayerEndTurn"]
[connection signal="toggled" from="CanvasLayer/SlideOutBar/SlideToggle" to="." method="_on_SlideToggle_toggled"]
[connection signal="pressed" from="CanvasLayer/SlideOutBar/VBoxContainer/DownButton" to="." method="_on_DownButton_pressed"]
[connection signal="pressed" from="CanvasLayer/SlideOutBar/VBoxContainer/RightButton" to="." method="_on_RightButton_pressed"]
[connection signal="pressed" from="CanvasLayer/SlideOutBar/VBoxContainer/LeftButton" to="." method="_on_LeftButton_pressed"]
[connection signal="pressed" from="CanvasLayer/SlideOutBar/VBoxContainer/UpButton" to="." method="_on_UpButton_pressed"]
[connection signal="value_changed" from="CanvasLayer/SlideOutBar/VBoxContainer/Zoom" to="." method="onSliderZoomChanged"]
[connection signal="pressed" from="CanvasLayer/SlideOutBar/VBoxContainer/QuitButton" to="." method="_on_QuitButton_pressed"]
[connection signal="pressed" from="CanvasLayer/ToolBar/MarginContainer/HBoxContainer/AdvisorButton" to="CanvasLayer/Advisor" method="ShowLatestAdvisor"]
[connection signal="pressed" from="CanvasLayer/ToolBar/MarginContainer/HBoxContainer/UiBarEndTurnButton" to="." method="_onEndTurnButtonPressed"]
[connection signal="BuildCity" from="CanvasLayer/PopupOverlay" to="." method="OnBuildCity"]
[connection signal="HidePopup" from="CanvasLayer/PopupOverlay" to="CanvasLayer/PopupOverlay" method="OnHidePopup"]
[connection signal="UnitDisbanded" from="CanvasLayer/PopupOverlay" to="." method="OnUnitDisbanded"]
[connection signal="BlinkyEndTurnButtonPressed" from="CanvasLayer/Control/GameStatus" to="." method="OnPlayerEndTurn"]
[connection signal="pressed" from="CanvasLayer/Control/ToolBar/MarginContainer/HBoxContainer/AdvisorButton" to="CanvasLayer/Advisor" method="ShowLatestAdvisor"]
[connection signal="pressed" from="CanvasLayer/Control/ToolBar/MarginContainer/HBoxContainer/UiBarEndTurnButton" to="." method="_onEndTurnButtonPressed"]
Expand All @@ -270,3 +278,6 @@ libraries = {
[connection signal="pressed" from="CanvasLayer/Control/SlideOutBar/VBoxContainer/UpButton" to="." method="_on_UpButton_pressed"]
[connection signal="value_changed" from="CanvasLayer/Control/SlideOutBar/VBoxContainer/Zoom" to="." method="_on_Zoom_value_changed"]
[connection signal="pressed" from="CanvasLayer/Control/SlideOutBar/VBoxContainer/QuitButton" to="." method="_on_QuitButton_pressed"]
[connection signal="HidePopup" from="CanvasLayer/PopupOverlay" to="CanvasLayer/PopupOverlay" method="CloseCurrentPopup"]
[connection signal="UnitDisbanded" from="CanvasLayer/PopupOverlay" to="." method="OnUnitDisbanded"]
[connection signal="SaveGame" from="CanvasLayer/PopupOverlay" to="." method="OnSaveGame"]
Loading