Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clue language #6356

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1293,3 +1293,6 @@
[submodule "vendor/grammars/zephir-sublime"]
path = vendor/grammars/zephir-sublime
url = https://github.com/phalcon/zephir-sublime
[submodule "vendor/grammars/Clue-For-VSCode"]
path = vendor/grammars/Clue-For-VSCode
url = https://github.com/ClueLang/Clue-For-VSCode.git
9 changes: 9 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3806,6 +3806,15 @@ Lua:
interpreters:
- lua
language_id: 213
Clue:
type: programming
tm_scope: source.clue
ace_mode: text
codemirror_mode: text
color: "#0009b5"
extensions:
- ".clue"
language_id: 163763508
Markos-Th09 marked this conversation as resolved.
Show resolved Hide resolved
M:
type: programming
aliases:
Expand Down
10 changes: 10 additions & 0 deletions samples/Clue/array.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local array = {1, 2, 3, 4}
assert(array[1] == 1)

table.insert(array, "hello")
table.insert(array, "world")
print(array[5], array[6])
Markos-Th09 marked this conversation as resolved.
Show resolved Hide resolved

for k, v in array {
print(k, v)
}
13 changes: 13 additions & 0 deletions samples/Clue/escapes.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
print("Hello \n World")
print("This make a bell noise \a")
print("Delete the\b character before it")
print("Line break without \fgoing to the newline")
print("replace what is at the beginning of the line \rReplace")
print("This is a\ttab")
print("A vertical \vtab!")
print("Deletes all whitespaces \z ahead")
print("\\")
print("A \"quote\"")
print("\u{1F602}")
print("\065")
print("\x41")
16 changes: 16 additions & 0 deletions samples/Clue/fizzbuzz.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local fn fizzbuzz(number) {
local string = ""
if number % 3 == 0 {
string ..= "fizz"
}
if number % 5 == 0 {
string ..= "buzz"
}
if string != "" {
print(string .. ": " .. number)
}
}

for i = 1, 100 {
fizzbuzz(i)
}
148 changes: 148 additions & 0 deletions samples/Clue/game.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
static score, mistakes = 0, 1
static hackamount, hacked = 0.5

local terminal = import("terminal")

local names = {}

local i = 1
for name with love.filesystem.lines("assets/names.txt") {
names[i] = name
i += 1
}

local commands
local seed2 = love.math.random(10, 10000)

local fn EntryCode(seed) {
local rng = love.math.newRandomGenerator((seed2 + math.floor(leveltime / 30)) * 10 + seed)
local code = ""
for _ = 1, 20 {
code ..= string.char(rng::random(33, 122))
}
return code
}

local fn GenerateIP(hacker) {
return math.ceil(math.abs(love.math.randomNormal(75, 128)) % (hacker ? 256 : 1000))
}

local user = {
new = fn(self) {
local hacker = love.math.random() > 0.8
self.ip1 = GenerateIP(hacker)
self.ip2 = GenerateIP(hacker)
self.ip3 = GenerateIP(hacker)
self.ip4 = GenerateIP(hacker)
self.glitch = self.ip1 > 255 || self.ip2 > 255 || self.ip3 > 255 || self.ip4 > 255
self.name = names[love.math.random(6000)]
self.age = math.floor((hacker || self.glitch) ? love.math.random(14, 79) : love.math.random(9, 145))
self.code = hacker ? love.math.random(-20, -1) : love.math.random(0, 9)
self.time = leveltime
self.hacker = hacker
}
next = fn(self) {
commands.score.code()
terminal::write("Reading next user's information...", 15)
self::new()
commands.user.code(4)
}
}

user::new()

local fn AwardScore(amount) {
if amount < 0 {
amount = math.ceil($ * mistakes)
terminal::write(string.format("(%d points)", amount), 60, 1, 0, 0)
mistakes += 0.5
} else {
terminal::write(string.format("(+%d points)", amount), 60, 1, 1, 0)
}
score += amount
}

commands = {
score = {
desc = "Display current score."
code = fn {
terminal::write("Score: " .. score, nil, 1, 0, 1)
local mistakes = (mistakes - 1) * 2
if mistakes == 0 {
terminal::write("You never messed up so far.", nil, 1, 0, 1)
} else {
terminal::write("You messed up " .. mistakes .. " times.", nil, 1, 0, 1)
}
}
}
user = {
desc = "Display the info of the user trying to connect."
code = fn(s = 0) {
terminal::write("Name: " .. user.name, 60, 1, 1, 0)
terminal::write("Age: " .. user.age, 60, 1, 1, 0)
terminal::write(string.format("IP: %d.%d.%d.%d", user.ip1, user.ip2, user.ip3, user.ip4), 60, 1, 1, 0)
terminal::write(string.format(
"Entry Code: %s (changes in %d seconds)",
EntryCode(user.code),
math.max(29 - math.floor(leveltime % 30) - s, 0)
), 60, 1, 1, 0)
}
}
codes = {
desc = "Display the 10 currently valid codes."
code = fn {
terminal::write("Currently valid codes:")
for i = 0, 9 {
terminal::write(EntryCode(i), 60, 1, 1, 0)
}
terminal::write(string.format(
"The codes will change in %d seconds.",
29 - math.floor(leveltime % 30)
))
}
}
allow = {
desc = "Allow the current user."
code = fn {
terminal::write(user.name .. " was allowed connection...", 10)
if user.hacker {
terminal::write("But they were an hacker!", 60, 1, 0, 0)
hacked = leveltime + 0.5
mistakes += 0.5
errors = 2
user::new()
return
} elseif user.glitch {
terminal::write("But they were a glitch!", 60, 1, 0, 0)
AwardScore(math.min(score / -2.5, -500))
errors = 1
} elseif user.age < 14 {
terminal::write("But they were too young to join.", 60, 1, 0, 0)
AwardScore(-300)
} elseif user.age >= 80 {
terminal::write("But they were a troll.", 60, 1, 0, 0)
AwardScore(-200)
} else {
terminal::write("And that was the correct choice!", 60, 1, 1, 0)
AwardScore(math.max(500 + math.floor((user.time - leveltime) * 20), 10))
}
user::next()
}
}
deny = {
desc = "Deny the current user."
code = fn {
terminal::write(user.name .. " was denied connection...", 10)
if !user.hacker && !user.glitch && user.age >= 14 && user.age < 80 {
terminal::write("But they had no bad intentions.", 60, 1, 0, 0)
AwardScore(-500)
} else {
terminal::write("And that was the correct choice!", 60, 1, 1, 0)
AwardScore(math.max(300 + math.floor((user.time - leveltime) * 20), 10))
}
user::next()
}
}
}

return commands
14 changes: 14 additions & 0 deletions samples/Clue/macro.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@macro add(x, y) {
$x + $y
}

@macro mul(x, y) {
$x * $y
}

@macro double(x) {
$mul!($x, 2)
}

print($add!(4, $add!(3, 2)))
print($double!(4))
102 changes: 102 additions & 0 deletions samples/Clue/main.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
static font = love.graphics.newFont("assets/clacon2.ttf", 24, "mono")
static fontheight = 23 //force it to 23 cause windows and linux use different sizes...
static screenheight = love.graphics.getHeight() - 10
static leveltime = 0

io.stdout::setvbuf("no")

local utf8 = require("utf8")
local terminal = import("terminal")
import("player")

local screen = love.graphics.newCanvas()
local hum = love.audio.newSource("assets/hum.ogg", "stream")
local win = love.audio.newSource("assets/win.ogg", "static")
local wrong = love.audio.newSource("assets/wrong.ogg", "static")

love.graphics.setFont(font)
love.keyboard.setKeyRepeat(true)
love.graphics.setShader(love.graphics.newShader("assets/shader.glsl"))

local start_command = commands.start

method love.load() {
terminal::write("╔═╗ ╔═════╗ ╔═════╗ ╔═╗ ╔═════╗ ╔═════╗ ╔═════╗ ╔═════╗", 400)
terminal::write("║ ║ ║ ╔═╗ ║ ║ ╔═╗ ║ ║ ║ ║ ╔═══╝ ║ ╔═╗ ║ ║ ╔═══╝ ║ ╔═══╝", 400)
terminal::write("║ ║ ║ ╚═╝ ║ ║ ╚═╝ ║ ║ ║ ║ ╚═══╗ ║ ╚═╝ ║ ║ ╚═══╗ ║ ╚═══╗", 400)
terminal::write("║ ║ ║ ╔═══╝ ║ ╔═══╝ ║ ║ ║ ╔═══╝ ║ ╔═╗ ║ ╚═══╗ ║ ║ ╔═══╝", 400)
terminal::write("║ ║ ║ ║ ║ ║ ║ ╚═══╗ ║ ╚═══╗ ║ ║ ║ ║ ╔═══╝ ║ ║ ╚═══╗", 400)
terminal::write("╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝", 400)
terminal::write("A game for the LÖVE Jam 2023 - Created by Maiori")
terminal::write("(Type 'guide' for instructions)")
hum::setLooping(true)
hum::setVolume(0.10)
hum::play()
}

method love.update(dt) {
leveltime += dt
local unfinished = terminal.unfinished[pointer]
if unfinished {
unfinished.progress += dt * unfinished.speed * 2
if unfinished.progress >= #unfinished.text {
unfinished.progress = nil
table.remove(terminal.unfinished, 1)
love.wheelmoved(0, -fontheight)
match unfinished.text::sub(-7) { //this is a hacky way to do this...
"glitch!" => {
terminal::corrupt()
}
"choice!" => {
win::play()
}
"o join." || " troll." || "ntions." => {
wrong::play()
}
}
}
} elseif hacked && leveltime > hacked {
terminal::corrupt()
hacked = leveltime + hackamount
hackamount /= 1.22
if hackamount < 0.00000000000001 {
hacked = nil
hackamount = 0.5
commands.clear.code()
setmetatable(commands, {})
commands.restart = start_command
terminal::write("GAME OVER", 1, 1, 0, 0)
terminal::write("Your server was destroyed...will you try again?", 15, 1, 0, 0)
terminal::write("Final Score: " .. score, nil, 1, 0, 0)
terminal::write("You messed up " .. ((mistakes - 1) * 2) .. " times.", nil, 1, 0, 0)
terminal::write("(Type 'restart' to try again)", nil, 1, 0, 0)
score = 0
mistakes = 1
}
}
}

global fn UpdateCanvas() {
love.graphics.clear()
local y = terminal::draw()
if terminal::finished() && !hacked {
love.graphics.setColor(0.125490196, 0.760784314, 0.054901961)
local text = "$ " .. terminal.input[1]
love.graphics.print(text, 5, y)
if math.floor(leveltime) % 2 == 0 {
love.graphics.print("_", 5 + font::getWidth(text), y)
}
}
}

method love.draw() {
screen::renderTo(UpdateCanvas)
love.graphics.setColor(1, 1, 1)
love.graphics.draw(screen)
}

method love.resize(_, height) {
screenheight = height - 10
screen = love.graphics.newCanvas()
love.wheelmoved(0, 0)
}
24 changes: 24 additions & 0 deletions samples/Clue/metatables.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local vector = {
x = 0, y = 0,
meta unary = fn(t) {
return {-t.x, -t.y}
}
meta tostring = fn(t) {
return "vector(" .. t.x .. ", " .. t.y .. ")"
}
meta + = fn(a, b) {
return {a.x + b.x, a.y + b.y}
}
meta - = fn(a, b) {
return {a.x - b.x, a.y - b.y}
}
meta * = fn(a, b) {
return {a.x * b.x, a.y * b.y}
}
meta / = fn(a, b) {
return {a.x / b.x, a.y / b.y}
}
meta == = fn(a, b) {
return a.x == b.x && a.y == b.y
}
}
12 changes: 12 additions & 0 deletions samples/Clue/mixed.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local bool_result = condition ? "true" : "false"
local result = 0
local output = "[Output] ";

result = match io.read("*n") {
1 => 1,
2 || 3 => 10
}

output ..= bool_result .. " " .. result

print(output)
Loading