From 5b4c060b123bc61058814ce41b094631b63f3575 Mon Sep 17 00:00:00 2001 From: Trey Tomes Date: Fri, 5 Jan 2024 13:29:45 -0600 Subject: [PATCH] Use the Color class everywhere. --- main.ms | 18 +++++++++--------- src/factories/behaviors.ms | 4 ++-- src/hud.ms | 8 ++++---- src/item.ms | 2 +- src/map.ms | 27 ++++++++++++--------------- src/ui.ms | 12 ++++++------ src/ui/ExamineWindow.ms | 2 +- src/ui/HeadsUpDisplay.ms | 2 +- src/ui/InventorySelectWindow.ms | 2 +- src/ui/SelectList.ms | 2 +- 10 files changed, 38 insertions(+), 41 deletions(-) diff --git a/main.ms b/main.ms index 65d85f5..5f08718 100644 --- a/main.ms +++ b/main.ms @@ -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 @@ -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 @@ -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] diff --git a/src/factories/behaviors.ms b/src/factories/behaviors.ms index 8f6ad1c..e4a8883 100644 --- a/src/factories/behaviors.ms +++ b/src/factories/behaviors.ms @@ -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 @@ -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) diff --git a/src/hud.ms b/src/hud.ms index 6e4a0c7..234a6bb 100644 --- a/src/hud.ms +++ b/src/hud.ms @@ -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 diff --git a/src/item.ms b/src/item.ms index 2dc2593..a708ce3 100644 --- a/src/item.ms +++ b/src/item.ms @@ -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" diff --git a/src/map.ms b/src/map.ms index a39c159..22b0b71 100644 --- a/src/map.ms +++ b/src/map.ms @@ -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 @@ -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 @@ -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 @@ -178,7 +178,7 @@ 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) @@ -186,14 +186,11 @@ Map.drawMiniMap = function() 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 @@ -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 @@ -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] @@ -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 diff --git a/src/ui.ms b/src/ui.ms index 6336da1..9065799 100644 --- a/src/ui.ms +++ b/src/ui.ms @@ -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() @@ -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) diff --git a/src/ui/ExamineWindow.ms b/src/ui/ExamineWindow.ms index 2bcef5e..37adec2 100644 --- a/src/ui/ExamineWindow.ms +++ b/src/ui/ExamineWindow.ms @@ -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 diff --git a/src/ui/HeadsUpDisplay.ms b/src/ui/HeadsUpDisplay.ms index 66aa6d4..a7e2c4c 100644 --- a/src/ui/HeadsUpDisplay.ms +++ b/src/ui/HeadsUpDisplay.ms @@ -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 diff --git a/src/ui/InventorySelectWindow.ms b/src/ui/InventorySelectWindow.ms index a206804..bd5e50d 100644 --- a/src/ui/InventorySelectWindow.ms +++ b/src/ui/InventorySelectWindow.ms @@ -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 diff --git a/src/ui/SelectList.ms b/src/ui/SelectList.ms index 2a6f9e3..3ccabab 100644 --- a/src/ui/SelectList.ms +++ b/src/ui/SelectList.ms @@ -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)