Rangi42 / polished-map

A map and tileset editor for pokecrystal, pokered, and projects based on them. Written in C++ with FLTK.
https://hax.iimarckus.org/topic/7222/
Other
191 stars 22 forks source link

Preserve underscores between digits in map constant to filename conversion #56

Closed Rangi42 closed 3 years ago

Rangi42 commented 3 years ago

Event::warp_map_name converts the map constant to a label, e.g. UNION_CAVE_1F to UnionCave1F. However, it doesn't appropriately handle a case that doesn't come up in pokecrystal, when the constant has an underscore between digits. LUSTER_APARTMENT_1_1F should convert to LusterApartment1_1F, not LusterApartment11F.

Here's a Python implementation for testing:

def constant2label(constant):
    label = ''
    downcase = False
    for c in constant:
        if downcase:
            c = c.lower()
        if c == '_':
            downcase = False
        else:
            label += c
            downcase = not c.isdigit()
    return label
Rangi42 commented 3 years ago

This gives better results:

def constant2label(constant):
    label = ''
    wasletter = False
    wasdigit = False
    maybeunderscore = False
    for c in constant:
        if c != '_':
            if maybeunderscore and c.isdigit():
                label += '_'
            if wasletter:
                c = c.lower()
            label += c
            maybeunderscore = False
        elif wasdigit:
            maybeunderscore = True
        wasletter = c.isalpha()
        wasdigit = c.isdigit()
    return label