Skip to content

Commit

Permalink
Use the Color class everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Jan 5, 2024
1 parent b31ca63 commit 5b4c060
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 41 deletions.
18 changes: 9 additions & 9 deletions main.ms
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ Display.clear = function()
Display.pixels = new PixelDisplay
Display.pixels.install 1 //PIXEL_0
// display(2).mode = displayMode.pixel
// display(2).color = color.clear
// display(2).color = Color.clear.str()
// Display.pixels = display(2)
end if
Display.pixels.clear color.clear // Why is this set to "off"???
Display.pixels.clear Color.clear.str() // Why is this set to "off"???
Display.particles.clear()
end function

Expand All @@ -145,22 +145,22 @@ drawEntities = function(display, map, renderOffset)
end function

drawHUD = function(display, player)
// display.color = color.clear
// display.backColor = color.clear
// display.color = Color.clear.str()
// display.backColor = Color.clear.str()
display.clear()
// display.row = 26

// display.column = 0
// display.color = color.white
// display.backColor = color.black
// display.color = Color.white.str()
// display.backColor = Color.black.str()

// drawMiniMap()

statusBar = "HP: {0}/{1} LVL: {2} XP: {3}/{4} world: {5}".fill([player.currentHP, player.maxHP, player.level, player.xp, player.xpToNextLevel, Service.world.currentLevel])
statusBar = statusBar + " " * (constants.UI_DISPLAY_WIDTH - statusBar.len - 10)

display.print(statusBar, 0, constants.UI_DISPLAY_YMAX, color.white, color.black)
display.print(" " * constants.UI_DISPLAY_WIDTH, 0, constants.UI_DISPLAY_HEIGHT, color.white, color.black)
display.print(statusBar, 0, constants.UI_DISPLAY_YMAX, Color.white.str(), Color.black.str())
display.print(" " * constants.UI_DISPLAY_WIDTH, 0, constants.UI_DISPLAY_HEIGHT, Color.white.str(), Color.black.str())

Service.messages.update()
end function
Expand All @@ -169,7 +169,7 @@ updateParticles = function(deltaTime, map, renderOffset)
if Service.fountains.len > 0 then
n = 0

Display.particles.clear color.clear
Display.particles.clear Color.clear.str()

while n < Service.fountains.len
f = Service.fountains[n]
Expand Down
4 changes: 2 additions & 2 deletions src/factories/behaviors.ms
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ makeUserInput = function()
end function
eraseCursor = function()
// ui.drawCell(Display.map, renderOffset.x + pnt.x, renderOffset.y + pnt.y, color.clear, color.clear, " ")
// ui.drawCell(Display.map, renderOffset.x + pnt.x, renderOffset.y + pnt.y, Color.clear, Color.clear, " ")
Service.world.map.drawTile Display.map, pnt.x, pnt.y, renderOffset
end function
Expand All @@ -288,7 +288,7 @@ makeUserInput = function()
width = math.max(16, text.len + 4)
clearBounds = rect.make(0, constants.UI_DISPLAY_HEIGHT - 3, constants.UI_DISPLAY_WIDTH, 3)
ui.clearRect(Display.hud, clearBounds, " ", color.clear, color.clear)
ui.clearRect(Display.hud, clearBounds, " ", Color.clear, Color.clear)
descriptionBounds = rect.make(constants.UI_DISPLAY_WIDTH - width, constants.UI_DISPLAY_HEIGHT - 3, width, 3)
ui.drawWindow(Display.hud, descriptionBounds)
Expand Down
8 changes: 4 additions & 4 deletions src/hud.ms
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Message.make = function(text, foregroundColor = null, backgroundColor = null)
self.maxLifeSpan = 5
m.lifeSpan = 5
m.text = text
m.foregroundColor = math.coalesce(foregroundColor, color.white)
m.backgroundColor = math.coalesce(backgroundColor, color.black)
m.foregroundColor = math.coalesce(foregroundColor, Color.white)
m.backgroundColor = math.coalesce(backgroundColor, Color.black)
return m
end function

Message.draw = function(row)
ratio = self.lifeSpan / self.maxLifeSpan
fg = color.lerp(color.clear, self.foregroundColor, ratio)
bg = color.lerp(color.clear, self.backgroundColor, ratio)
fg = Color.lerp(Color.clear, self.foregroundColor, ratio)
bg = Color.lerp(Color.clear, self.backgroundColor, ratio)
Display.hud.print self.text, 0, row, fg, bg
end function

Expand Down
2 changes: 1 addition & 1 deletion src/item.ms
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Item = new Object
Item.name = "n/a"
Item.isConsumedOnUse = true
Item.tile = tile.make("?", color.gray, color.black)
Item.tile = tile.make("?", Color.gray, Color.black)
Item.weight = 0
Item.goldValue = 0
Item.description = "N/A"
Expand Down
27 changes: 12 additions & 15 deletions src/map.ms
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end function
Map.clear = function(dsp)
for y in range(0, SCREEN_MAX_Y - 1)
for x in range(0, SCREEN_MAX_X)
dsp.setCell x, y, 24 * 16 + 2, color.white, color.white
dsp.setCell x, y, 24 * 16 + 2, Color.white, Color.white
end for
end for
end function
Expand All @@ -141,7 +141,7 @@ Map.drawTile = function(dsp, x, y, renderOffset=null)
end if
if not math.isInRange(x, 0, self.width - 1) or not math.isInRange(y, 0, self.height - 1) then
dsp.setCell rx, ry, 24 * 16 + 2, color.white, color.white
dsp.setCell rx, ry, 24 * 16 + 2, Color.white, Color.white
return
end if
Expand All @@ -160,10 +160,10 @@ Map.drawTile = function(dsp, x, y, renderOffset=null)
// c = t.foregroundColor.str()
// Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c
else
dsp.setCell rx, ry, 24 * 16 + 2, color.white, color.white
dsp.setCell rx, ry, 24 * 16 + 2, Color.white, Color.white
// // Draw minimap.
// c = color.gray
// c = Color.gray
// Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c
end if
end function
Expand All @@ -178,22 +178,19 @@ Map.drawMiniMap = function()
borderY = constants.PIXEL_HEIGHT - renderHeight - borderSize * 2
borderWidth = renderWidth + borderSize * 2
borderHeight = renderHeight + borderSize * 2
Display.pixels.drawRect borderX, borderY, borderWidth, borderHeight, color.brown, borderSize
Display.pixels.drawRect borderX, borderY, borderWidth, borderHeight, Color.brown, borderSize
for y in range(0, self.height)
for x in range(0, self.width)
tile = self.getTile(x, y)
rx = constants.PIXEL_WIDTH - (renderWidth - x * cellSize) - borderSize - 1
ry = constants.PIXEL_HEIGHT - (renderHeight - y * cellSize) - borderSize - 1
if tile.hasBeenVisited then
c = tile.mapColor.str()
// Display.pixels.setPixel rx, ry, c
Display.pixels.drawRect rx, ry, cellSize, cellSize, c, 1
c = tile.mapColor
else
c = color.gray
// Display.pixels.setPixel rx, ry, c
Display.pixels.drawRect rx, ry, cellSize, cellSize, c, 1
c = Color.gray
end if
Display.pixels.drawRect rx, ry, cellSize, cellSize, c.str(), 1
end for
end for
Expand All @@ -205,13 +202,13 @@ Map.drawMiniMap = function()
continue
end if
c = e.tile.mapColor.str()
c = e.tile.mapColor
rx = constants.PIXEL_WIDTH - (renderWidth - ex * cellSize) - borderSize - 1
ry = constants.PIXEL_HEIGHT - (renderHeight - ey * cellSize) - borderSize - 1
// Display.pixels.setPixel rx, ry, c
Display.pixels.drawRect rx, ry, cellSize, cellSize, c, 1
Display.pixels.drawRect rx, ry, cellSize, cellSize, c.str(), 1
end for
end function
Expand Down Expand Up @@ -251,7 +248,7 @@ Map.getDrawInfo = function(display, x, y, renderOffset)
end if
if not math.isInRange(x, 0, self.width - 1) or not math.isInRange(y, 0, self.height - 1) then
return [color.gray, color.black, "#"]
return [Color.gray, Color.black, "#"]
end if
t = self.tiles[y][x]
Expand All @@ -261,7 +258,7 @@ Map.getDrawInfo = function(display, x, y, renderOffset)
else if t.hasBeenVisited then
return t.getDrawInfo(true)
else
return [color.gray, color.black, "#"]
return [Color.gray, Color.black, "#"]
end if
end function
Expand Down
12 changes: 6 additions & 6 deletions src/ui.ms
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEFAULT_TEXT = " "
DEFAULT_FOREGROUND_COLOR = color.gray
DEFAULT_BACKGROUND_COLOR = color.black
DEFAULT_FOREGROUND_COLOR = Color.gray
DEFAULT_BACKGROUND_COLOR = Color.black

drawCell = function(display, x, y, fg, bg, text)
if fg isa Color then fg = fg.str()
Expand Down Expand Up @@ -85,10 +85,10 @@ drawText = function(display, text, bounds, fg, bg=null)
return lineCount
end function
WINDOW_BORDER_FOREGROUND = color.blue
WINDOW_BORDER_BACKGROUND = color.black
WINDOW_TITLE_FOREGROUND = color.yellow
WINDOW_TITLE_BACKGROUND = color.black
WINDOW_BORDER_FOREGROUND = Color.blue
WINDOW_BORDER_BACKGROUND = Color.black
WINDOW_TITLE_FOREGROUND = Color.yellow
WINDOW_TITLE_BACKGROUND = Color.black
drawWindow = function(display, bounds, title=null)
ui.clearRect(display, bounds)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ExamineWindow.ms
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ExamineWindow.draw = function(title) //, description="")
ui.drawCell(Display.hud, windowBounds.centerX, windowBounds.top, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 207)

// Unused?
// Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, color.white, color.black
// Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, Color.white, Color.black

self.selectList.drawItems()
end function
Expand Down
2 changes: 1 addition & 1 deletion src/ui/HeadsUpDisplay.ms
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end function
HeadsUpDisplay.clear = function()
for y in range(0, constants.UI_DISPLAY_YMAX)
for x in range(0, constants.UI_DISPLAY_XMAX)
self.setCell x, y, 0, color.black, color.clear
self.setCell x, y, 0, Color.black, Color.clear
end for
end for
end function
Expand Down
2 changes: 1 addition & 1 deletion src/ui/InventorySelectWindow.ms
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ InventorySelectWindow.draw = function(title) //, description="")
ui.drawCell(Display.hud, windowBounds.centerX, windowBounds.top, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 207)

// I'm not actually using the description anywhere.
// Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, color.white, color.black
// Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, Color.white, Color.black
self.selectList.drawItems()
end function
Expand Down
2 changes: 1 addition & 1 deletion src/ui/SelectList.ms
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SelectList.scrollDown = function()
end function

SelectList.erase = function()
ui.clearRect(self.display, self.windowBounds, " ", color.clear, color.clear)
ui.clearRect(self.display, self.windowBounds, " ", Color.clear, Color.clear)
end function

SelectList.getItemRow = function(itemIndex)
Expand Down

0 comments on commit 5b4c060

Please sign in to comment.