From 3a4ca5fdcdc668f733873c97064264a652aa21ef Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 11 Jul 2022 01:39:53 +0800 Subject: [PATCH] Squashed commit of the following: commit 59b74b946a090dd0b95e21814fe2ed7751b6e09b Author: Andrew Tang Date: Mon Jul 11 01:16:34 2022 +0800 Complete DiceRoller Singleton Version Created script: "DiceRoller.gd" to be the only dice script attached to a node and will act as a singleton. A single DieManager object is created in this script. The DieManager's values can be changed and methods can be called through the DiceRoller Script commit 3a402d43316599c1a883ab583583942dd7723d7b Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:28 2022 -0400 Delete .DS_Store commit c00b24c60ac3cc9a39a93b79cf3352241b1c9186 Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:16 2022 -0400 Delete .DS_Store commit 4f788de0c7676fec60624f50be6284b4f2e419ac Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:05 2022 -0400 Delete .DS_Store commit c20fd855676052b135e7c99af9800af86ad81060 Author: Andrew Tang Date: Mon Jul 4 00:13:15 2022 +0800 Added D10 and easier die selection --- .DS_Store | Bin 6148 -> 0 bytes Phase2/.DS_Store | Bin 6148 -> 0 bytes Phase2/Godot ===(Game Code)===/.DS_Store | Bin 6148 -> 0 bytes .../DiceRoller/DiceRoller.gd | 69 +++++++ .../DiceRoller/DiceRoller.tscn | 10 +- .../DiceRoller/Die.gd | 28 +-- .../DiceRoller/DieManager.gd | 180 +++++++++--------- .../DiceRoller/project.godot | 14 +- 8 files changed, 184 insertions(+), 117 deletions(-) delete mode 100644 .DS_Store delete mode 100644 Phase2/.DS_Store delete mode 100644 Phase2/Godot ===(Game Code)===/.DS_Store create mode 100644 Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.gd diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 14c586a0622dbe3a9b2181333e67d7620ae6d6cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&uiN-6n;vx#-Fvi(U&77>ZgIB5~piO7R8R(v$S5stGiNyU0< zK%vLjr;vJknL3WMrEKT;8yVoatI=E9qh0FJ-2AB+5ndKM(9IuOU=gj-0i94p1r4ZW z=K41G@}AuGVy<|0Uv4}p&f-judljE$X)$UxuSI30`e?Q0)x0(DC_GV^sr)Pa9P{ZAQ?Wx`dI#L3Q%ZiJj)$I~5_Fw71{?#9frl_)cP?-3Aw@3N zG2j^ZFBstcK|&b=i={!mb)eB#0ALkvEwK5gk!z&Iz+!0-5r{CQKvOF06+@VE_@&JY zES3gMISG6D5cbK!-cW>oI>wheokU>JwT=PDz#;=Hrd#Lpzjycjf3e8*90QJle~JN7 z?S|bBKFOY~OCQH)t%QDovT$B$@U{eoK8lgcNAWsT3;dD|U|_K{2oJ>l2xuBy;~4m( G4EzN6Re%`) diff --git a/Phase2/.DS_Store b/Phase2/.DS_Store deleted file mode 100644 index 0dc27f25717df5318ec5857580266ab74e20efce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK(TWo>6us$IciOtp2N(Jx1bk5_+ODg(h)}y#S|EM4~&6+C+6C^5Bf+Dw3ZV*R!u! z$(Arr=srRUD5D`|d&x>`SKt(I3jAvd@V8r`9=_WgUig01AWT$WiorXzgqspjSsqb%J^7MP!xm{oc}3EEA-KE#M4aIsqyIpWe1r$Gt4-!jtA2{Pt9-Bs|Fn;q!Pn>DMprsx%McbU4z4I2xkK%l$Zw)TFD%X_RTMZz{ZsSLxRq z)9Kds?WSzEZ_b)>y0g`4%IzDsX0wX7dHMRCC;hj{QK~**jxd3JSlfoh6JQNatz(o8 zk`VLYPESpK=a14vr3c_LzeYZmPhr8|Bg~Xu`esXu{G;|X7@*(WV z!roAX9v%Hl-JC?npi7+sPJu-Q*34_2&;R?szW*5l&%xnVH}nT4uDG1R$D|CM@_N}Rh4>% z|G;11$}i!+aDwmIo|LBDg#$v!ud+YK{+?g*rGAcyNDT5xkEl&V4hmy^2h|4SaV~3C zGd(S!P;;D+qzJz$&DPkq!zy4E_}3KRwYx(@3Tcd0TUx(IksJq+3^2~g;Ty`=U&_$B z!6zuv#Q1y|ztK!eErR?v}F}NXO z9jl1>Dqq~I@LS;JNZ1*C5};3?)}sg(r5vR}ufQtkCHQ!ED^y~=+>xLW&D13RnfK0%Zj_Ke#B2eS=GlDs`YzM*v_Q z-OAAB&jt2z4fYK#HDUxNv@1}%3UkB|+8zC_;q?tJHEMSf=I|j*WMNJyLPf{?uA-CZ zYqYghz$&n+z?Qyj^ZtK$^Z9?($zE9ntOEa)0-`?jh66m3*<05hj`vy@?QP%_xcD)3ho_zl void: - if passResult: - $Outcome.text = "Successful Roll!" - else: - $Outcome.text = "Failed Roll!" - - var diceResultText = "Rolled Values:\n" - - #Prints the integer calues of each die rolled in the form: "D(num faces): (value rolled)" - for i in range(diceUsed.size()): - diceResultText += ("D" + str(diceUsed[i].numFaces) + ": " + str(rolledValues[i]) + "\n") - - - #NOTE: degree of success is always calculated regardlesss of success/failure. Let me know if this should be changed - degreeOfSuccess = percentRolled - neededPercentageToPass - - #changing labels on screen - $RolledValues.text = diceResultText - $PercentNeeded.text = "Percent Needed to Pass: " + str(neededPercentageToPass * 100) + "%" - $PercentRolled.text = "Percent Rolled: " + str(percentRolled * 100) + "%" - $DegreeOfSuccess.text = "Degree of Success: " + str(degreeOfSuccess * 100) + "%" - - #revealing labels to user - $Outcome.show() - $RolledValues.show() - $PercentNeeded.show() - $PercentRolled.show() - $DegreeOfSuccess.show() + #In case this method is being called on no dice + if len(diceUsed) == 0: + push_error("Cannot roll without any dice!") + var rolledVal = inputedDie.rollDie() + + #add rolled integer value to array + rolledValues.append(rolledVal) + + #Checks if a percentageroll is being done + if isPercentageRoll: + #This conditional is used to detemrine if the rolled value is + #for the tens or ones digit + return float(rolledVal % 10) + + return float(rolledVal) / float(inputedDie.numFaces) -#function for when "roll" button is clicked -func _on_Die_button_down(): +#Rolls all of the dice in diceUsed +#returns the average of all the percentages +func rollDice(): + #In case this method is being called on no dice + if len(diceUsed) == 0: + push_error("Cannot roll without any dice!") + #denominator will equal the total number of dice rolled var denominator = 0 #sum of floats of all rolled die percentages var sumOfPercentages = 0 - #stores the rolled integer value of die in loop - var rolledVal + if isPercentageRoll: + sumOfPercentages += (returnDiePercentage(diceUsed[0]) / 10.0) + (returnDiePercentage(diceUsed[1]) / 100.0) + else: + for die in diceUsed: + sumOfPercentages += returnDiePercentage(die) + denominator += 1 + + var result = [] + + result.append(rolledValues) - #remember that the size of diceInPlay decrements by 1 each time returnDiePercentage is called - while diceInPlay.size() > 0: - rolledVal = diceInPlay[0].rollDie() + if isPercentageRoll: + #Percentage roll result remains the sum of the rolls + result.append(sumOfPercentages) + else: + if denominator == 0: + result.append(0) + #result is average of sum of percentages otherwise rounded to 2 decimcal places - #add rolled integer vaslue to array - rolledValues.append(rolledVal) + result.append(stepify((float(sumOfPercentages) / float(denominator)), 0.0001)) - #add percentage to sum - sumOfPercentages += returnDiePercentage(rolledVal) - - #increment denominator - denominator += 1 + passedRoll = (result[1] >= neededPercentageToPass) +#NOTE: degree of success is always calculated regardlesss of success/failure. Let me know if this should be changed + degreeOfSuccess = result[1] - neededPercentageToPass + result.append(passedRoll) + result.append(neededPercentageToPass) + result.append(degreeOfSuccess) + result.append(desiredDice) - #result is average of sum of percentages - var result = sumOfPercentages / denominator - - passedRoll = (result >= neededPercentageToPass) - - showOnUI(passedRoll, result) + #rollDice result: [[rolledValues], percentRolled, passResult, neededPercent, degreeOfSuccess, dice] return result - -#Reset stored values and text -func _on_Reset_pressed(): - $Outcome.hide() - $PercentNeeded.hide() - $PercentRolled.hide() - $DegreeOfSuccess.hide() - $RolledValues.hide() - #Fill diceInPlay again and empty diceUsed - for die in diceUsed: - diceInPlay.append(die) - diceUsed = [] - rolledValues = [] diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot b/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot index cad39e9..b95a96b 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot @@ -9,13 +9,19 @@ config_version=4 _global_script_classes=[ { -"base": "Button", +"base": "Node2D", "class": "Die", "language": "GDScript", "path": "res://Die.gd" +}, { +"base": "Node2D", +"class": "DieManager", +"language": "GDScript", +"path": "res://DieManager.gd" } ] _global_script_class_icons={ -"Die": "" +"Die": "", +"DieManager": "" } [application] @@ -24,6 +30,10 @@ config/name="GodotDiceRoller_Andrew" run/main_scene="res://DiceRoller.tscn" config/icon="res://icon.png" +[autoload] + +DiceRoller="*res://DiceRoller.gd" + [physics] common/enable_pause_aware_picking=true