Git Product home page Git Product logo

sdattool's People

Contributors

einstein95 avatar froggestspirit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sdattool's Issues

-ru (remove unused) flag potentially broken

For the most part, this option works, removing unused items in infoblock, as well as removing files with duplicate MD5 checksums. There was an issue with 2 SBNK that are unique, but sharing 2 duplicate SWAR, not being renamed properly in the infoblock, causing a glitchy build.

Optimize Issue

Untested, but since MD5 is only calculated at time of unpack, a modified duplicate file will still be removed when rebuilding optimized.

Fix: Recalculate MD5 at build time if optimizing the build

Code cleanup

In the interest of transpiling this code to C/C++, I recommend the following changes. Many of them are cosmetic, but all will improve code readability.

  1. Define all global variables at the top of the file, before methods. This will make it easier to determine the type of a global variable that's used in a module-level method. It also provides security against exceptions like NameError and UnboundLocalError, and allows intellisense editors to detect if you may be shadowing a global variable.

  2. Use list/dict comprehension where feasible. This is generally faster and more succinct than creating the container empty and appending to it.

Before:

foo = []
foo.append(1)
foo.append('apple')
foo.append(3.14159)

After:

foo = [1, 'apple', 3.14159]
  1. Indent with 4 spaces instead of a tab character. This will cause your file to render consistently across editors. In particular, on GitHub where tabs are displayed as 8 characters wide, switching to 4 spaces will make the code's appearance easier on the eyes.

  2. Conditional statements don't need to be wrapped in parentheses. Many IDEs will gripe about this.

Before:

if(my_var == 0):
    pass

After:

if my_var == 0:
    pass
  1. Use with statements where feasible. Some classes in Python, file types in particular, support the with statement, which simplifies the following workflow:

Before:

file = open(filename, 'rb')
try:
    do stuff with file
finally:
    file.close()

After:

with open(filename, 'rb') as file:
    do stuff with file
# On unindent, file is automatically closed.
  1. Use argparse (Python standard library) to parse commandline arguments. Python implements argument parsing in a very easy-to-write and easy-to-read manner because, unlike with C/C++, it can.

Before:

for i, argument in enumerate(sysargv):
   if(i > 0):  # The first iteration is wasted cycles.
        if(argument.startswith("-")):
            if(argument == "-u" or argument == "--unpack):
                mode = 1

After:

parser = argparse.ArgumentParser()
parser.add_argument('infile', type=argparse.FileType('rb'))
parser.add_argument('outfile', type=argparse.FileType('wb'), nargs='?')
mode_grp = parser.add_mutually_exclusive_group(required=True)
mode_grp.add_argument('-u', '--unpack', dest='mode', action='store_false')
mode_grp.add_argument('-b', '--build', dest='mode', action='store_true')
parser.add_argument('-m', '--md5', dest='md5', action='store_true')
parser.add_argument('-o', '--optimize', dest='optimize', action='store_true')
parser.add_argument('-ru', '--removeUnused', dest='removeUnused', action='store_true')
parser.add_argument('-ns', '--noSymbBlock', dest='noSymbBlock', action='store_true')
args = parser.parse_args()

Note: -h and --help are added automatically by the argparse library.

  1. When testing whether a variable takes one of several values, use in instead. Example:

Before:

if(x == 1 or x == 2 or x == 4 or x == 8):
    pass

After:

if x in (1, 2, 4, 8):
    pass

Build fails if any files are edited or removed.

Rebuilding SDAT will fail on any option if any files are removed or edited.

Exampe of failiure regarding removed files using Pokemon B2W2's Sdat:

C:\Users\Goji Goodra\Downloads\SDATEDIT>py SDATTool -b b2w2.sdat
Building...
Traceback (most recent call last):
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool_main_.py", line 391, in
main()
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool_main_.py", line 384, in main
build(args)
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool_main_.py", line 325, in build
build_fileBlock(sdat, args)
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool\Sdat.py", line 574, in build_fileBlock
write_sseq(read_sseq_from_midi(args, fName), args, fName)
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool\Midi.py", line 301, in read_sseq_from_midi
raise Exception(f"Missing File:{testPath}")
Exception: Missing File:b2w2/Files/SEQ/SEQ_PV001.mid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Goji Goodra\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Goji Goodra\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\Goji Goodra\Downloads\SDATEDIT\SDATTool_main
.py", line 393, in
raise Exception(e)
Exception: Missing File:b2w2/Files/SEQ/SEQ_PV001.mid

In this case, I had manually removed all non music related files. (SFX and the like, leaving music, musical effects and STRM alone)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.