Stephan Fuchs před 9 měsíci
rodič
revize
df77119353

+ 5 - 1
sugarcube/src/js/Time.js

@@ -236,7 +236,7 @@ class GameTime{
 		4 - the beginning of the night
 		5 - night
 		6 - the end of the night*/
-		let minutesSinceMidnight = this.hour * 60 + this.minutes;
+		let minutesSinceMidnight = this.minutesSinceMidnight;
 		let dayStages = this.dayStagesStartEnd;
 		for (const [key, startEnd] of Object.entries(dayStages)) {
 			if(startEnd[0] < startEnd[1]){
@@ -290,6 +290,10 @@ class GameTime{
 		return (seasons[this.month - 1] == 'winter');
 	}
 
+	get minutesSinceMidnight() {
+		return this.hour * 60 + this.minutes;
+	}
+
 	get now(){
 		//return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minutes, this.seconds));
 		//return setup.DateUTC(this.year, this.month, this.day, this.hour, this.minutes, this.seconds);

+ 7 - 4
sugarcube/src/locations/city/city_residential.tw

@@ -117,14 +117,17 @@
 <</if>>*/
 <p>
 	<<if $time.hour >= 5 and $time.hour <= 23>>
-		The metro station is a 5 minute walk away.'
+		The metro station is a 5 minute walk away.
 	<</if>>
-	<<if $time.hour >= 8 and $time.hour <= 20>>
+	<<if setup.isOpen('shop')>>
 		<<ConnectedLocationCode 'Supermarket' 'locations/shared/store/shop.jpg' 3>>
 			<<gt 'shop'>>
 		<</ConnectedLocationCode>>
-		The supermarket is not far from here.
+		The supermarket is not far from here. It is open
+	<<else>>
+		The nearby supermarket opens
 	<</if>>
+	<<=setup.openTimeToString('shop')>>.
 </p>
 
 <p>
@@ -132,7 +135,7 @@
 		<<ConnectedLocation 'Clinic' 'city_clinic' 'start' 'locations/shared/clinic/poli.jpg' 1>>
 		The clinic is also nearby.
 	<<else>>
-		The clinic is close. It will open at 08:00.
+		The clinic is closed. It will open at 08:00.
 	<</if>>
 	<<if $time.hour >= 6 and $time.hour <= 9 and getvar("$military") == 1 and $time.weekday == 6>>
 		<<ConnectedLocation 'military bus' 'Military' 'start' 'locations/city/shared/military/military.jpg' 60>>

+ 67 - 12
sugarcube/src/locations/stores/shop.tw

@@ -1,8 +1,63 @@
-:: shop_events[events]
-	<<if $time.hour < 8 or $time.hour > 20>>
-		<h2>Supermarket</h2>
-		The supermarket is currently closed.
-		<<include 'shop_navigation'>>
+:: shop_scripts[script]
+setup.openTime ??= {};
+setup.openTime.shop={
+	days:'work',
+	open:[6,0],
+	close:[22,0]
+}
+
+setup.isOpen ??= function(openTime){
+	if(typeof openTime == "string")
+		openTime = setup.openTime[openTime];
+	let days = openTime.days;
+	switch(days){
+		case 'work':
+			days = [1,2,3,4,5,6];
+	}
+	let time = State.variables.time;
+	if(!days.includes(time.weekday))
+		return false;
+
+	let openMinutes = openTime.open[0] * 60 + openTime.open[1];
+	let closeMinutes= openTime.close[0]* 60 + openTime.close[1];
+
+	let minutesSinceMidnight = time.minutesSinceMidnight;
+
+	//Default case: the place isn't open over midnight
+	if(openMinutes <= closeMinutes)
+		return (minutesSinceMidnight >= openMinutes && minutesSinceMidnight < closeMinutes);
+
+	// The place is open over midnight
+	if(minutesSinceMidnight >= openMinutes)
+		return days.includes((time.weekday + 1) % 7 || 7); // The place is only open if it listed to be open tomorrow at well.
+	if(minutesSinceMidnight < closeMinutes)
+		return days.includes((time.weekday + 6) % 7 || 7); // The place is only open if it listed to be open yesterday at well.
+	return false;
+
+}
+
+setup.openTimeToString = function(openTime){
+	let result = '';
+	if(typeof openTime == "string")
+		openTime = setup.openTime[openTime];
+	if(typeof openTime.days == "string"){
+		switch(openTime.days){
+			case 'work': result += 'from Monday to Saturday ';
+		}
+	}
+	result += 'from '+openTime.open[0].toString().padStart(2,"0") +':'+openTime.open[1].toString().padStart(2,"0");
+	result += ' to ' +openTime.close[0].toString().padStart(2,"0")+':'+openTime.close[1].toString().padStart(2,"0");
+	return result;
+}
+
+:: shop_events[events shop_events]
+	<<if !setup.isOpen('shop')>>
+		<<event 100000>>
+			<h2>Supermarket</h2>
+			The supermarket is currently closed.
+			<<include 'shop_navigation'>>
+			<<eventFired>>
+		<</event>>
 	<</if>>
 
 :: shop_navigation[include]
@@ -22,7 +77,7 @@
 			<</ConnectedLocationCode>>
 	<</switch>>
 
-	<<if $time.hour >= 8 and $time.hour <= 20>>
+	<<if setup.isOpen('shop')>>
 		<<if _thisMainPassage == 'shop'>>
 			/*<<ConnectedLocation 'ATM' 'shop_atm' '' "locations/shared/store/atm.jpg" 1>>*/
 		<<else>>
@@ -39,7 +94,7 @@
 
 
 
-:: shop[public indoors hasEvents]
+:: shop[public indoors]
 	<<include 'shop_navigation'>>
 
 	/*<<act "MegaFon">><<set $time.minutes += 1>><<gt 'shop_megafon'>><</act>>
@@ -187,7 +242,7 @@
 	<<include 'shop_navigation'>>
 	<h2>Grocery</h2>
 	<<image "locations/shared/store/shop1.jpg">>
-	<<if $time.hour < 8 or $time.hour > 20>>
+	<<if !setup.isOpen('shop')>>
 		The grocery department is currently closed.
 	<<else>>
 		<<shopItemList>>
@@ -308,7 +363,7 @@
 	<<include 'shop_navigation'>>
 	<h2>Cosmetics Department</h2>
 	<<image "locations/shared/store/shop2.jpg">>
-	<<if $time.hour < 8 or $time.hour > 20>>
+	<<if !setup.isOpen('shop')>>
 		The cosmetics department is currently closed.
 	<<else>>
 		<<set _shopLocation to 'shop_cosmetics'>>
@@ -349,7 +404,7 @@
 	<<include 'shop_navigation'>>
 	<h2>Division of household goods</h2>
 	<<image "locations/shared/store/shop3.jpg">>
-	<<if $time.hour < 8 or $time.hour > 20>>
+	<<if !setup.isOpen('shop')>>
 		The hardware department is currently closed.
 	<<else>>
 		<<shopItemList>>
@@ -384,7 +439,7 @@
 	<h2>Department of Women's Clothing</h2>
 	<<image "locations/shared/store/shop4.jpg">>
 	This department only sells cheap underwear and ice skates.
-	<<if $time.hour < 8 or $time.hour > 20>>
+	<<if !setup.isOpen('shop')>>
 		The women''s clothing department is currently closed.
 	<<else>>
 		<p>Women's panties and bras 300<b>₽</b> each</p>
@@ -430,7 +485,7 @@
 	<<include 'shop_navigation'>>
 	<h2>Department of household appliances</h2>
 	<<image "locations/shared/store/shop5.jpg">>
-	<<if $time.hour < 8 or $time.hour > 20>>
+	<<if !setup.isOpen('shop')>>
 		The household appliance department is currently closed.
 	<<else>>
 		<<shopItemList>>