如何正确排序 Plist?

发布于 2025-01-01 03:32:14 字数 1819 浏览 2 评论 0原文

好吧,我做了一个小游戏,在游戏结束时给我 3 个数据。

分数、硬币和等级。为此,我添加了排名。 (目前这是手动完成的,直到我弄清楚如何根据分数更改排名#)

所以,这是 Plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"         "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>entry1</key>
<dict>
    <key>rank</key>
    <string>1</string>
    <key>level</key>
    <string>9</string>
    <key>score</key>
    <string>1999</string>
    <key>coins</key>
    <string>764</string>
</dict>
<key>entry2</key>
<dict>
    <key>rank</key>
    <string>2</string>
    <key>level</key>
    <string>8</string>
    <key>score</key>
    <string>1799</string>
    <key>coins</key>
    <string>375</string>
</dict>
<key>entry3</key>
<dict>
    <key>rank</key>
    <string>3</string>
    <key>level</key>
    <string>6</string>
    <key>score</key>
    <string>1599</string>
    <key>coins</key>
    <string>894</string>
</dict>
<key>entry4</key>
<dict>
    <key>rank</key>
    <string>4</string>
    <key>level</key>
    <string>3</string>
    <key>score</key>
    <string>799</string>
    <key>coins</key>
    <string>523</string>
</dict>
</dict>
</plist>

我希望能够按排名、硬币或级别对高分面板进行排序。

我尝试了很多方法来实现它,但没有任何方法能达到我想要的效果。

因此,如果有人能给我一些提示,我将非常感激。

提前致谢。

Well, I made a little game with give me at the end of the game, 3 datas.

Score, Coins, and Level. To this, I added the rank. (Which is manually done at the moment until I figure out how to change the rank # depending on the score)

So, here is the Plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"         "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>entry1</key>
<dict>
    <key>rank</key>
    <string>1</string>
    <key>level</key>
    <string>9</string>
    <key>score</key>
    <string>1999</string>
    <key>coins</key>
    <string>764</string>
</dict>
<key>entry2</key>
<dict>
    <key>rank</key>
    <string>2</string>
    <key>level</key>
    <string>8</string>
    <key>score</key>
    <string>1799</string>
    <key>coins</key>
    <string>375</string>
</dict>
<key>entry3</key>
<dict>
    <key>rank</key>
    <string>3</string>
    <key>level</key>
    <string>6</string>
    <key>score</key>
    <string>1599</string>
    <key>coins</key>
    <string>894</string>
</dict>
<key>entry4</key>
<dict>
    <key>rank</key>
    <string>4</string>
    <key>level</key>
    <string>3</string>
    <key>score</key>
    <string>799</string>
    <key>coins</key>
    <string>523</string>
</dict>
</dict>
</plist>

I would like to be able to sort the highscore panels by rank, or coins, or level.

I've tried many things to achieve it but nothing does what I want.

So if anyone can give me some tips, I'll be very grateful.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-01-08 03:32:14

属性列表是存储数据的格式。要对其进行排序,您应该:

  1. 将数据读入适当的结构。
  2. 对结构中的数据进行排序。
  3. 将结构写回属性列表。

使用适当的结构很重要。属性列表支持两种容器对象:数组和字典。数组是有序列表;字典是键/值对的无序列表。看起来您现在正在使用一本字典,其中的键表示顺序。您应该更改存储方案以使用数组。然后您可以根据分数对数组进行排序并将其写入文件。

The property list is the format of the data in storage. To sort it, you should:

  1. Read the data into an appropriate structure.
  2. Sort the data in the structure.
  3. Write the structure back out to a property list.

Using an appropriate structure is important. Property lists support two kinds of container objects: arrays and dictionaries. Arrays are ordered lists; dictionaries are unordered lists of key/value pairs. It looks like you're using a dictionary right now, with keys that indicate order. You should change your storage scheme to use an array instead. Then you can just sort the array according to score and write it out to a file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文