Skip to content

Commit

Permalink
minor tweaks, updated binary, reworked smbthing.lua to work off the l…
Browse files Browse the repository at this point in the history
…oaded data in a romhack project
  • Loading branch information
SpiderDave committed Feb 15, 2021
1 parent 8055283 commit d6b60a9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 85 deletions.
3 changes: 3 additions & 0 deletions NESBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,9 @@ def saveArrayToFile(self, f, fileData):
file.close()
return True
def writeToFile(self, f, fileData):
# if type(fileData) == np.ndarray:
# fileData = list(fileData)

f = fixPath2(f)
file=open(f,"w")
file.write(fileData)
Expand Down
4 changes: 0 additions & 4 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pyinstaller --onefile -%parameter% -i icon.ico -n NESBuilder%suffix%.exe ^
NESBuilder.py
if %errorlevel% NEQ 0 goto error

set sdasmupdate="J:\svn\NESBuilder\include\SpiderDaveAsm\update and commit.bat"
call "%sdasmupdate%"
if %errorlevel% NEQ 0 set errormessage=Could not find %sdasmupdate%.& goto error

echo start time: %starttime%
echo end time: %TIME%

Expand Down
4 changes: 0 additions & 4 deletions build_console.bat
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pyinstaller --onefile -%parameter% -i icon.ico -n NESBuilder%suffix%.exe ^
NESBuilder.py
if %errorlevel% NEQ 0 goto error

set sdasmupdate=J:\svn\NESBuilder\include\SpiderDaveAsm\update.bat
call "%sdasmupdate%"
if %errorlevel% NEQ 0 set errormessage=Could not find %sdasmupdate%.& goto error

echo start time: %starttime%
echo end time: %TIME%

Expand Down
Binary file modified dist/NESBuilder.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,8 @@ function ExportCHR_cmd()
if fmt then
surface.save(f, fmt)
elseif ext == ".chr" then
util.writeToFile(f, 0, currentChr(), true)
--util.writeToFile(f, 0, currentChr(), true)
NESBuilder:saveArrayToFile(f, currentChr())
else
print("unknown extension "..ext)
end
Expand Down
137 changes: 61 additions & 76 deletions plugins/smbthing.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-- NESBuilder plugin
-- smbthing.lua
--
-- To enable this plugin, remove the "_" from the start of the filename.

local plugin = {
author = "SpiderDave",
Expand Down Expand Up @@ -89,19 +87,19 @@ function plugin.onInit()

push(y)

control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingLoadRom",text="Load rom"}
control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingReload",text="Reload"}
y = y + control.height + pad
control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingImport",text="Import"}

control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingSaveRom",text="Save rom"}
y = y + control.height + pad
x = x + control.width + pad
y = pop()

control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingSaveRomAs",text="Save rom as..."}
y = y + control.height + pad
control=NESBuilder:makePaletteControlQt{x=x,y=y,cellWidth=config.cellWidth,cellHeight=config.cellHeight, name="smbthingPalette", palette=nespalette}
control.helpText = "Click to select a color"
y = y + control.height + pad*2

control = NESBuilder:makeButtonQt{x=x,y=y,w=buttonWidth, name="smbthingTest",text="Test rom"}
y = y + control.height + pad

push(x + control.width+pad*2)
push(x + control.width+pad * 2)

local p = {[0]=0x0f,0x0f,0x0f,0x0f}

Expand Down Expand Up @@ -149,89 +147,80 @@ function plugin.onInit()
end
pop() -- consume the pop and discard

x,y = pop(2)

control=NESBuilder:makePaletteControlQt{x=x,y=y,cellWidth=config.cellWidth,cellHeight=config.cellHeight, name="smbthingPalette", palette=nespalette}
control.helpText = "Click to select a color"
y = y + control.height + pad*2

plugin.selectedColor=0x0f
end

function smbthingTest_cmd()
function plugin.onLoadProject()
data.project.smbPaletteData = data.project.smbPaletteData or {}
smbthingRefreshPalettes()
end

function plugin.onBuild()
smbthingExport()
end

function smbthingReload_cmd()
-- make sure file is loaded
if not plugin.fileData then return end
if not data.project.rom.data then return end

NESBuilder:setWorkingFolder()
local f = "temp.nes"
local workingFolder = f

print(f..' '..workingFolder)
NESBuilder:saveArrayToFile(f, plugin.fileData)
NESBuilder:shellOpen(workingFolder, f)
data.project.smbPaletteData = {}
smbthingRefreshPalettes()
end

function smbthingLoadRom_cmd()
function smbthingImport_cmd()
local f = NESBuilder:openFile{filetypes={{"NES rom", ".nes"}}}
if f == "" then
print("Open cancelled.")
return
end
plugin.fileData = NESBuilder:getFileAsArray(f)
plugin.inputFile = f
plugin.outputFile = plugin.inputFile

smbthingRefreshPalettes()
end

function smbthingSaveRom_cmd()
if not plugin.fileData then return end
plugin.outputFile = plugin.inputFile

-- if NESBuilder:getControl('smbRotateMod').get() == 1 then
-- replace the last two entries in "BlankPalette" with the last two from Ground4
-- plugin.fileData[0x10+0x9ce]= plugin.fileData[0x10 + smbPaletteData.Ground4.offset+2]
-- plugin.fileData[0x10+0x9cf]= plugin.fileData[0x10 + smbPaletteData.Ground4.offset+3]

-- Modify a counter so the last two colors of area type aren't used for palette 3
-- It will instead fall back to the entries in BlankPalette above.
-- plugin.fileData[0x10+0x9ff]=0x01
-- else
-- plugin.fileData[0x10+0x9ce]= 0xff
-- plugin.fileData[0x10+0x9cf]= 0xff
-- plugin.fileData[0x10+0x9ff]= 0x03
-- end
local fileData = NESBuilder:getFileAsArray(f)

data.project.smbPaletteData = {}
for _, item in ipairs(smbPaletteData) do
p={}
for i=0,item.nColors-1 do
data.project.smbPaletteData[item.offset + i] = int(fileData[0x10 + item.offset + i])
table.insert(p, data.project.smbPaletteData[item.offset + i])
end

NESBuilder:saveArrayToFile(plugin.fileData, plugin.inputFile)
c = NESBuilder:getControl('smbPalette'..item.name)
c.setAll(p)
end
end

function smbthingSaveRomAs_cmd()
if not plugin.fileData then return end
function smbthingExport()
local out

local f = NESBuilder:saveFileAs{filetypes={{"NES rom", ".nes"}}, initial='output.nes'}
if f == "" then
print("Save cancelled.")
else
print("file: "..f)
NESBuilder:saveArrayToFile(plugin.fileData, f)
plugin.outputFile = f
plugin.inputFile = plugin.outputFile
out = "bank 0\n\n"
for _, item in ipairs(smbPaletteData) do
out = out .. string.format("; %s\norg $%04x\n", item.name, 0x8000 + item.offset)
out = out .. string.format(" db ")
for i = 0, item.nColors - 1 do
if i > 0 then
out = out .. ', '
end
out = out .. string.format("$%02x", data.project.smbPaletteData[item.offset + i] or 0)
end
out = out .. "\n\n"
end

filename = data.folders.projects..projectFolder.."code/smbPalettes.asm"
util.writeToFile(filename,0, out, true)
end


function smbthingRefreshPalettes()
local offset
local c

if not plugin.fileData then return end
if not data.project.rom.data then return end

for _, item in ipairs(smbPaletteData) do
offset = 0x10+item.offset

p={}
for i=0,item.nColors-1 do
table.insert(p,plugin.fileData[offset+i])
if not data.project.smbPaletteData[item.offset + i] then
-- Make sure it's not a <class 'numpy.uint8'>
data.project.smbPaletteData[item.offset + i] = int(data.project.rom.data[0x10 + item.offset + i])
end
table.insert(p, data.project.smbPaletteData[item.offset + i])
end

c = NESBuilder:getControl('smbPalette'..item.name)
Expand All @@ -249,23 +238,19 @@ end

function smbPaletteCmd(t)
local event = t.cell.event
local offset
local p, control

-- make sure file is loaded
if not plugin.fileData then return end
if not data.project.rom.data then return end

local paletteData = smbPaletteData[t.control.data.index]

offset = 0x10+paletteData.offset

if not plugin.fileData then return end

if event.button == 2 then
-- left click
plugin.selectedColor = plugin.fileData[offset+t.cellNum]
-- right click
plugin.selectedColor = data.project.smbPaletteData[paletteData.offset + t.cellNum]
elseif event.button == 1 then
plugin.fileData[offset+t.cellNum]=plugin.selectedColor
-- left click
data.project.smbPaletteData[paletteData.offset + t.cellNum] = int(plugin.selectedColor)

smbthingRefreshPalettes()
end
Expand Down
Binary file modified templates/romhack_sdasm1.zip
Binary file not shown.

0 comments on commit d6b60a9

Please sign in to comment.