use log instead of console

This commit is contained in:
2025-05-29 00:39:14 -05:00
parent 1040c61863
commit 8d9bb4a2c9
60 changed files with 446 additions and 467 deletions

View File

@@ -12,9 +12,7 @@ myblob.write_bit(0)
myblob.__proto__.toString = function() {
return `[${this.length} bit blob]`
}
console.log(myblob.toString())
console.log(myblob)
console.log(myblob.length)
log.console(myblob.toString(), myblob, myblob.length)
var input = use('input')
@@ -63,7 +61,7 @@ function updateTitle() {
break;
}
console.log(title)
log.console(title)
}
// Initialize title
@@ -125,16 +123,16 @@ function handleMouseButtonUp(e) {
}
if (mover.tryMove(grid.at(selectPos)[0], c)) {
console.log("Made move from", selectPos, "to", c);
log.console("Made move from", selectPos, "to", c);
// Send move to opponent
console.log("Sending move to opponent:", opponent);
log.console("Sending move to opponent:", opponent);
send(opponent, {
type: 'move',
from: selectPos,
to: c
});
isMyTurn = false; // It's now opponent's turn
console.log("Move sent, now opponent's turn");
log.console("Move sent, now opponent's turn");
selectPos = null;
updateTitle();
}
@@ -305,11 +303,11 @@ function startServer() {
updateTitle();
$_.portal(e => {
console.log("Portal received contact message");
log.console("Portal received contact message");
// Reply with this actor to establish connection
console.log (json.encode($_))
log.console (json.encode($_))
send(e, $_);
console.log("Portal replied with server actor");
log.console("Portal replied with server actor");
}, 5678);
}
@@ -318,10 +316,10 @@ function joinServer() {
updateTitle();
function contact_fn(actor, reason) {
console.log("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason);
log.console("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason);
if (actor) {
opponent = actor;
console.log("Connection established with server, sending join request");
log.console("Connection established with server, sending join request");
// Send a greet message with our actor object
send(opponent, {
@@ -329,7 +327,7 @@ function joinServer() {
client_actor: $_
});
} else {
console.log(`Failed to connect: ${json.encode(reason)}`);
log.console(`Failed to connect: ${json.encode(reason)}`);
gameState = 'waiting';
updateTitle();
}
@@ -349,33 +347,33 @@ $_.receiver(e => {
else if (e.kind == 'draw')
send(e, draw())
else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet')
console.log("Receiver got message:", e.type, e);
log.console("Receiver got message:", e.type, e);
if (e.type === 'quit') os.exit()
if (e.type === 'greet') {
console.log("Server received greet from client");
log.console("Server received greet from client");
// Store the client's actor object for ongoing communication
opponent = e.client_actor;
console.log("Stored client actor:", json.encode(opponent));
log.console("Stored client actor:", json.encode(opponent));
gameState = 'connected';
updateTitle();
// Send game_start to the client
console.log("Sending game_start to client");
log.console("Sending game_start to client");
send(opponent, {
type: 'game_start',
your_color: 'black'
});
console.log("game_start message sent to client");
log.console("game_start message sent to client");
}
else if (e.type === 'game_start') {
console.log("Game starting, I am:", e.your_color);
log.console("Game starting, I am:", e.your_color);
myColor = e.your_color;
isMyTurn = (myColor === 'white');
gameState = 'connected';
updateTitle();
} else if (e.type === 'move') {
console.log("Received move from opponent:", e.from, "to", e.to);
log.console("Received move from opponent:", e.from, "to", e.to);
// Apply opponent's move
var fromCell = grid.at(e.from);
if (fromCell.length) {
@@ -383,12 +381,12 @@ $_.receiver(e => {
if (mover.tryMove(piece, e.to)) {
isMyTurn = true; // It's now our turn
updateTitle();
console.log("Applied opponent move, now my turn");
log.console("Applied opponent move, now my turn");
} else {
console.log("Failed to apply opponent move");
log.console("Failed to apply opponent move");
}
} else {
console.log("No piece found at from position");
log.console("No piece found at from position");
}
} else if (e.type === 'mouse_move') {
// Update opponent's mouse position

View File

@@ -101,7 +101,7 @@ $_.receiver(function(msg) {
break;
case 'status':
console.log(`got status request. current is ${json.encode(get_status())}`)
log.console(`got status request. current is ${json.encode(get_status())}`)
send(msg, {
type: 'status_response',
...get_status()

View File

@@ -8,13 +8,13 @@ var waiting_client = null;
var match_id = 0;
$_.portal(e => {
console.log("NAT server: received connection request");
log.console("NAT server: received connection request");
if (!is_actor(e.actor))
send(e, {reason: "Must provide the actor you want to connect."});
if (waiting_client) {
console.log(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`)
log.console(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`)
send(waiting_client, e.actor)
send(e, waiting_client.actor)
@@ -25,5 +25,5 @@ $_.portal(e => {
waiting_client = e
console.log(`actor ${json.encode(e.actor)} is waiting ...`)
log.console(`actor ${json.encode(e.actor)} is waiting ...`)
}, 4000);

View File

@@ -1,11 +1,11 @@
console.log(`nat client starting`)
log.console(`nat client starting`)
$_.contact((actor, reason) => {
if (actor) {
console.log(`trying to message ${json.encode(actor)}`)
log.console(`trying to message ${json.encode(actor)}`)
send(actor, {type:"greet"})
} else {
console.log(json.encode(reason))
log.console(json.encode(reason))
}
}, {
address: "108.210.60.32", // NAT server's public IP
@@ -16,7 +16,7 @@ $_.contact((actor, reason) => {
$_.receiver(e => {
switch(e.type) {
case 'greet':
console.log(`hello!`)
log.console(`hello!`)
break
}
})

View File

@@ -23,23 +23,23 @@ var stats_loaded = false;
// Initialize Steam
function init_steam() {
if (!steam) {
console.log("Steam module not available");
log.console("Steam module not available");
return false;
}
console.log("Initializing Steam...");
log.console("Initializing Steam...");
steam_available = steam.steam_init();
if (steam_available) {
console.log("Steam initialized successfully");
log.console("Steam initialized successfully");
// Request current stats/achievements
if (steam.stats.stats_request()) {
console.log("Stats requested");
log.console("Stats requested");
stats_loaded = true;
}
} else {
console.log("Failed to initialize Steam");
log.console("Failed to initialize Steam");
}
return steam_available;
@@ -59,13 +59,13 @@ function unlock_achievement(achievement_name) {
// Check if already unlocked
var unlocked = steam.achievement.achievement_get(achievement_name);
if (unlocked) {
console.log("Achievement already unlocked:", achievement_name);
log.console("Achievement already unlocked:", achievement_name);
return true;
}
// Unlock it
if (steam.achievement.achievement_set(achievement_name)) {
console.log("Achievement unlocked:", achievement_name);
log.console("Achievement unlocked:", achievement_name);
// Store stats to make it permanent
steam.stats.stats_store();
@@ -87,7 +87,7 @@ function update_stat(stat_name, value, is_float) {
}
if (success) {
console.log("Stat updated:", stat_name, "=", value);
log.console("Stat updated:", stat_name, "=", value);
steam.stats.stats_store();
}
@@ -115,7 +115,7 @@ function start_game() {
total_score = get_stat(STATS.TOTAL_SCORE, false);
current_score = 0;
console.log("Starting game #" + (games_played + 1));
log.console("Starting game #" + (games_played + 1));
}
function end_game(score) {
@@ -167,7 +167,7 @@ function load_from_cloud() {
function cleanup_steam() {
if (steam_available) {
steam.steam_shutdown();
console.log("Steam shut down");
log.console("Steam shut down");
}
}