Skip to content

Commit

Permalink
Merge branch 'main' into add-system-files-to-gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
NexusNull authored Nov 14, 2023
2 parents 798d30c + 0acdeca commit e7dd5e8
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*.pem
*.pub
/scripts/test.js

# System Files
.DS_Store
Thumbs.db
Thumbs.db
4 changes: 2 additions & 2 deletions design/drops.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#[0.00018,"mistletoe"],
#[0.00005,"candycane"],
#[0.00001,"open","xN"],
[0.00005,"candy0"], #originally 4X [11/10/19]
[0.00125,"candy1"], #originally 4X [11/10/19]
#[0.00005,"candy0"], #originally 4X [11/10/19]
#[0.00125,"candy1"], #originally 4X [11/10/19]
#[0.000015,"goldenegg"], #originally 0.000005
#[0.000001,"5bucks"],
#[0.0002,"gift0"],
Expand Down
2 changes: 1 addition & 1 deletion design/precomputed.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));

if(!f.in_args("nocheck") && f.read_file("~/thegame/stack/tocheck.txt")) // nocheck doesn't work [23/01/17]
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/electron_bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var image_size=require('image-size'),fs=require('fs');
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
var images={};

f.execs("rm -rf ~/thegame/electron/files");
Expand Down
235 changes: 235 additions & 0 deletions scripts/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
//var execsync=require('sync-exec');
var child_process=require('child_process');
var compressor=require("node-minify"),util=require("util"),fs=require("fs"),request=require('request');
var really_old=new Date(0);

function replace_all(str, find, replace)
{
return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
}

function cdate(time) // custom date/time format [12/06/15]
{
var time_str="",current=new Date(),arr=[current.getHours(),current.getMinutes(),current.getDate(),current.getMonth()+1,current.getYear()];
for(var i=0;i<arr.length;i++)
{
if(arr[i]<10) arr[i]="0"+arr[i];
else arr[i]=""+arr[i];
}
arr[4]=arr[4].substr(1,5);
if(time) time_str="["+arr[0]+":"+arr[1]+"]";
return time_str+"["+arr[2]+"/"+arr[3]+"/"+arr[4]+"]";
}

function string_to_int(s)
{
unique=0
for(var i=0;i<s.length;i++) unique=(unique*150 + s.charCodeAt(i))%123126580007
return unique;
}

function download(source,destination)
{
execso("wget "+source+" -O "+destination);
}

function add_log(storage,log)
{
logs=storage.getItem("logs");
if(!logs) logs=[];
logs.push({date:new Date(),message:log});
console.log("[add_log] "+log);
if(logs.length>1000) logs=logs.slice(4,1200);
storage.setItem("logs",logs);
}

function report_logs(storage)
{
logs=storage.getItem("logs");
if(!logs) logs=[];
for(var i=0;i<logs.length;i++)
{
console.log("["+logs[i].date+"]: "+logs[i].message);
}
}

function in_between_from_file(file,prefix,suffix)
{
return read_file(file.replace("~",process.env.HOME)).split(prefix)[1].split(suffix)[0];
}

function lib_version(cur)
{
return in_between_from_file(cur.file,cur.prefix,cur.suffix);
}

function fetch(url,success,errorf)
{
request(url, function (error, response, content) {
if(!error && response.statusCode == 200)
{
success(content);
}
else
{
errorf(error);
}
});
}

function endswith(s,suffix)
{
return s.indexOf(suffix, s.length - suffix.length) !== -1;
}

function execs(code)
{
try{
//output=execsync(code);
//if(output.stderr) console.log("execs.Error: "+output.stderr);
//return output.stdout;
output=child_process.execSync(code);
if(output.toString) output=output.toString();
return output;
}
catch(e){console.log("execs.Error: "+e)}
}
function sleep(n){
execs("sleep "+n);
}

function color(message,color)
{
color={"black":"0;30","gray":"1;30","blue":"0;34","lblue":"1;34","green":"0;32","lgreen":"1;32","cyan":"0;36","lcyan":"1;36",
"red":"0;31","lred":"1;31","purple":"0;35","lpurple":"1;35","orange":"0;33","yellow":"1;33","lgray":"0;37","white":"1;37"}[color];
return red="\033["+color+"m"+message+"\033[0m";
}

function ccolor(a1,a2,a3)
{
if(!a2 && !a3) return color(a1,"orange");
if(a1!=a2 && a1!=a3) return color(a1,"red");
return color(a1,"green");
}

function execso(code)
{
try{
//var output=execsync(code);
//if(output.stdout) console.log(output.stdout);
//if(output.stderr) console.log("execs.Error: "+output.stderr);
output=child_process.execSync(code);
if(output.toString) output=output.toString();
console.log(output);
}
catch(e){console.log("execso.Error: "+e);}
}

function minify_all(path,files)
{
path=path.replace("~",process.env.HOME);
for(var sub_path in files)
{
for(var i=0;i<files[sub_path].length;i++)
{
var type='sqwish',file=files[sub_path][i],the_path=path+"/"+sub_path+"/"; // previously 'yui-css' but requires Java [16/06/20]
if(sub_path=="-") the_path=path+"/"; //[17/10/15]
console.log("Minifying "+the_path+file);
if(endswith(file,".js")) type='gcc'; // previously 'yui-js' - but can't minify es6 :/ [02/06/20]
var promise=compressor.minify({
compressor: type,
sync:true,
input: the_path+file,
output: the_path+file});
a=function(the_path,file){
promise.then(function(){
console.log("Minification complete: "+the_path+file);
}).catch(function(err){
console.log("Minification exception: "+the_path+file);
console.log(err);
});
}
a(the_path,file);
}
}
}

function in_args(strs)
{
if(typeof strs == "string") strs=[strs];
for(var j=0;j<strs.length;j++)
{
str=strs[j];
for(var i=0;i<process.argv.length;i++)
if(process.argv[i]==str) return true;
}
return false;
}

function get_arg(num)
{
if(process.argv.length>num) return process.argv[num];
return false;
}

function is_production()
{
if(in_args("live") || in_args("production")) return " production ";
return "";
}

function is_sdk(){ return !is_production(); }

function ch(path)
{
path=path.replace("~",process.env.HOME);
process.chdir(path);
}

function read_file(path)
{
path=path.replace("~",process.env.HOME);
return fs.readFileSync(path,{encoding:'utf-8'});
}

function write_file(path,content)
{
path=path.replace("~",process.env.HOME);
fs.writeFileSync(path,content);
}

function mssince(t,ref)
{
if(!ref) ref=new Date();
return ref.getTime() - t.getTime();
}
function ssince(t,ref) { return mssince(t,ref)/1000.0; }
function msince(t,ref) { return mssince(t,ref)/60000.0; }
function hsince(t,ref) { return mssince(t,ref)/3600000.0; }

module.exports={
util:util, format:util.format,
execs:execs,
execso:execso,
minify_all:minify_all,
is_production:is_production,
is_sdk:is_sdk,
ch:ch,
in_args:in_args,
get_arg:get_arg,
read_file:read_file,
write_file:write_file,
color:color,
ccolor:ccolor,
fetch:fetch,
in_between_from_file:in_between_from_file,
lib_version:lib_version,
mssince:mssince,ssince:ssince,msince:msince,hsince:hsince,
add_log:add_log,report_logs:report_logs,
really_old:really_old,
download:download,
string_to_int:string_to_int,
cdate:cdate,
sleep:sleep,
replace_all:replace_all,
}
2 changes: 1 addition & 1 deletion scripts/keep_alive.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

setInterval(function(){
Expand Down
2 changes: 1 addition & 1 deletion scripts/list_commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

servers.forEach(function(server){
Expand Down
2 changes: 1 addition & 1 deletion scripts/list_servers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

for(var id in machines)
Expand Down
2 changes: 1 addition & 1 deletion scripts/precompute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var image_size=require('image-size'),fs=require('fs');
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
var images={};

var data=f.read_file("~/thegame/design/sprites.py");
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare_server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
f.execs("rm -rf ~/deploy/server");
f.execs("mkdir ~/deploy/server");
f.execs("cp -r ~/thegame/node/* ~/deploy/server");
Expand Down
2 changes: 1 addition & 1 deletion scripts/process_gallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var image_size=require('image-size'),fs=require('fs');
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
var images=[];

[["/images/tiles/monsters/","monsters",".png"],["/images/tiles/characters/","characters",".png"],["/images/tiles/characters/tribes/","tribes",".png"],["/images/tiles/characters/npcs/","npcs",".png"],["/images/tiles/map/","map",".png"],["/images/tiles/examples/","examples",".png"],["/images/tiles/examples/","examples_gif",".gif"],["/images/sprites/animations/","animations",".png"],["/images/sprites/emblems/","emblems",".png"],["/images/sprites/weather/","weather",".png"],["/images/tiles/animations/","new animations",".png"]].forEach(function(fext){
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_a_command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

for(var id in machines)
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_servers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

servers.forEach(function(server){
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_iap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var secret="ac2b8964dffd4a8a961f427d1257d8f7";
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
var iap = require('in-app-purchase');
var receipt_file="/Applications/Adventure Land.app/Contents/_MASReceipt/receipt";
//var receipt_file="/Users/kaan/Downloads/receipt";
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_machines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var f=require(process.env.HOME+"/thegeobird/scripts/functions.js");
var path=require("path"),f=require(path.resolve(__dirname, "functions.js"));
require(process.env.HOME+"/thegame/scripts/data.js");

f.execso("node ~/gscripts/prepare_server.js;");
Expand Down

0 comments on commit e7dd5e8

Please sign in to comment.