Skip to content

Commit 5bfbdd1

Browse files
committed
Add the cmd removal tool
1 parent 7df35ee commit 5bfbdd1

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

CmdRemoval/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# CmdRemovalTool
2+
3+
In order for all of your shit to work on Etterna 0.56 and onwards, you will need to replace every cmd call in your lua files(most likely your noteskins files), and this tool makes this process easier - so you probably should use it
4+
5+
## reqs
6+
7+
Python 3.5 or superior, available at: https://www.python.org/downloads/release/python-363/
8+
The actual script, available at: https://raw.githubusercontent.com/caiohsr14/etterna/master/CmdRemoval/sure.py (right click - save as sure.py)
9+
10+
## usage guide
11+
12+
First you move the downloaded script to the root folder of your game, or whatever folder you want to replace the cmds, in this example I'm using my noteskins folder:
13+
![image](img/image1.png?raw=true)
14+
15+
Then open your preferred command line tool and navigate to your folder, if you don't have any you can either open Windows Command Prompt, Windows Powershell or Git Bash
16+
For this one I'm going to use the Windows Command Prompt:
17+
![image](img/image2.png?raw=true)
18+
19+
From here, we simply call the script:
20+
```
21+
python sure.py
22+
```
23+
24+
And then it will list all the files that were(or should be) changed:
25+
![image](img/image3.png?raw=true)
26+
27+
And it's done, congrats
28+
29+
## troubleshooting
30+
31+
If you have any questions or if anything broke you can find me(Frustration#2297) on the Etterna Dev Group discord

CmdRemoval/img/image1.png

18.1 KB
Loading

CmdRemoval/img/image2.png

4.58 KB
Loading

CmdRemoval/img/image3.png

9.16 KB
Loading

CmdRemoval/sure.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import io
2+
import os
3+
4+
for root, dirs, files in os.walk(os.getcwd()):
5+
for file in files:
6+
if (".lua" in file):
7+
enc = "utf8"
8+
fullpath = os.path.join(root, file)
9+
try:
10+
hasCmd = "cmd" in io.open(fullpath, encoding=enc).read()
11+
except UnicodeDecodeError:
12+
enc = "windows-1252"
13+
hasCmd = "cmd" in io.open(fullpath, encoding=enc).read()
14+
if (hasCmd):
15+
print("cmd found:", fullpath)
16+
with io.open(fullpath, "r", encoding=enc) as f:
17+
lines = f.readlines()
18+
for i, line in enumerate(lines):
19+
if not line.lstrip().startswith("-"):
20+
if "cmd" in line.split("--")[0]:
21+
indent = line[:len(line) - len(line.lstrip())]
22+
cmt = " " + line[line.rfind("--"):].strip() if len(line.split("--")) > 1 else ""
23+
line = line.split("--")[0]
24+
oneLiner = "{" in line and "}" in line
25+
ending = line.strip()[line.strip().index("}"):] if oneLiner else line.strip()[-1]
26+
if ending == ')':
27+
ending = ""
28+
init = line.split("cmd")[0]
29+
args = line.split("cmd")[1]
30+
idx = args[:args.rfind(')')].rfind(')') if "RunCommandsOnChildren" in init else args[:args[:args.rfind(')')].rfind(')')].rfind(')') if init[-1] == '(' else args.rfind(')')
31+
args = args[1:idx].split(";") if idx - 1 > 0 else ""
32+
newArg = ""
33+
if len(args) > 0:
34+
for arg in args:
35+
if (arg != ""):
36+
if (len(arg.split(",", 1)) == 1):
37+
newArg += ":" + arg + "()"
38+
else:
39+
newArg += ":" + arg.split(",", 1)[0].strip() + "(" + arg.split(",", 1)[1].strip() + ")"
40+
if oneLiner:
41+
init = ("{\n" + indent + " ").join(init.split("{"))
42+
lines[i] = indent + cmt + "\n" + init + "function(self)\n" + indent + " self" + newArg + "\n" + indent + " end\n" + indent + ending + "\n"
43+
elif "RunCommandsOnChildren" in init:
44+
lines[i] = init + "function(self) self" + newArg + " end" + ")" + ending + cmt + "\n"
45+
elif init[-1] == '(':
46+
lines[i] = indent + line[line.rfind('(')+1:line.rfind(')')] + newArg + ending + cmt + "\n"
47+
else:
48+
lines[i] = init + "function(self)\n" + indent + " self" + newArg + cmt + "\n" + indent + "end" + ending + "\n"
49+
else:
50+
lines[i] = ""
51+
with io.open(fullpath, "w", encoding=enc) as f:
52+
lines = "".join(lines)
53+
f.write(lines)

0 commit comments

Comments
 (0)