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 5 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 @@ -1121,6 +1121,15 @@ Cloud Firestore Security Rules:
filenames:
- firestore.rules
language_id: 407996372
Clue:
type: programming
tm_scope: source.clue
ace_mode: text
codemirror_mode: text
color: "#0009b5"
extensions:
- ".clue"
language_id: 163763508
CoNLL-U:
type: data
extensions:
Expand Down
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
27 changes: 27 additions & 0 deletions samples/Clue/graph.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
io.stdout::setvbuf("no");

import("line");

method love.draw() {
love.graphics.print(formula, 0, 0, 0, 2);
love.graphics.translate(150, 450);
love.graphics.setColor(0.3, 0.3, 0.3);
for x = -150, 650, 10 {
if x == 0 {continue}
love.graphics.line(x, 150, x, -450);
}
for y = -450, 150, 10 {
if y == 0 {continue}
love.graphics.line(-150, y, 650, y);
}
love.graphics.setColor(1, 1, 1);
love.graphics.line(0, 150, 0, -450);
love.graphics.line(-150, 0, 650, 0);
if dots {
love.graphics.line(dots);
} else {
love.graphics.origin()
love.graphics.setColor(1, 0, 0);
love.graphics.printf(errormsg, 0, 300, 400, "center", 0, 2);
}
}
36 changes: 36 additions & 0 deletions samples/Clue/line.clue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
static dots, formula, errormsg;
dots = {0, 0, 0, 0};
formula = "y=";
errormsg = "";

local utf8 = require("utf8");
local env = {x = 0, y = 0};

for k, v of math {
env[k] = v;
}

method love.textinput(key) {
formula ..= key;
dots = {};
try {
local formula, errormsg = loadstring(formula);
if !formula {error(errormsg);}
setfenv(formula, env);
for x = -150, 650 {
env.x = x;
formula();
table.insert(dots, env.x || 0);
table.insert(dots, -(env.y || 0));
}
} catch error {
dots = nil;
errormsg = error;
}
}

method love.keypressed(key) {
if key == "backspace" && utf8.len(formula) > 0 {
formula = ($)::sub(1, utf8.len($)-1);
}
}
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)
}
Loading