Fluorohydride / ygopro

A script engine for "yu-gi-oh!" and sample gui
GNU General Public License v2.0
1.85k stars 596 forks source link

DataManager: fix GetNumString #2603

Closed salix5 closed 1 month ago

salix5 commented 1 month ago

Base: #2602

aa1e281674e07b6e54d05f027167b5bb3724c3c5

std::wstring DataManager::GetNumString(int num, bool bracket) const;

Now GetNumString does not use global buffer. The return value is a wide string. Fix: Now the max number of cards in a pack is not limited by the size of numStrings.

8509aec134cbd584810808e16727dd0201b23a75 Rebuild class ustring16 from edopro version, which is modified by @edo9300 .

edopro changes:

remove allocator

Before:

template <typename TAlloc = irrAllocator<uchar16_t> >
class ustring16

After:

class ustring16

https://learn.microsoft.com/en-us/cpp/standard-library/allocators?view=msvc-170 If you are targeting C++11 and you need to write a new custom allocator, make it a minimal allocator if possible. Even if you have already implemented an old-style allocator, consider modifying it to be a minimal allocator in order to take advantage of the more efficient construct() method that will be provided for you automatically.

When creating a minimal allocator, do not implement any members except the ones shown in the example below:

  1. a converting copy constructor (see example)
  2. operator==
  3. operator!=
  4. allocate
  5. deallocate

class ustring16 is written before C++11, and it seems that its allocator irrAllocator is out-dated. I agree that removing the allocator is a better choice.

remove class _ustring16_iterator_access

Before:

typedef typename ustring16<TAlloc>::_ustring16_iterator_access access;

After:

typedef uchar32_t access;

class _ustring16_const_iterator does not use std::iterator

Before:

class _ustring16_const_iterator : public std::iterator <
    std::bidirectional_iterator_tag,    // iterator_category
    access,                             // value_type
    ptrdiff_t,                          // difference_type
    const access,                       // pointer
    const access                        // reference
>

After:

class _ustring16_const_iterator

https://en.cppreference.com/w/cpp/iterator/iterator

template<
    class Category,
    class T,
    class Distance = std::ptrdiff_t,
    class Pointer = T*,
    class Reference = T&
> struct iterator;

(deprecated in C++17)

https://en.cppreference.com/w/cpp/iterator/iterator_traits iterator_category value_type difference_type pointer reference

This template is just a helper, and we can explicitly define these traits.

remove class _ustring16_iterator

Now it only has const_iterator.

ygopro changes

Remove if constexpr

It is a C++17 feature. I am not sure if we are ready for C++17.

Add constructor for irr::core::wstring

core::stringw in current version does not have data().


8a8dc31b695a7671e68618a7d5b866580aef89a2 bcdaa5d73f25ed51651ccf3912415946a6eb9093 class CGUITTFont add drawUstring

void drawUstring(const core::ustring& text, const core::rect<s32>& position,
                video::SColor color, bool hcenter = false, bool vcenter = false,
                const core::rect<s32>* clip = 0);

Before: Convert the string from core::stringw to core::ustring

After: Use core::ustring directly.

343537ae85425a02e5642bef147885de6f339be5 update DrawShadowText

template<typename T>
inline void DrawShadowText(irr::gui::CGUITTFont* font, const T& text, const core::rect<s32>& position, 
const core::rect<s32>& padding, video::SColor color = 0xffffffff, 
video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const core::rect<s32>* clip = nullptr) 

Before: wchar_t => converted to core::stringw => converted to core::ustring a member function of Game

After: wchar_t or std::wstring => converted to core::ustring not a member function of Game

c457ae5e146ba38f47cfb271ee584c7dfafa031c c97b29c4acbca3ef1362d244c25ee7c19ddb26da fix Game::lpcstring fix DuelInfo::vic_string Now they are std::wstring. Keeping a pointer to local variable is dangerous and unnecessary.

@mercury233 @purerosefallen @Wind2009-Louse @edo9300