2016-10-17 159 views
0

所以这个程序我在有精灵。每个精灵都有其精灵可以拥有的帧数量的限制,并且我试图弄清楚如何学习该限制,以便我可以对其进行修改。但是我一直在阅读的代码对我来说确实很难。我一直在阅读它使用的一些东西(如DictionaryOut),但是当我尝试将该阅读应用于代码时,它只是分崩离析。因此,如果有人愿意分析代码并告诉我它说了什么,那就太好了。完整的可以发现here,但是这是我想特别为:需要帮助的理解代码

class FrameData { 
    Dictionary<FrameType, Dictionary<Enums.Direction, int>> frameCount; 
} 

public FrameData() { 
    frameCount = new Dictionary<FrameType, Dictionary<Enums.Direction, int>>(); 
} 

public void SetFrameCount(FrameType type, Enums.Direction dir, int count) { 
    if (frameCount.ContainsKey(type) == false) { 
     frameCount.Add(type, new Dictionary<Enums.Direction, int>()); 
    } 
    if (frameCount[type].ContainsKey(dir) == false) { 
     frameCount[type].Add(dir, count); 
    } else { 
     frameCount[type][dir] = count; 
    } 
} 

public int GetFrameCount(FrameType type, Enums.Direction dir) { 
    Dictionary<Enums.Direction, int> dirs = null; 
    if (frameCount.TryGetValue(type, out dirs)) { 
     int value = 0; 
     if (dirs.TryGetValue(dir, out value)) { 
      return value; 
     } else { 
      return 0; 
     } 
    } else { 
     return 0; 
    } 
} 
+0

尝试张贴的问题在这里-http://codereview.stackexchange.com/ – OldProgrammer

+3

@OldProgrammer这问题将不会成为Code Review的主题,因为它正在寻求关于代码如何工作的建议。 CR代码已经按照预期工作,并且可以理解,但您希望改进。 –

回答

1
//This bit declares the class. note that all the stuff after it should come inside the open and closed curly braces, so there's already a syntax error here. 
class FrameData { 
    Dictionary<FrameType, Dictionary<Enums.Direction, int>> frameCount; 
} 
// Public parameterless constructor. This gets called when someone creates an instance of the class, e.g. FrameData myframe = new FrameData() 
public FrameData() { 
    // initialize the instance variable frameCount with a new dictionary that takes a FrameType as the key and another dictionary of Enums.Direction and ints as key and value 
    frameCount = new Dictionary<FrameType, Dictionary<Enums.Direction, int>>(); 
} 
// Public method for adding or replacing a key and its value in the frameCount dictionary 
public void SetFrameCount(FrameType type, Enums.Direction dir, int count) { 
    // adds a new one if it didn't already have that key 
    if (frameCount.ContainsKey(type) == false) { 
     frameCount.Add(type, new Dictionary<Enums.Direction, int>()); 
    } 
    // adds a new key to the inner dictionary if it's not there 
    if (frameCount[type].ContainsKey(dir) == false) { 
     frameCount[type].Add(dir, count); 
    } else { 
     // otherwise just replaces what was already there 
     frameCount[type][dir] = count; 
    } 
} 
// fetches the nested value from the inner dictionary given the type and direction 
public int GetFrameCount(FrameType type, Enums.Direction dir) { 
    Dictionary<Enums.Direction, int> dirs = null; 
    if (frameCount.TryGetValue(type, out dirs)) { 
     int value = 0; 
     if (dirs.TryGetValue(dir, out value)) { 
      return value; 
     } else { 
      return 0; 
     } 
    } else { 
     return 0; 
    } 
} 
+0

谢谢!我想这可能不会是什么设置一个spritesheet可以有多少帧,然后......筛选更多文件的时间x: – Tapu