是否有定制 Joda-Time 年表的优质资源?
我正在开发一款 RPG 风格的游戏,我想为该游戏开发一个具有独特月份、工作日、月份长度和日期长度的自定义日历。我最初计划覆盖 JDK 日历并尝试这样做;然而,我遇到了 Joda-Time,它对于这个目的来说似乎更有前途和更强大。但是,我无法弄清楚如何创建自己的年表,并且想知道是否有好的资源(我似乎找不到)来解释如何创建年表。
我尝试过设计一个超载的 AssembledChronology,但似乎无法让它满足我的需求。我想要的是一个 9 个月的日历,每月 40 天,每周 10 天。除此之外,每年还有最后一个“无月”的第十个月,仅持续 5 天。
任何帮助/建议表示赞赏。
I'm working on an RPG style game and I want to develop a custom Calendar for the game with unique months, week-days, month lengths, and day lengths. I was planning originally to override the JDK Calendar and attempt to do it that way; however, I ran across Joda-Time and it seemed more promising and powerful for this purpose. However, I'm having trouble figuring out to create my own Chronology and was wondering if there were good resources (that I can't seem to find) that explain how to create a Chronology.
I've tried come up with an overloaded AssembledChronology but can't seem to get it to fit my needs. And idea of what I want is a 9 month Calendar with 40 days a month, 10 days a week. In addition to that, there is a final "monthless" 10th month per year that only lasts 5 days.
Any help/advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的建议:不要尝试用 Joda Time 来做到这一点。
也许是可能的 - 尽管“无月”的月份听起来有点奇怪 - 并且 Joda Time 无疑是建立在灵活性之上的......但是让你的头脑了解
AssembledChronology、
DelegateDateTimeField
、DecolatedDateTimeField
等可能会让您感到困惑。哦,然后您需要时区的可能性。老实说,您的日历听起来非常简单 - 足够简单,从头开始实现一个简单的 API 可能比尝试详细了解 Joda Time 的实现更简单。
不要误会我的意思:我喜欢 Joda Time,因为我将它用于正常的业务应用程序。它比
Date
和Calendar
好得多,一旦你开始使用它就没有回头路了 - 但它很复杂。(就上下文而言,我将 Joda Time 移植到 .NET,或者至少是它的“引擎”部分。它有相当详细的文档记录,但到处都有大量的继承层次结构,这不利于“只是“创建一个新的日历系统。对于已经了解 Joda Time 细节的人来说,最终可能不需要很多代码,但它足够棘手,否则我会尽量避免它。)
当然,这真的取决于取决于您需要多丰富的 API。如果您确实想要 Joda Time 的所有功能,那么安装您的日历系统确实比您自己重新实现所有 API 更简单。另一方面,如果您主要只是想表达“这是我的自定义日历中的一个日期”,那么有更简单的方法可以实现它。就游戏中的日期/时间算术而言,您真正需要什么?
My advice: don't try to do it with Joda Time.
It may be possible - although a "monthless" month sounds a little odd - and Joda Time is certainly built on flexibility... but getting your head round all of the business of
AssembledChronology
,DelegatedDateTimeField
,DecoratedDateTimeField
etc is likely to do your head in. Oh, and then you need the possibility of time zones.Your calendar sounds quite simple to be honest - sufficiently simple that implementing a straightforward API from scratch may well be simpler than trying to understand the implementation of Joda Time in detail.
Don't get me wrong: I love Joda Time in terms of using it for normal business applications. It's so much better than
Date
andCalendar
, there's really no turning back once you've started using it - but it is complicated.(Just in terms of context, I'm porting Joda Time to .NET, or at least the "engine" part of it. It's fairly well documented but there are large inheritance hierarchies all over the place, and it's just not conducive to "just" creating a new calendar system. It may well not take a lot of code in the end for someone who already knows the details of Joda Time, but it's sufficiently tricky otherwise that I'd just try to avoid it.)
Of course, it really depends on how rich an API you need. If you really want all the power of Joda Time, then fitting your calendar system in would indeed be simpler than re-implementing all of the API yourself. On the other hand, if you're mostly just after a way of saying, "Here's a date in my custom calendar" then there are simpler ways of achieving it. What do you really need in terms of date/time arithmetic in your game?