Skip to content
Merged

jq #20

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def populate_enum(self):
displayedValues = [locales[loc]("lang") for loc in locales]
self.menuOptions[3]["populatedValues"] = localeNames
self.menuOptions[3]["displayedValues"] = displayedValues
self.menuOptions[7]["displayedValues"] = layoutNames
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks-

self.menuOptions[7]["populatedValues"] = layoutNames

def translate(self):
Expand Down
Binary file modified requirements.txt
Binary file not shown.
100 changes: 50 additions & 50 deletions src/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def create_text(self, atPos = 0, lasts = 1, text = "", anchor = CENTER, align =
"text": text,
"anchor": anchor,
"align": align,
"offset": [0,0]
"offset": [0,0],
}
self.mapToEdit["notes"].append(newNote)
self.mapToEdit["notes"] = sorted(self.mapToEdit["notes"], key=lambda d: d['beatpos'][0]*4+d['beatpos'][1])
Expand Down Expand Up @@ -263,12 +263,12 @@ def input_colorPicker(self, val):
if val.name == "KEY_ESCAPE" or val.name == "KEY_ENTER":
self.colorPickerFieldSelected = False
else:
if val.name == "KEY_RIGHT" and self.colorPickerSelectedCol < 3:
self.colorPickerColor[self.colorPickerSelectedCol] += 1
if val.name in ("KEY_RIGHT", "KEY_SRIGHT") and self.colorPickerSelectedCol < 3:
self.colorPickerColor[self.colorPickerSelectedCol] += {'KEY_RIGHT': 1, 'KEY_SRIGHT': 10}[val.name]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh, didn't know that {}[] was a thing!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pattern of "keying" into a dictionary, instead of using if statements.

if a == "1":
    result = "2"
elif a == "2":
    result = "3"
else:
   result = "4"

can be changed to,

result = {"1": 2", "2": "3"}.get(a, "4")

self.colorPickerColor[self.colorPickerSelectedCol] = min(self.colorPickerColor[self.colorPickerSelectedCol], 255)
self.colorPickerFieldContent = hexcode_from_color_code(self.colorPickerColor)
if val.name == "KEY_LEFT" and self.colorPickerSelectedCol < 3:
self.colorPickerColor[self.colorPickerSelectedCol] -= 1
if val.name in ("KEY_LEFT", "KEY_SLEFT") and self.colorPickerSelectedCol < 3:
self.colorPickerColor[self.colorPickerSelectedCol] -= {'KEY_LEFT': 1, 'KEY_SLEFT': 10}[val.name]
self.colorPickerColor[self.colorPickerSelectedCol] = max(self.colorPickerColor[self.colorPickerSelectedCol], 0)
self.colorPickerFieldContent = hexcode_from_color_code(self.colorPickerColor)
if val.name == "KEY_DOWN":
Expand Down Expand Up @@ -1146,11 +1146,13 @@ def handle_input(self):
self.localConduc.currentBeat = 0
if val.name == "KEY_ESCAPE":
self.pauseMenuEnabled = True
if val.name == "KEY_RIGHT":
self.localConduc.currentBeat += (1/self.snap)*4
if val.name in ("KEY_RIGHT", "KEY_SRIGHT"):
multiplier = {"KEY_RIGHT": 1, "KEY_SRIGHT": 4}[val.name]
self.localConduc.currentBeat += (1/self.snap)*4*multiplier
print_at(0,term.height-4, term.clear_eol)
if val.name == "KEY_LEFT":
self.localConduc.currentBeat = max(self.localConduc.currentBeat - (1/self.snap)*4, 0)
if val.name in ("KEY_LEFT", "KEY_SLEFT"):
multiplier = {"KEY_LEFT": 1, "KEY_SLEFT": 4}[val.name]
self.localConduc.currentBeat = max(self.localConduc.currentBeat - (1/self.snap)*4*multiplier, 0)
print_at(0,term.height-4, term.clear_eol)
if val == "z":
self.keyPanelEnabled = True
Expand All @@ -1175,14 +1177,16 @@ def handle_input(self):

if self.mapToEdit["notes"] != []:
note = self.mapToEdit["notes"][self.selectedNote]
if val.name == "KEY_DOWN":
if val.name in ("KEY_DOWN", "KEY_SDOWN"):
multiplier = {"KEY_DOWN": 1, "KEY_SDOWN": 4}[val.name]
print_at(0,term.height-4, term.clear_eol)
self.selectedNote = min(self.selectedNote + 1, len(self.mapToEdit["notes"])-1)
self.selectedNote = min(self.selectedNote + (1*multiplier), len(self.mapToEdit["notes"])-1)
note = self.mapToEdit["notes"][self.selectedNote]
self.localConduc.currentBeat = (note["beatpos"][0] * 4 + note["beatpos"][1])
if val.name == "KEY_UP":
if val.name in ("KEY_UP", "KEY_SUP"):
multiplier = {"KEY_UP": 1, "KEY_SUP": 4}[val.name]
print_at(0,term.height-4, term.clear_eol)
self.selectedNote = max(self.selectedNote - 1, 0)
self.selectedNote = max(self.selectedNote - (1*multiplier), 0)
note = self.mapToEdit["notes"][self.selectedNote]
self.localConduc.currentBeat = (note["beatpos"][0] * 4 + note["beatpos"][1])

Expand All @@ -1195,36 +1199,34 @@ def handle_input(self):
print_at(0,term.height-4, term.clear_eol)
note["beatpos"] = [self.localConduc.currentBeat//4, self.localConduc.currentBeat%4]

if val == "d":
if val == "d" and "key" in note:
self.selectedNote = self.create_note(
note["beatpos"][0]*4 + note["beatpos"][1],
note["key"]
)
self.mapToEdit["notes"][self.selectedNote] = copy.deepcopy(note)

if note["type"] == "hit_object":
if note["type"] == "hit_object" and val:
screenPos = note["screenpos"]
calculatedPos = Game.calculatePosition(screenPos, 5, 3, term.width-10, term.height-11)
if val == "h":
# erase hitbox
if val in "hjklHJKL":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, interesting! again, didn't know that was a thing

print_at(calculatedPos[0]-1, calculatedPos[1]-1, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+0, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+1, f"{term.normal} ")
note["screenpos"][0] = max(round(note["screenpos"][0] - 1/(defaultSize[0]-1), 3), 0)
if val == "j":
print_at(calculatedPos[0]-1, calculatedPos[1]-1, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+0, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+1, f"{term.normal} ")
note["screenpos"][1] = min(round(note["screenpos"][1] + 1/defaultSize[1], 3), 1)
if val == "k":
print_at(calculatedPos[0]-1, calculatedPos[1]-1, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+0, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+1, f"{term.normal} ")
note["screenpos"][1] = max(round(note["screenpos"][1] - 1/defaultSize[1], 3), 0)
if val == "l":
print_at(calculatedPos[0]-1, calculatedPos[1]-1, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+0, f"{term.normal} ")
print_at(calculatedPos[0]-1, calculatedPos[1]+1, f"{term.normal} ")
note["screenpos"][0] = min(round(note["screenpos"][0] + 1/(defaultSize[0]-1), 3), 1)
# calculate new x/y position
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah previously that section was kinda badly written, thanks for rewriting it in a clearer way-

if val in "hH":
multiplier = {"h": 1, "H": 3}[val]
note["screenpos"][0] = max(round(note["screenpos"][0] - multiplier/(defaultSize[0]-1), 3), 0)
if val in "jJ":
multiplier = {"j": 1, "J": 2}[val]
note["screenpos"][1] = min(round(note["screenpos"][1] + multiplier/defaultSize[1], 3), 1)
if val in "kK":
multiplier = {"k": 1, "K": 2}[val]
note["screenpos"][1] = max(round(note["screenpos"][1] - multiplier/defaultSize[1], 3), 0)
if val in "lL":
multiplier = {"l": 1, "L": 3}[val]
note["screenpos"][0] = min(round(note["screenpos"][0] + multiplier/(defaultSize[0]-1), 3), 1)
if val == "e":
self.run_noteSettings(note, self.selectedNote, 0)
if val == "E":
Expand All @@ -1235,33 +1237,31 @@ def handle_input(self):
if val == "X":
note["color"] -= 1
note["color"] %= len(colors)
if note["type"] == "text":
if val == "h":
print(term.clear)
note["offset"][0] -= 1
if val == "j":
print(term.clear)
note["offset"][1] += 1
if val == "k":
print(term.clear)
note["offset"][1] -= 1
if val == "l":
print(term.clear)
note["offset"][0] += 1
if note["type"] == "text" and val:
if val in "hH":
multiplier = 3 if val.isupper() else 1
note["offset"][0] = note["offset"][0] - multiplier
if val in "jJ":
multiplier = 2 if val.isupper() else 1
note["offset"][1] = note["offset"][1] + multiplier
if val in "kK":
multiplier = 2 if val.isupper() else 1
note["offset"][1] = note["offset"][1] - multiplier
if val in "lL":
multiplier = 3 if val.isupper() else 1
note["offset"][0] = note["offset"][0] + multiplier
if val == "U":
print(term.clear)
note["length"] = max(note["length"] - (1/self.snap)*4, 0)
if val == "I":
print(term.clear)
note["length"] += (1/self.snap)*4
if val == "e":
self.run_noteSettings(note, self.selectedNote, 0)

if val == "x":
note["color"] += 1
note["color"] = note.get('color', -1) + 1
note["color"] %= len(colors)
if val == "X":
note["color"] -= 1
note["color"] = note.get('color', len(colors)) - 1
note["color"] %= len(colors)
if val == "c":
self.run_noteSettings(note, self.selectedNote, 2)
Expand Down Expand Up @@ -1385,4 +1385,4 @@ def __init__(self) -> None:
# loadedMenus["Editor"] = editor
editor.layoutname = "qwerty"
editor.layout = Game.setupKeys(None, editor.layoutname)
editor.loop()
editor.loop()
4 changes: 2 additions & 2 deletions src/termutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def print_lines_at(x, y, text, center = False, eol = False, color = None):

def print_image(x,y,imagePath,scale):
if os.path.exists(imagePath):
image = from_file(imagePath, width=scale)
image = BlockImage.from_file(imagePath, width=scale)
stringifiedImage = str(image)
print_lines_at(x, y, stringifiedImage)
return True
Expand Down Expand Up @@ -235,4 +235,4 @@ def __init__(self, x, y, width, height) -> None:
self.y = y
self.width = width
self.height = height
pass
pass