Skip to content

Commit

Permalink
Integrated CCScript as a Python module rather than calling it by an e…
Browse files Browse the repository at this point in the history
…xternal executable. Fixes #98
  • Loading branch information
kiij committed May 23, 2014
1 parent 162dee0 commit fee8ee4
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 105 deletions.
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "ccscript_legacy"]
path = ccscript_legacy
url = git://github.com/mraccident/ccscript_legacy.git
[submodule "mobile-sprout"]
path = mobile-sprout
url = git://github.com/kiij/mobile-sprout
[submodule "coilsnake/assets/mobile-sprout"]
path = coilsnake/assets/mobile-sprout
url = git://github.com/kiij/mobile-sprout.git
20 changes: 1 addition & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
CCSCRIPT_SRC_DIR=ccscript_legacy/src
CCSCRIPT_EXE=$(CCSCRIPT_SRC_DIR)/bin/ccc

MOBILE_SPROUT_LIB_DIR=mobile-sprout/lib

ASSETS_CCSCRIPT_DIR=coilsnake/assets/ccc
ASSETS_CCSCRIPT_EXE=$(ASSETS_CCSCRIPT_DIR)/ccc
ASSETS_CCSCRIPT_LIB_DIR=$(ASSETS_CCSCRIPT_DIR)/lib

all: coilsnake_lib ccscript mobile_sprout
all: coilsnake_lib submodule

install: all
python setup.py install
python script/post_install.py

test: coilsnake_lib
python setup.py test
Expand All @@ -22,14 +12,6 @@ coverage: coilsnake_lib
coilsnake_lib:
python setup.py build_ext --inplace clean

ccscript: submodule
cd $(CCSCRIPT_SRC_DIR) ; \
make
cp $(CCSCRIPT_EXE) $(ASSETS_CCSCRIPT_EXE)

mobile_sprout: submodule
cp -r $(MOBILE_SPROUT_LIB_DIR)/* $(ASSETS_CCSCRIPT_LIB_DIR)

submodule:
git submodule init
git submodule update
Expand Down
26 changes: 4 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,10 @@ using modified assets.
Most of the game's data is editable by CoilSnake, making it possible to create entirely new games in the EarthBound
engine.

### Installation
### Download

#### Windows

Download the Windows version of CoilSnake [here](http://kiij.github.io/CoilSnake/).

#### Linux

sudo apt-get install python-pip python-dev libyaml-dev python-tk \
g++ libboost-filesystem-dev
git clone https://github.com/kiij/CoilSnake.git
cd CoilSnake
make
sudo make install

After installing, you can start up the GUI with:

coilsnake

To use the command line interface:

coilsnake-cli
Download and usage instructions for Windows and Linux can be found on the
[CoilSnake website](http://kiij.github.io/CoilSnake/download.html).

### Development

Expand All @@ -40,7 +22,7 @@ which makes CoilSnake available on `sys.path` but also allows it to be edited di
./script/gui.py # Launch the GUI
./script/cli.py # Launch the CLI

### Running the Tests
#### Running the Tests

make test

Expand Down
1 change: 0 additions & 1 deletion ccscript_legacy
Submodule ccscript_legacy deleted from 76ac17
Empty file removed coilsnake/assets/ccc/lib/.gitkeep
Empty file.
Submodule mobile-sprout updated from 000000 to 7fd250
4 changes: 4 additions & 0 deletions coilsnake/exceptions/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class FileAccessError(CoilSnakeInternalError):
pass


class CCScriptCompilationError(CoilSnakeError):
pass


# For when the data is of the expected type or form, but the content of the data itself is invalid or unexpected.
# This should generally be caused by some error or inconsistency in the user's input.
class InvalidUserDataError(CoilSnakeUserError):
Expand Down
2 changes: 1 addition & 1 deletion coilsnake/modules/eb/CccInterfaceModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class CccInterfaceModule(EbModule):
NAME = "CCScript"
NAME = "CCScript Labels"

SUMMARY_RESOURCE_NAME = 'ccscript/summary'
SUMMARY_RESOURCE_EXTENSION = 'txt'
Expand Down
41 changes: 18 additions & 23 deletions coilsnake/ui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
import os
from shutil import copyfile
import time
from subprocess import Popen, PIPE
import sys

from ccscript import ccc
from CCScriptWriter.CCScriptWriter import CCScriptWriter

from coilsnake.util.common.project import FORMAT_VERSION, PROJECT_FILENAME, get_version_name
from coilsnake.exceptions.common.exceptions import CoilSnakeError
from coilsnake.exceptions.common.exceptions import CoilSnakeError, CCScriptCompilationError
from coilsnake.model.common.blocks import Rom
from coilsnake.ui.formatter import CoilSnakeFormatter
from coilsnake.util.common.project import Project
from coilsnake.util.common.assets import open_asset, ccc_file_name
from coilsnake.util.common.assets import open_asset, ccscript_library_path


log = logging.getLogger(__name__)


def setup_logging(quiet=False, verbose=False):
handler = logging.StreamHandler()
def setup_logging(quiet=False, verbose=False, stream=None):
if not stream:
stream = sys.stdout
handler = logging.StreamHandler(stream=stream)
handler.setFormatter(CoilSnakeFormatter())
if quiet:
logging.root.disabled = True
Expand Down Expand Up @@ -92,29 +93,23 @@ def compile_project(project_path, base_rom_filename, output_rom_filename, ccscri
if x.lower().endswith('.ccs')]

if script_filenames:
log.info("Calling CCScript compiler")
log.info("Compiling CCScript")
if not ccscript_offset:
ccscript_offset = "F10000"
elif type(ccscript_offset) == int:
ccscript_offset = "{:x}".format(ccscript_offset)

process = Popen(
[ccc_file_name(),
"-n",
"-o", output_rom_filename,
"-s", ccscript_offset,
"--summary", os.path.join(project_path, "ccscript", "summary.txt")]
+ script_filenames,
stdout=PIPE,
stderr=PIPE,
shell=(sys.platform == 'win32'))

cccStdin, cccStderr = process.communicate()
if process.returncode == 0:
log.info("CCScript compiler finished successfully")
ccc_args = ["-n",
"--libs", ccscript_library_path(),
"--summary", os.path.join(project_path, "ccscript", "summary.txt"),
"-s", ccscript_offset,
"-o", output_rom_filename] + script_filenames
ccc_returncode, ccc_log = ccc(ccc_args)

if ccc_returncode == 0:
log.info("Finished compiling CCScript")
else:
log.error("CCScript compiler failed with the following message:\n" + cccStderr)
raise CoilSnakeError("CCScript compilation failed")
raise CCScriptCompilationError("CCScript compilation failed with output:\n" + ccc_log)

rom = Rom()
rom.from_file(output_rom_filename)
Expand Down
6 changes: 3 additions & 3 deletions coilsnake/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def do_compile(self, project_entry, base_rom_entry, rom_entry):

self.progress_bar.clear()

log.info("Starting compilation...")

thread = Thread(target=self._do_compile_help, args=(project, base_rom, rom))
thread.start()

Expand Down Expand Up @@ -378,10 +380,8 @@ def tab_changed(event):
self.notebook.bind("<<NotebookTabChanged>>", tab_changed)

self.console_stream = self.console
sys.stdout = self.console_stream
sys.stderr = self.console_stream

setup_logging(quiet=False, verbose=False)
setup_logging(quiet=False, verbose=False, stream=self.console_stream)
self.refresh_debug_logging()

def create_about_window(self):
Expand Down
7 changes: 2 additions & 5 deletions coilsnake/util/common/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ def open_asset(*path):
return open(asset_path(path), 'r')


def ccc_file_name():
if sys.platform == "win32" or sys.platform == "cygwin":
return asset_path(["ccc", "ccc.exe"])
else:
return asset_path(["ccc", "ccc"])
def ccscript_library_path():
return asset_path(["mobile-sprout", "lib"])
23 changes: 0 additions & 23 deletions script/post_install.py

This file was deleted.

6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
install_requires=[
"Pillow>=2.4.0",
"PyYAML>=3.11",
"CCScriptWriter>=1.1"
"CCScriptWriter>=1.1",
"ccscript>=1.337"
],
dependency_links=[
"http://github.com/Lyrositor/CCScriptWriter/tarball/master#egg=CCScriptWriter-1.1"
"http://github.com/Lyrositor/CCScriptWriter/tarball/master#egg=CCScriptWriter-1.1",
"http://github.com/mraccident/ccscript_legacy/tarball/master#egg=ccscript-1.337"
],
ext_modules=[
Extension("coilsnake.util.eb.native_comp", ["coilsnake/util/eb/native_comp.c"])
Expand Down

0 comments on commit fee8ee4

Please sign in to comment.