Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Added support for highlighting text in different colors and cleaning …
Browse files Browse the repository at this point in the history
…up formatting for auto complete.
  • Loading branch information
jessefreeman committed Nov 18, 2021
1 parent 15d27d6 commit b4bb6cb
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 76 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/pixel-vision-8-release-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:

# This runs before the builds and cretes the new feature release
# This runs before the builds and creates the new feature release
create-release:

name: "Create Release"
Expand All @@ -32,9 +32,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.compute_tag.outputs.next_tag }}
release_name: Terminal 8 ${{ steps.compute_tag.outputs.next_tag }} Release
release_name: Terminal 8 ${{ steps.compute_tag.outputs.next_tag }} Incremental Release
draft: false
prerelease: false
prerelease: true


changelogger:
Expand Down Expand Up @@ -63,7 +63,6 @@ jobs:
IFS='.' read -ra my_array <<< "${{ steps.compute_tag.outputs.next_tag }}"
echo "CURRENT=${my_array[0]:1}.$((${my_array[1]} - 1)).$((${my_array[2]}))" >> $GITHUB_ENV
echo "PREVIOUS=${my_array[0]:1}.$((${my_array[1]} - 2)).0" >> $GITHUB_ENV
# Setup dotnet v6.0.x
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
Expand All @@ -75,7 +74,7 @@ jobs:

- name: Build
run: |
sed -i 's/0.0.0/${{env.CURRENT}}/g' App/Content/bios.json
sed -i 's/0.0.0/${{env.CURRENT}}/g' Content/bios.json
sed -i 's/0.0.0/${{env.CURRENT}}/g' App/MyGame.DesktopRunner.csproj
npm install
npm install gulp -g
Expand All @@ -92,16 +91,16 @@ jobs:
tag: v${{env.CURRENT}}
gzip: false
body: >
This is a stable build of Terminal 8 based on the Github source code. You can download a build for Windows, Mac, and Linux below. Please make sure to backup your game's maps before running this or any new build of Terminal 8.
This is an incremental build of Terminal 8 based on the GitHub source code. You can download an executable for Windows, Mac, and Linux below. Please make sure to backup your `Workspace` and game projects before running this or any preview version of Terminal 8.
For more details on what has changed, see the [change log](https://github.com/PixelVision8/Terminal8/compare/v${{ env.PREVIOUS }}...v${{ env.CURRENT }}).
In addition, you can see the current open issues [here](https://github.com/PixelVision8/Terminal8/issues) or use one of the following links to submit a new [bug](https://github.com/PixelVision8/Terminal8/issues/new?assignees=jessefreeman&labels=bug&template=bug_report.md), [feature](https://github.com/PixelVision8/Terminal8/issues/new?assignees=jessefreeman&labels=bug&template=feature_request.md) or [question](https://github.com/PixelVision8/Terminal8/issues/new?assignees=jessefreeman&labels=bug&template=question.md).
To learn more about Pixel Vision 8, check out [the documentation](https://docs.pixelvision8.com/), explore [the examples](https://www.pixelvision8.com/examples), join [the Discord server](https://discord.gg/pixelvision8), and visit [the main website](https://www.pixelvision8.com/).
To learn more about Pixel Vision 8, check out [the documentation](https://github.com/PixelVision8/Terminal8/wiki), explore [the examples](https://github.com/PixelVision8/Examples), join [the Discord server](https://discord.gg/pixelvision8), and visit [the main website](https://www.pixelvision8.com/).
files: >
terminal-8-v${{env.CURRENT}}-macos.zip:Releases/Final/terminal-8-macos.zip
terminal-8-v${{env.CURRENT}}-win.zip:Releases/Final/terminal-8-win.zip
Expand Down
41 changes: 33 additions & 8 deletions Game/Src/code-display-text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function CreateTextDisplay(rect)

data.rect = rect
data.lines = {}
data.colorOffsets = {}
data.currentLine = 1
data.totalLines = 0
data.textDelay = .02
Expand Down Expand Up @@ -90,15 +91,15 @@ end

function DrawNextLine(data)
local line = data.lines[data.currentLine]

local colorOffset = data.colorOffsets[data.currentLine]
-- print("offsets", dump(data.colorOffsets))

local char = line:sub(data.currentChar, data.currentChar)

DrawText(char, data.currentChar * 8, data.nextY, DrawMode.TilemapCache, "large", 15)
DrawText(char, data.currentChar * 8, data.nextY, DrawMode.TilemapCache, "large", colorOffset[data.currentChar])

data.currentChar = data.currentChar + 1



if(data.currentChar > #line) then
data.currentChar = 0
data.currentLine = data.currentLine + 1
Expand Down Expand Up @@ -142,22 +143,46 @@ function DisplayText(data, text, clear)
if(clear == true) then
ClearTextDisplay(data)
data.lines = {}
data.colorOffsets = {}
data.currentLine = 1
data.nextY = data.rect.y
end

data.startLine = data.currentLine

-- We are going to render the message in a box as tiles. To do this, we need to wrap the
-- text, then split it into lines and draw each line.
local wrap = WordWrap(text, (data.rect.w / 8) - 2)
-- Before we can split the lines, we need to create the color map and replace the tokens since each one has additional characters that would throw off the wrapping logic
local newText, colors = colorizeText(text, 15)

-- We are going to render the message in a box as tiles. To do this, we need to wrap the text, then split it into lines and draw each line.
local wrap = WordWrap(newText, (data.rect.w / 8) - 2)

-- Get the lines
local newLines = SplitLines(wrap)

print("lines", dump(newLines))

local offset = 0

-- Add the lines
for i = 1, #newLines do
table.insert(data.lines, newLines[i])

-- Get the line
local line = newLines[i]

-- Add it to the lines table
table.insert(data.lines, line)

-- Since lua doesn't have a way to splice or get a range of values in an array, we need to do this manually
local colorOffsets = {}

for j = 1, #line do
table.insert(colorOffsets, colors[j + offset])
end

offset = offset + #line + 1-- +1 for the new line

table.insert(data.colorOffsets, colorOffsets)

end

-- Update the total lines
Expand Down
49 changes: 37 additions & 12 deletions Game/Src/code-map-generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
Learn more about making Pixel Vision 8 games at https://www.gitbook.com/@pixelvision8
]]--

-- To make things easier to read, let's define some shorter names for the `CalculateIndex()` and `CalculatePosition()` APIs.
local calId = CalculateIndex
local calPos = CalculatePosition

function NewMap(w, h)

local data = {
Expand All @@ -29,7 +33,9 @@ function NewMap(w, h)

MapToString(data)

print("Raw Map\n" ..dump(data.roomIndex))
-- print("Raw Map\n" ..dump(data.roomIndex))

print("Generate Map", data.mapString)

return data

Expand Down Expand Up @@ -70,8 +76,19 @@ function GenerateMap(data)
data.maze[i][j].down = 1
data.maze[i + 1][j].up = 1
end

local c = i-1
local r = j-1

print("tile", c, r, calId(c, r, data.width), dump(data.maze[i][j]))

end


end

print("Raw map\n", dump(data.maze))

end

function CleanUpMap(data)
Expand All @@ -87,25 +104,33 @@ function CleanUpMap(data)
end

for i = 0, #data.maze * 2, 1 do
data.mapTable[CalculateIndex(0, i, data.width) + 1] = 1
data.mapTable[calId(0, i, data.width) + 1] = 1
end

for j = 1, #data.maze[1] * 2, 1 do
data.mapTable[CalculateIndex(j, 0, data.height) + 1] = 1
data.mapTable[calId(j, 0, data.height) + 1] = 1
end

local total = data.width * data.height

print("test", #data.maze, #data.maze[1], data.height, data.width)

for i = 1, #data.maze do

for j = 1, #data.maze[1] do

data.mapTable[ CalculateIndex(j * 2, i * 2, data.width) + 1] = 1
data.mapTable[ calId(j * 2, i * 2, data.width) + 1] = 1

if data.maze[i][j].right == 0 then
data.mapTable[CalculateIndex(j * 2, (i * 2) - 1, data.width) + 1] = 1
data.mapTable[calId(j * 2, (i * 2) - 1, data.width) + 1] = 1
end

if data.maze[i][j].down == 0 then
data.mapTable[CalculateIndex((j * 2) - 1, i * 2, data.width) + 1] = 1
data.mapTable[calId((j * 2) - 1, i * 2, data.width) + 1] = 1
end

end

end

end
Expand All @@ -118,7 +143,7 @@ function MapToString(data)

local tmpValue = data.mapTable[i]

data.mapString = data.mapString .. (tmpValue == 1 and " " or string.lpad(tostring(i), 2, "0"))
data.mapString = data.mapString .. (tmpValue == 1 and " " or string.lpad(tostring(i), 3, "0"))

data.mapString = data.mapString .. " "

Expand All @@ -138,7 +163,7 @@ function FindRooms(data)
local roomValue = data.mapTable[i]
if(roomValue == 0) then

local pos = CalculatePosition(i, data.width)
local pos = calPos(i, data.width)

local room = {
id = i,
Expand All @@ -149,28 +174,28 @@ function FindRooms(data)
local tmpIndex = -1
-- Top

tmpIndex = CalculateIndex(pos.x, pos.y - 1, data.width)
tmpIndex = calId(pos.x, pos.y - 1, data.width)
if(data.mapTable[tmpIndex] == 0) then
room.north = tmpIndex
end

-- Right

tmpIndex = CalculateIndex(pos.x + 1, pos.y, data.width)
tmpIndex = calId(pos.x + 1, pos.y, data.width)
if(data.mapTable[tmpIndex] == 0) then
room.east = tmpIndex
end

-- Bottom

tmpIndex = CalculateIndex(pos.x, pos.y + 1, data.width)
tmpIndex = calId(pos.x, pos.y + 1, data.width)
if(data.mapTable[tmpIndex] == 0) then
room.south = tmpIndex
end

-- Left

tmpIndex = CalculateIndex(pos.x - 1, pos.y, data.width)
tmpIndex = calId(pos.x - 1, pos.y, data.width)
if(data.mapTable[tmpIndex] == 0) then
room.west = tmpIndex
end
Expand Down
2 changes: 1 addition & 1 deletion Game/Src/code-room-decorator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local randomItems =
name = "gun",
needs = "ammo",
value = 1,
message = "In the shadows you see something shimmer. It looks like a gun has been left on the floor.",
message = "In the shadows you see something shimmer. It looks like a {gun:14} has been left on the floor.",
examine = "This is a standard issue hand gun. You need ammo in order to use it unless you plan on throwing it at enemies?",
take = "You found a gun. Remember to point it away from you before using it.",
use = function(state)
Expand Down
53 changes: 38 additions & 15 deletions Game/Src/code-simple-input-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,42 @@ function DrawInputField(data)
end

if(data.invalid) then


-- Reset the validation
data.invalid = false

-- Look for matches for the auto complete
local matches = AutoComplete(data.text, gameState.autoComplete)

-- Find the first suggestion
data.suggestedTest = #matches == 0 and data.text or matches[1]
data.suggestedTest = data.text

-- Create an array for color offsets
local colorOffsets = {}
-- Look to see if there is an auto complete match
if( #matches > 0 ) then

-- Loop through each character in the text
for i = 1, #data.suggestedTest do
local match = matches[1]
local suggestion = match:sub(#data.text + 1)

-- Get the color offset for the character
table.insert(colorOffsets, i <= #data.text and 15 or 5)
if(#suggestion > 0) then
suggestion = "{" .. suggestion .. ":5}"
end
-- Add the current text plus the rest of the first match while highlighting it.
data.suggestedTest = data.suggestedTest .. suggestion

if(data.suggestedTest == match) then
data.suggestedTest = "{" .. data.suggestedTest .. ":11}"
end

end

-- Clear the line
DrawRect(data.rect.x, data.rect.y, data.rect.w, 8, 0, DrawMode.TilemapCache)

-- Draw the text to the display
DrawColoredText(data.suggestedTest, data.rect.x, data.rect.y, DrawMode.TilemapCache, "large", colorOffsets)
-- Colorize the text
local text, colorOffsets = colorizeText(data.suggestedTest, 6)

-- Reset the validation
data.invalid = false
-- Draw the text to the display
DrawColoredText(text, data.rect.x, data.rect.y, DrawMode.TilemapCache, "large", colorOffsets)

end

Expand All @@ -122,7 +132,13 @@ function KeyCapture(data)

elseif(Key(Keys.Tab) and #data.suggestedTest > #data.text) then

data.text = data.suggestedTest
local matches = AutoComplete(data.text, gameState.autoComplete)

if(#matches > 0) then

data.text = matches[1]

end

data.invalid = true

Expand Down Expand Up @@ -169,11 +185,18 @@ function CaptureInput(data)

end

function ClearInputField(data)
-- function ClearInputFieldBackground()

-- DrawRect(data.rect.x, data.rect.y, data.rect.w, 8, 0, DrawMode.TilemapCache)

DrawRect(data.rect.x, data.rect.y, data.rect.w, 8, 0, DrawMode.TilemapCache)
-- end

function ClearInputField(data)

data.text = ""

data.invalid = true

end

function SubmitText(data)
Expand Down
Loading

0 comments on commit b4bb6cb

Please sign in to comment.