mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-02 20:42:36 +02:00
Remove Python console stuff
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import utils
|
||||
# example script
|
||||
|
||||
def noise(typ,amount=50):
|
||||
for xx in range(4,612):
|
||||
for yy in range(4,384):
|
||||
if(random.randrange(0,100)<amount):
|
||||
tpt.create(xx,yy,typ)
|
||||
|
||||
def increment(amount=1):
|
||||
for xx in range(4,612):
|
||||
for yy in range(4,384):
|
||||
i = tpt.get_pmap(xx,yy)>>8
|
||||
t = tpt.get_prop(i,"type")+amount
|
||||
if t>=148:
|
||||
t=t-148
|
||||
if t==128:
|
||||
t=129
|
||||
if t==55:
|
||||
t=56
|
||||
tpt.set_type(i=i,settoint=t)
|
@@ -1,211 +0,0 @@
|
||||
import tpt
|
||||
import sys
|
||||
import time
|
||||
import socket
|
||||
import tpt_console
|
||||
|
||||
HOST="irc.freenode.net"
|
||||
PORT=6667
|
||||
name=tpt.get_name()
|
||||
print "name is %s"%repr(name)
|
||||
if(name==""):
|
||||
#fuck. abort?
|
||||
raise SystemExit("please log in!")
|
||||
|
||||
def raw(s,st):
|
||||
s.send("%s\n\r"%st)
|
||||
|
||||
def init():
|
||||
global frame,s,rec,readbuffer,namelist,typing,typed,IDENT,NICK
|
||||
global REALNAME,CHANNEL
|
||||
frame=0
|
||||
s=None
|
||||
rec=([("",0,0,0,255)]*20)+[("connected.",255,0,0,128)]
|
||||
readbuffer=""
|
||||
namelist=[]
|
||||
typing=False
|
||||
typed=""
|
||||
NICK=name+"[tpt]"
|
||||
IDENT=name+"[tpt]"
|
||||
REALNAME=name
|
||||
CHANNEL="#powder"
|
||||
readbuffer=""
|
||||
|
||||
def exit():
|
||||
raw(s,"QUIT")
|
||||
s.close()
|
||||
|
||||
def console_handle(txt):
|
||||
"""
|
||||
:doxin!~lieuwe@unaffiliated/lieuwe JOIN :#foobar7
|
||||
:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG #foobar7 :there
|
||||
:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG #foobar7 :ACTION is fat
|
||||
"""
|
||||
lst=txt.split(" ")
|
||||
if(lst[0]=="/me"):
|
||||
rec.append(("%s %s"%(NICK,txt[4:]),255,0,255,128))
|
||||
raw(s,"PRIVMSG %s :\x01ACTION %s\x01"%(CHANNEL,txt[4:]))
|
||||
tpt.console_close()
|
||||
else:
|
||||
rec.append(("<%s>: %s"%(NICK,txt),255,255,0,128))
|
||||
raw(s,"PRIVMSG %s :%s"%(CHANNEL,txt))
|
||||
tpt.console_close()
|
||||
|
||||
def key(keyy) :
|
||||
try:
|
||||
a=key.pmod
|
||||
except:
|
||||
key.pmod=(False,False,False)
|
||||
global typing,typed
|
||||
#print "got %s"%repr(keyy)
|
||||
ctrl1,ctrl2,alt1,alt2,shift1,shift2=tpt.get_modifier()
|
||||
mod=(ctrl1 or ctrl2,alt1 or alt2,shift1 or shift2)
|
||||
skip=False
|
||||
if(not key.pmod[0] and mod[0]):
|
||||
skip=True
|
||||
if(not key.pmod[1] and mod[1]):
|
||||
skip=True
|
||||
if(not key.pmod[2] and mod[2]):
|
||||
skip=True
|
||||
key.pmod=mod
|
||||
if(skip):
|
||||
return
|
||||
|
||||
if(typing and ord(keyy)>=32 and ord(keyy)<=126):
|
||||
if(mod[2]):
|
||||
typed+=keyy.upper()#needs to be fixed for special chars
|
||||
else:
|
||||
typed+=keyy
|
||||
if(keyy=="\x1b" and typing):
|
||||
typing=False
|
||||
typed=""
|
||||
tpt.shortcuts_enable()
|
||||
if(keyy=="t" and typing==False):
|
||||
typing=True
|
||||
tpt.shortcuts_disable()
|
||||
if(keyy=="\r" and typing==True):
|
||||
console_handle(typed)
|
||||
typed=""
|
||||
typing=False
|
||||
tpt.shortcuts_enable()
|
||||
#got '\t'
|
||||
#got '\x08'
|
||||
if(keyy=="\x08"):
|
||||
typed=typed[:-1]
|
||||
#if(keyy=="\t"):
|
||||
# startswith=
|
||||
|
||||
|
||||
def step():
|
||||
global frame,s,rec,readbuffer,namelist
|
||||
frame+=1
|
||||
if(frame==1):
|
||||
tpt.console_close()
|
||||
#lets see if we can seize the console:
|
||||
tpt_console._handle=console_handle
|
||||
if(frame==2):
|
||||
tpt.draw_fillrect(0,0,612,384,0,0,0,128)
|
||||
tpt.draw_text(32,32,"opening connection\nhold on to your pants.",255,255,255)
|
||||
if(frame==3):
|
||||
s=socket.socket()
|
||||
s.settimeout(5)
|
||||
s.connect((HOST, PORT))
|
||||
raw(s,"NICK %s" % NICK)
|
||||
raw(s,"USER %s %s bla :%s" % (IDENT, HOST, REALNAME))
|
||||
s.settimeout(0)
|
||||
if(frame==120):
|
||||
raw(s,"JOIN %s"%CHANNEL)
|
||||
rec.append(("joined",255,0,0,255))
|
||||
if(frame>=3):
|
||||
try:
|
||||
readbuffer=readbuffer+s.recv(1024)
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
temp=readbuffer.split("\n")
|
||||
readbuffer=temp.pop()
|
||||
|
||||
for line in temp:
|
||||
line=line.strip()
|
||||
#print repr(line)
|
||||
line=line.split()
|
||||
if(line[1]=="PRIVMSG"):
|
||||
#:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG doxin[tpt] :some shit
|
||||
frm=line[0][1:].partition("!")[0]
|
||||
msg=' '.join(line[3:])[1:]
|
||||
tmp=["<",frm,"> ",msg]
|
||||
if(msg[0]=="\x01" and msg[-1]=="\x01"):
|
||||
msg=msg[8:-1]#ACTION
|
||||
tmp=[frm," ",msg]
|
||||
if(line[2]==NICK):
|
||||
rec.append((''.join(tmp),255,255,255,255))
|
||||
else:
|
||||
rec.append((''.join(tmp),255,255,255,128))
|
||||
elif(line[0]=="PING"):
|
||||
raw(s,"PONG %s"%line[1])
|
||||
elif(line[1]=="353"):
|
||||
#:leguin.freenode.net 353 doxin[tpt] = #powder :doxin[tpt] ZebraineZ _-_Rafael_-_ doxin bildramer BlueMaxima TheRazorsEDGE raj-k webb|AP where @devast8a Merbo FrozenKnight EppyMoon EvilJStoker Mortvert SpitfireWP @frankbro Ares
|
||||
names=line[4:]
|
||||
namelist=[]
|
||||
for item in names:
|
||||
item=item.strip()
|
||||
r=255
|
||||
g=255
|
||||
b=255
|
||||
if(item[0]==":"):
|
||||
item=item[1:]
|
||||
elif(item[0]=="@"):
|
||||
g=0
|
||||
b=0
|
||||
namelist.append((item,r,g,b,128))
|
||||
elif(line[1]=="JOIN"):
|
||||
#':savask!~savask@95-190-25-195-xdsl-dynamic.kuzbass.net JOIN :#powder'
|
||||
tmp=line[0][1:].partition("!")[0]
|
||||
namelist.append((tmp,255,255,255,128))
|
||||
rec.append(("%s joined"%name,0,255,0,128))
|
||||
elif(line[1]=="PART"):
|
||||
#':savask!~savask@95-190-25-195-xdsl-dynamic.kuzbass.net PART #powder :"Leaving."'
|
||||
tmp=line[0][1:].partition("!")[0]
|
||||
msg=' '.join(line[2:])[1:]
|
||||
rem=None
|
||||
for item in namelist:
|
||||
if(item[0]==tmp or item[0]=="@"+tmp):
|
||||
rem=item
|
||||
rec.append(("%s parted: %s"%(name,msg),0,255,0,128))
|
||||
if(rem!=None):
|
||||
namelist.remove(rem)
|
||||
elif(line[1]=="NICK"):
|
||||
#:doxin!~lieuwe@unaffiliated/lieuwe NICK :d0x1n
|
||||
tmp=line[0][1:].partition("!")[0]
|
||||
rem=None
|
||||
for item in namelist:
|
||||
if(item[0]==tmp or item[0]=="@"+tmp):
|
||||
rem=item
|
||||
rec.append(("%s is now known as %s"%(name,line[2]),0,255,0,128))
|
||||
if(rem!=None):
|
||||
if(rem[0][0]=="@"):
|
||||
namelist.append(("@"+line[2][1:],rem[1],rem[2],rem[3],rem[4]))
|
||||
else:
|
||||
namelist.append((line[2][1:],rem[1],rem[2],rem[3],rem[4]))
|
||||
namelist.remove(rem)
|
||||
|
||||
|
||||
|
||||
|
||||
yy=32
|
||||
if(len(rec)>20):
|
||||
rec=rec[-20:]
|
||||
for item in rec:
|
||||
tpt.draw_text(8,yy,item[0],item[1],item[2],item[3],item[4])
|
||||
yy+=8
|
||||
if(typing):
|
||||
if(frame%30<15):
|
||||
tpt.draw_text(8,yy,typed+"|",255,255,255,255)
|
||||
else:
|
||||
tpt.draw_text(8,yy,typed,255,255,255,255)
|
||||
#print namelist
|
||||
yy=32
|
||||
for item in namelist:
|
||||
tpt.draw_text(604-tpt.get_width(item[0]),yy,item[0],item[1],item[2],item[3],item[4])
|
||||
yy+=8
|
||||
|
@@ -1,9 +0,0 @@
|
||||
import tpt
|
||||
def init():
|
||||
pass
|
||||
def key(keyy):
|
||||
pass
|
||||
def step():
|
||||
tpt.draw_text(100,100,"FUCK YEAH!",255,255,255,255)
|
||||
def exit():
|
||||
pass
|
@@ -1,116 +0,0 @@
|
||||
import tpt
|
||||
from tpt import *
|
||||
import sys
|
||||
import code
|
||||
import ctypes
|
||||
import traceback
|
||||
DEBUG=False
|
||||
|
||||
#print "console module loaded."
|
||||
#redirect stdout like this:
|
||||
class logger:
|
||||
def write(self,txt):
|
||||
txt=txt.strip().split("\n")[-1]
|
||||
repr(txt)
|
||||
tpt.log(txt)
|
||||
if(DEBUG==False):
|
||||
sys.stdout=logger()
|
||||
sys.stderr=logger()
|
||||
|
||||
|
||||
element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
|
||||
"nitr":8,"clne":9,"gas":10,"plex":11,"goo":12,"icei":13,"metl":14,"sprk":15,
|
||||
"snow":16,"wood":17,"neut":18,"plut":19,"plnt":20,"acid":21,"void":22,
|
||||
"wtrv":23,"cnct":24,"dstw":25,"salt":26,"sltw":27,"dmnd":28,"bmtl":29,
|
||||
"brmt":30,"phot":31,"uran":32,"wax":33,"mwax":34,"pscn":35,"nscn":36,
|
||||
"lntg":37,"insl":38,"bhol":39,"whol":40,"rbdm":41,"lrbd":42,"ntct":43,
|
||||
"sand":44,"glas":45,"ptct":46,"bgla":47,"thdr":48,"plsm":49,"etrd":50,
|
||||
"nice":51,"nble":52,"btry":53,"lcry":54,"stkm":55,"swch":56,"smke":57,
|
||||
"desl":58,"coal":59,"lo2":60,"o2":61,"inwr":62,"yest":63,"dyst":64,
|
||||
"thrm":65,"glow":66,"brck":67,"hflm":68,"firw":69,"fuse":70,"fsep":71,
|
||||
"amtr":72,"bcol":73,"pcln":74,"hswc":75,"iron":76,"mort":77,"gol":78,
|
||||
"hlif":79,"asim":80,"2x2":81,"dani":82,"amoe":83,"move":84,"pgol":85,
|
||||
"dmoe":86,"34":87,"llif":88,"stan":89,"spng":90,"rime":91,"fog":92,
|
||||
"bcln":93,"love":94,"deut":95,"warp":96,"pump":97,"fwrk":98,"pipe":99,
|
||||
"frzz":100,"frzw":101,"grav":102,"bizr":103,"bizrg":104,"bizrs":105,
|
||||
"inst":106,"isoz":107,"iszs":108,"prti":109,"prto":110,"pste":111,
|
||||
"psts":112,"anar":113,"vine":114,"invis":115,"equalvel":116,"spawn2":117,
|
||||
"spawn":118,"shld1":119,"shld2":120,"shld3":121,"shld4":122,"lolz":123,
|
||||
"wifi":124,"filt":125,"aray":126,"bray":127,"stkm2":128,"bomb":129,
|
||||
"c5":130,"sing":131,"qrtz":132,"pqrt":133,"seed":134,"maze":135,
|
||||
"coag":136,"wall":137,"gnar":138,"repl":139,"myst":140,"boyl":141,
|
||||
"lote":142,"frg2":143,"star":144,"frog":145,"bran":146,"wind":147,
|
||||
"num":148}
|
||||
|
||||
|
||||
def fork_unblock():
|
||||
pass#i need to implement this some day.
|
||||
def error(ex):
|
||||
traceback.print_exc()
|
||||
err=traceback.format_exc()
|
||||
sys.stdout.write(err)
|
||||
|
||||
def clean():
|
||||
#add any functions that must be reachable here.
|
||||
"""copy=["__builtins__","__name__","__doc__","__package__",'tpt','clean',
|
||||
'element','fork','_fork','fork_status','fork_unblock','sys']
|
||||
handle.glob={}
|
||||
for item in copy:
|
||||
handle.glob[item]=globals()[item]"""
|
||||
handle.glob=globals()
|
||||
handle.buf=""
|
||||
|
||||
def handle(txt):
|
||||
try:
|
||||
a=handle.glob
|
||||
except:
|
||||
clean()
|
||||
try:
|
||||
_handle(txt)
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
|
||||
def _handle(txt):
|
||||
#print "handling '%s'"%txt
|
||||
try:
|
||||
sys.stdout.write(repr(eval(txt,handle.glob)))
|
||||
except:
|
||||
try:
|
||||
exec txt in handle.glob
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
|
||||
|
||||
_extensions=[]
|
||||
def loadext(fname):
|
||||
ext=__import__(fname)
|
||||
ext.init()
|
||||
_extensions.append(ext)
|
||||
|
||||
def keypress(key):
|
||||
unload=[]
|
||||
for item in _extensions:
|
||||
try:
|
||||
item.key(key)
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
unload.append(item)
|
||||
for item in unload:
|
||||
item.exit()
|
||||
_extensions.remove(item)
|
||||
|
||||
|
||||
def step():
|
||||
unload=[]
|
||||
for item in _extensions:
|
||||
try:
|
||||
item.step()
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
unload.append(item)
|
||||
for item in unload:
|
||||
try:
|
||||
item.exit()
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
_extensions.remove(item)
|
Reference in New Issue
Block a user