Files
Diabolo/tools/implement_v15.py
T

85 lines
6.8 KiB
Python

from pathlib import Path
root=Path(__file__).resolve().parent.parent/'Demon_v0.15'
p=root/'workshop.gd';s=p.read_text(encoding='utf-8-sig')
def change(a,b):
global s
if a not in s:raise RuntimeError('Missing '+a[:100])
s=s.replace(a,b)
def function(name,body):
global s
start=s.index('func '+name+'(');end=s.find('\nfunc ',start+1)
if end<0:end=len(s)
s=s[:start]+body.strip()+'\n'+s[end:]
change('const TITLES=["Алтарь плети","Дыба","Колесо","Железная дева"]','const TITLES=["Алтарь плети","Дыба","Колесо","Железная дева","Музыкальный стул","Котёл"]')
change('const PRICES=[40,80,140,220]','const PRICES=[40,80,140,220,300,380]')
change('Vector2i(3,3)]','Vector2i(3,3),Vector2i(3,3),Vector2i(4,4)]')
change('const AREA=Vector2i(9,9)','const AREA=Vector2i(12,9)\nconst EXTRA=preload("res://new_equipment.gd")')
change('var g\n','var g\nvar sentences\nvar dialogue_clock=6.0\nvar dialogue_turn=0\n')
change('\tg=game\n','\tg=game\n\tsentences=preload("res://judgement.gd").new();sentences.setup(self)\n')
change('Vector2(496,490)','Vector2(496,638)')
change('for i in range(4):','for i in range(TITLES.size()):')
change('unlock=0;helper_speed=0;automation=false;spawn_clock=0;darkness=0','unlock=0;helper_speed=0;automation=false;spawn_clock=0;darkness=0\n\tdialogue_clock=6;dialogue_turn=0')
change('elif node is Light3D:node.hide()','elif node is Light3D:node.hide()\n\t\telif node is AudioStreamPlayer3D:node.stop()')
change('\tvar removed=selected','\tvar removed=selected\n\tif not sentences.can_remove(s):message("Это орудие ещё нужно душам. Используй перемещение.");return')
change('soul.assigned-=1','soul.assigned-=1\n\t\tif soul.get("origin_station",-1)>removed:soul.origin_station-=1')
change('Rect2(-7.1,-4.8,14.1,10.5)','Rect2(-7.1,-4.8,18.15,10.5)')
change('"operator":-1}','"operator":-1,"ready":false}')
change('0,29),clampi','0,37),clampi')
change('Rect2i(0,0,30,22)','Rect2i(0,0,38,22)')
change('for x in range(30):','for x in range(38):')
change('(p.x>4 and p.y< -3.1) or (p.x>5.7 and p.y>3)','(p.x>4 and p.x<7.5 and p.y< -3.1) or (p.x>5.7 and p.x<7.5 and p.y>3)')
change('"unlock1","unlock2","unlock3":','"unlock1","unlock2","unlock3","unlock4","unlock5":')
change('s.get("state","")=="held").size()','s.get("state","")=="held" and s.get("queue_reserved",true)).size()')
change('if i>=0:g.souls[i].state="queue"','if i>=0:sentences.drop(g.souls[i])')
change('if d.soul>=0:return false','if d.soul>=0 or not sentences.accepts(s,d.selected):return false\n\tsentences.release_origin(s)\n\ts.queue_reserved=false;d.ready=false')
change('elif d.selected==3:s.visual.position=Vector3(0,.22,0)','elif d.selected==3:s.visual.position=Vector3(0,.22,0)\n\telif d.selected==4:s.visual.position=Vector3(0,-.25,0);s.visual.scale=Vector3.ONE*.9\n\telif d.selected==5:s.visual.position=Vector3(0,.45,0);s.visual.scale=Vector3.ONE*.85')
change('s["pose_target"]=s.visual.transform;s.node.rotation=Vector3(0,d.turns*PI/2,0)','s["pose_target"]=s.visual.transform;s.node.rotation=Vector3(0,d.turns*PI/2,0)\n\tannounce_soul(s)')
function('finish','''func finish(d):
var index=g.index_of(d.soul)
if index<0:return
var soul=g.souls[index]
var complete=sentences.complete_stage(d)
EXTRA.animate(g,d,0,false)
if not complete:return
g.life.burn(soul);g.souls.remove_at(index)
var count=soul.required.size()
g.coins+=10*count;g.done+=1
for stage_index in range(count):g.development.reward()
g.floating("+%d ЗОЛОТА +%d ОПЫТА" % [10*count,20*count],d.device.position+Vector3(0,2.8,0),Color("c8ae75"))
d.soul=-1;d.cooldown=2.6;d.release_clock=2.05;d.operator=-1;d.bar.hide()
if d.flame:d.flame.hide()
refresh();g.save_progress()
''')
change('if i<0:\n\t\tif s.selected==3:','if i<0:\n\t\tEXTRA.animate(g,s,dt,false)\n\t\tif s.selected==3:')
change('\tvar soul=g.souls[i]\n\tif s.placement>0:','\tvar soul=g.souls[i]\n\tif s.ready:\n\t\tEXTRA.animate(g,s,dt,false)\n\t\ts.bar.visible=soul.state in ["ready","reserved_next"]\n\t\ts.bar.position=g.camera.unproject_position(s.device.position+Vector3(0,3.4,0))-Vector2(48,0)\n\t\treturn\n\tif s.placement>0:')
change('elif s.selected==2:s.elapsed+=dt*rate','elif s.selected==2:s.elapsed+=dt*rate\n\t\telif s.selected>=4:s.elapsed+=dt*rate')
change('elif s.selected==3:progress=(s.elapsed if s.stage==0 else .35+s.elapsed)/3.35','elif s.selected==3:progress=(s.elapsed if s.stage==0 else .35+s.elapsed)/3.35\n\telif s.selected>=4:progress=s.elapsed/(6.0 if s.selected==4 else 7.0)')
change('if s.flame:s.flame.visible=active and s.stage==1','if s.flame:s.flame.visible=active and (s.stage==1 or s.selected==5)')
change('s.motion.update(dt,active);g.working=-1','s.motion.update(dt,active);g.working=-1\n\tEXTRA.animate(g,s,dt,active)')
change('(s.selected==3 and s.stage==1 and s.elapsed>=3):finish(s)','(s.selected==3 and s.stage==1 and s.elapsed>=3) or (s.selected==4 and s.elapsed>=6) or (s.selected==5 and s.elapsed>=7):finish(s)')
change('var waiting=queued().filter(func(s):return not s.entering)','var waiting=g.souls.filter(func(s):return s.state=="ready")+queued().filter(func(s):return not s.entering)')
change(''' for si in range(stations.size()):
if is_free(stations[si]):free=si;break
if waiting.is_empty() or free<0:
h.model.set_walking(false);continue
var soul=waiting[0];soul.state="reserved";soul.assigned=hi''',''' var soul=null
for candidate in waiting:
for si in range(stations.size()):
if is_free(stations[si]) and sentences.accepts(candidate,stations[si].selected):free=si;soul=candidate;break
if soul!=null:break
if soul==null:
h.model.set_walking(false);continue
soul.state="reserved_next" if soul.get("origin_station",-1)>=0 else "reserved";soul.assigned=hi''')
change('if move_helper(h,g.souls[index].node.position,dt):h.state="deliver";g.souls[index].state="transit"','''var target=g.souls[index].node.position
if g.souls[index].get("origin_station",-1)>=0:target=approach(stations[g.souls[index].origin_station])
if move_helper(h,target,dt):
h.state="deliver";g.souls[index].state="transit";sentences.float_pose(g.souls[index])''')
change('if stations[h.station].soul<0:h.state="idle"','if stations[h.station].soul<0 or stations[h.station].ready:h.state="idle"')
change('delete_button.disabled=not is_free(s)','delete_button.disabled=not is_free(s) or not sentences.can_remove(s)')
change('clampi(int(saved.get("unlock",0)),0,3)','clampi(int(saved.get("unlock",0)),0,TITLES.size()-1)')
change('desired.x=clampf(desired.x,-7.1,7.0)','desired.x=clampf(desired.x,-7.1,11.05)')
change('if desired.x>4 and desired.z< -3.1:','if desired.x>4 and desired.x<7.5 and desired.z< -3.1:')
change('if desired.x>5.7 and desired.z>3:','if desired.x>5.7 and desired.x<7.5 and desired.z>3:')
p.write_text(s,encoding='utf-8')
print('Workshop 0.15 integration applied')