Skip to content

Commit

Permalink
Fixed #98 - Crash when loading mods
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral committed Nov 16, 2019
1 parent fa0beaa commit a10c4da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions source/gameMods.brs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
' ** Roku Prince of Persia Channel - http://github.com/lvcabral/Prince-of-Persia-Roku
' **
' ** Created: July 2016
' ** Updated: September 2019
' ** Updated: November 2019
' **
' ** Ported to Brighscript by Marcelo Lv Cabral from the Git projects:
' ** https://github.com/ultrabolido/PrinceJS - HTML5 version by Ultrabolido
Expand Down Expand Up @@ -126,7 +126,7 @@ Sub ModsAndCheatsScreen()
port: m.port
}
this.screen.SetMessagePort(this.port)
this.screen.SetHeader("Mods an d Cheats")
this.screen.SetHeader("Mods and Cheats")
this.modArray = [{name: "(none)", author:"", levels: false, sprites: false, sounds: false}]
this.modIndex = 0
for each modId in m.mods.Keys()
Expand Down
13 changes: 7 additions & 6 deletions source/gameUtil.brs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
' ** Roku Prince of Persia Channel - http://github.com/lvcabral/Prince-of-Persia-Roku
' **
' ** Created: February 2016
' ** Updated: July 2019
' ** Updated: November 2019
' **
' ** Ported to Brighscript by Marcelo Lv Cabral from the Git projects:
' ** https://github.com/ultrabolido/PrinceJS - HTML5 version by Ultrabolido
Expand Down Expand Up @@ -231,7 +231,7 @@ Function key_s() as boolean
return m.cursors.shift
End Function

Function LoadBitmapRegions(scale as float, path as string, jsonFile as string, pngFile = "" as string, flip = false as boolean, simpleScale = false as boolean) as object
Function LoadBitmapRegions(scale as float, path as string, jsonFile as string, pngFile = "" as string, flip = false as boolean, simpleScale = false as boolean)
if pngFile = ""
pngFile = jsonFile
end if
Expand All @@ -257,7 +257,7 @@ Function LoadBitmapRegions(scale as float, path as string, jsonFile as string, p
return regions
End Function

Function GenerateFrameNames(prefix as string, start as integer, finish as integer, suffix = "" as string, shuffle = false as boolean, repeatFrame = 1 as integer) as object
Function GenerateFrameNames(prefix as string, start as integer, finish as integer, suffix = "" as string, shuffle = false as boolean, repeatFrame = 1 as integer)
frameNames = []
if shuffle
length = finish-start+1
Expand All @@ -278,13 +278,14 @@ Function GenerateFrameNames(prefix as string, start as integer, finish as intege
return frameNames
End Function

Function GetPaintedBitmap(color as integer, width as integer, height as integer, alpha as boolean) as object
Function GetPaintedBitmap(color as integer, width as integer, height as integer, alpha as boolean)
bitmap = CreateObject("roBitmap", {width:width, height:height, alphaenable:alpha})
bitmap.clear(color)
return bitmap
End Function

Function ScaleBitmap(bitmap as object, scale as float, simpleMode = false as boolean) as object
Function ScaleBitmap(bitmap as object, scale as float, simpleMode = false as boolean)
if bitmap = invalid then return bitmap
if scale = 1.0
scaled = bitmap
else if scale = int(scale) or simpleMode
Expand All @@ -299,7 +300,7 @@ Function ScaleBitmap(bitmap as object, scale as float, simpleMode = false as boo
return scaled
End Function

Function ScaleToSize(bitmap as object, width as integer, height as integer, ratio = true as boolean) as object
Function ScaleToSize(bitmap as object, width as integer, height as integer, ratio = true as boolean)
if bitmap = invalid then return bitmap
if ratio and bitmap.GetWidth() <= width and bitmap.GetHeight() <= height
scaled = bitmap
Expand Down
14 changes: 10 additions & 4 deletions source/levelCustom.brs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
' ** Roku Prince of Persia Channel - http://github.com/lvcabral/Prince-of-Persia-Roku
' **
' ** Created: July 2016
' ** Updated: September 2019
' ** Updated: November 2019
' **
' ** Ported to Brighscript by Marcelo Lv Cabral from the Git projects:
' ** https://github.com/ultrabolido/PrinceJS - HTML5 version by Ultrabolido
Expand Down Expand Up @@ -53,8 +53,8 @@ Function build_custom(levelId as integer, modObj as object) as object
xmlGuard = xmlRoom.GetNamedElements("guard").Simplify()
xmlGrdAt = xmlGuard.GetAttributes()
xmlLinks = xmlRoom.GetNamedElements("links").Simplify()
xmlLnkAt = xmlLinks.GetAttributes()
id = Val(xmlRomAt[number])
xmlLnkAt = xmlLinks.GetAttributes()
id = Val(xmlRomAt["number"])
rmlnk = {hideUp: false, hideLeft: false, leftZ: 5}
if xmlLnkAt["left"] > "0"
rmlnk.left = Val(xmlLnkAt["left"])
Expand All @@ -81,6 +81,7 @@ Function build_custom(levelId as integer, modObj as object) as object
this.rooms[id].links = rmlnk
'Add tiles
for each xmlTile in xmlTiles
xmlTilAt = xmlTile.GetAttributes()
tl = {element: Val(xmlTilAt["element"]) and &h1F, modifier: Val(xmlTilAt["modifier"])}
if tl.element = m.const.TILE_WALL
if tl.modifier > 1
Expand Down Expand Up @@ -167,8 +168,13 @@ Function build_custom(levelId as integer, modObj as object) as object
print "layout dimensions: "; this.width; " by "; this.height
'dim layout[this.height, this.width]
layout = []
for h = 0 to this.height
layout.push([])
for w = 0 to this.width
layout[h].push(invalid)
next
next
for r = 1 to 24
layout.push([0])
room = this.rooms[r]
if room <> invalid and room.layout
room.x = room.x + Abs(layoutOffset.tx)
Expand Down

0 comments on commit a10c4da

Please sign in to comment.