Skip to content

Commit eb84240

Browse files
committed
Responsive banner, prettified interface, added bunch of helpful func (≥u≤)
1 parent 24e3bba commit eb84240

File tree

7 files changed

+337
-165
lines changed

7 files changed

+337
-165
lines changed

main/game/classes.py

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
1-
import json
2-
import random
3-
import os
4-
import sys
5-
from time import *
61
from datetime import datetime
72
from game.prep import tsl
8-
9-
10-
11-
def confirm():
12-
dash()
13-
print("Input apa saja untuk melanjutkan")
14-
dash()
15-
input()
16-
17-
18-
def dash(n=36,r=False):
19-
if r == True:
20-
return "="*n
21-
print("="*n)
22-
23-
24-
def loading(duration=3):
25-
end_time = time() + duration # Time duration for the animation
26-
27-
frames = [
28-
"⠂⠄⠅","⠇⠆⠘","⠐⠠⠐",
29-
"⠄⠅⠇","⠆⠘⠐","⠠⠐⠘",
30-
"⠅⠇⠆","⠘⠐⠠","⠐⠘⠂",
31-
"⠇⠆⠘","⠐⠠⠐","⠘⠂⠄",
32-
"⠆⠘⠐","⠠⠐⠘","⠂⠄⠅",
33-
"⠘⠐⠠","⠐⠘⠂","⠄⠅⠇",
34-
"⠐⠠⠐","⠘⠂⠄","⠅⠇⠆",
35-
"⠠⠐⠘","⠂⠄⠅","⠇⠆⠘",
36-
"⠂⠄⠅","⠇⠆⠘","⠐⠠⠐"
37-
]
38-
39-
while time() < end_time:
40-
for frame in frames:
41-
if time() == end_time:
42-
break
43-
sys.stdout.write(f'\r{frame*10}') # \r to overwrite the line
44-
sys.stdout.flush() # Flush the output buffer
45-
sleep(0.05)
46-
clear()
47-
48-
# Final message after the loading is done
49-
# Overwrite the loading text with "Done!"
50-
51-
52-
53-
54-
def clear():
55-
if os.name == 'nt':
56-
os.system('cls')
57-
else:
58-
os.system('clear')
3+
from game.prep import user_width
4+
from game.prep import confirm
5+
from game.prep import dash
6+
from game.prep import dashn
7+
from game.prep import loading
8+
from game.prep import clear
9+
from game.prep import random
10+
from game.prep import json
11+
from game.prep import os
5912

6013
roles_index = [
6114
1,
@@ -443,8 +396,8 @@ def getDetail(self,filepath):
443396
print(f"{tsl['errload']}")
444397
loading(2)
445398
#Contoh:
446-
taring_naga = Item("Taring Naga", 100, "Rare")
447-
taring_naga.update_price(quantity_sold=5) #per 1 quantity = 10 decrease
399+
#taring_naga = Item("Taring Naga", 100, "Rare")
400+
#taring_naga.update_price(quantity_sold=5) #per 1 quantity = 10 decrease
448401
#print(taring_naga.current_price) # Output: Harga menurun berdasarkan jumlah penjualan
449402
#taring_naga.getDetail("items.json")
450403

main/game/fun.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22

3-
from .classes import *
3+
from game.classes import *
4+
5+
import random
6+
47

58
def maintenance():
69
print("Fitur maintenance! :v")

main/game/prep.py

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,170 @@
11

2+
import shutil
3+
from time import *
4+
import json
5+
import os
6+
import sys
7+
import random
28

9+
# Variable Glosarium
10+
MINIMUM_WIDTH = 16
11+
MAXIMUM_WIDTH = 60
12+
STANDARD_WIDTH = 37
13+
user_width = STANDARD_WIDTH
14+
warning = True # button for terminal_warning()
15+
dot = "." # just in case
16+
nl = "\n"
17+
d = '-'
318

4-
import json
19+
lang = {
20+
'en':'English',
21+
'es':'Español',
22+
'fr':'Français',
23+
'gr':'Deutsch',
24+
'ina':'Indonesia',
25+
'jp':'日本語',
26+
'cn':'中国',
27+
'arb':'عربي',
28+
'ind':'भारत'
29+
}
30+
31+
# =========== MAIN METHOD ============
32+
33+
# For clearing view
34+
def clear():
35+
if os.name == 'nt':
36+
os.system('cls')
37+
else:
38+
os.system('clear')
39+
40+
41+
# Refresh width
42+
def refresh_width(debug=False):
43+
now = shutil.get_terminal_size().columns # Get current terminal width
44+
global warning
45+
46+
47+
if warning:
48+
width = now
49+
while True: # Loop until a valid response is given
50+
if width <= MINIMUM_WIDTH:
51+
c = input("Your\nscreen\nis\ntoo\nsmall,\nProceed?\n(y/n)\n(f = fix)\n: ").strip().lower()
52+
if c == 'y':
53+
warning = False
54+
break
55+
elif c == 'f':
56+
print("Please\nset\nyour\nterminal\nwidth\nto, or\nabove\n16pt\nand\nbelow\n36pt", flush=True)
57+
input("Press Enter when done...")
58+
warning = False
59+
break
60+
61+
elif c == 'n':
62+
sys.exit('Thx\nFor\nPlay-\ning!\n:D')
63+
else:
64+
clear() # Clear screen for invalid input
65+
pass
66+
elif width >= MAXIMUM_WIDTH:
67+
c = input("Y O U R S C R E E N I S T O O B I G !\n\nP R O C E E D ( Y / N / F T O F I X) : ").strip().lower()
68+
if c == 'y':
69+
warning = False
70+
break
71+
elif c == 'f':
72+
print(f"{'P L E A S E S E T Y O U R T E R M I N A L W I D T H E Q U A L / A B O V E 1 2 P T A N D B E L O W 3 6 P T ':^{width}}", flush=True)
73+
input("Press Enter when done...")
74+
warning = False
75+
break
76+
elif c == 'n':
77+
sys.exit(f"{'T H A N K S F O R P L A Y I N G ! ! ! :D':^{width}}")
78+
else:
79+
clear() # Clear screen for invalid input
80+
81+
else:
82+
break # Exit if width is within acceptable bounds
83+
84+
now = shutil.get_terminal_size().columns
85+
if debug:
86+
print("Width refreshed to ", now)
87+
88+
return now
89+
90+
91+
92+
# Blank input to continue
93+
def confirm():
94+
dash()
95+
print("Input apa saja untuk melanjutkan")
96+
dashn()
97+
input()
98+
99+
100+
101+
# Open dash
102+
def dash(n=None, r=False, d="="):
103+
if n is None:
104+
n = refresh_width()
105+
if r:
106+
return d * n
107+
print(d * n, flush=True)
108+
109+
110+
111+
# Close dash (with newline)
112+
def dashn(n=None, r=False, d="="):
113+
if n is None:
114+
n = refresh_width()
115+
if r:
116+
return d * n
117+
print(d * n, "\n", flush=True)
118+
119+
120+
121+
# Loading animation
122+
def loading(duration=3):
123+
wide = refresh_width() # Call once
124+
end_time = time() + duration
5125

126+
frames = [
127+
"⠂⠄⠅","⠇⠆⠘","⠐⠠⠐",
128+
"⠄⠅⠇","⠆⠘⠐","⠠⠐⠘",
129+
"⠅⠇⠆","⠘⠐⠠","⠐⠘⠂",
130+
"⠇⠆⠘","⠐⠠⠐","⠘⠂⠄",
131+
"⠆⠘⠐","⠠⠐⠘","⠂⠄⠅",
132+
"⠘⠐⠠","⠐⠘⠂","⠄⠅⠇",
133+
"⠐⠠⠐","⠘⠂⠄","⠅⠇⠆",
134+
"⠠⠐⠘","⠂⠄⠅","⠇⠆⠘",
135+
"⠂⠄⠅","⠇⠆⠘","⠐⠠⠐"
136+
]
137+
138+
while time() < end_time:
139+
for frame in frames:
140+
if time() >= end_time:
141+
break
142+
sys.stdout.write(f'\r{frame * (wide // 3)}')
143+
sys.stdout.flush()
144+
sleep(0.05)
145+
clear()
146+
147+
148+
# printing (prettifier)
149+
# print(index,text) for num list
150+
# printf(text) for plain centered text
151+
def printf(index=None,text=None):
152+
if text == False:
153+
dash()
154+
print("This is a function i built because i get sick of repeating long format print :)")
155+
dashn()
156+
elif index:
157+
if type(index) == str:
158+
return f"{f'{index}':^{refresh_width()}}"
159+
return f"{f'{dash(20,1,d)}{nl}':^{refresh_width()}}\r{f'|{index} {text:<16}|':^{refresh_width()}}{nl}{dash(20,1,d):^{refresh_width()}}"
160+
161+
else:
162+
dash()
163+
print("ERROR PRINTING, ARGS = ",text)
164+
dashn()
165+
166+
167+
# ====== TRANSLATION FUNCTION =====
6168
def load_translations(language="en"):
7169
try:
8170
with open(f"../translation/{language}.json", "r", encoding="utf-8") as file:

0 commit comments

Comments
 (0)