Skip to content

Commit

Permalink
ref: Removed the use of seed rng on visual stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 committed Apr 23, 2022
1 parent 1667552 commit b442046
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
24 changes: 15 additions & 9 deletions src/core/CardTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1770,11 +1770,17 @@ func animate_shuffle(anim_speed : float, style : int) -> void:
var rot_anim
var pos_speed := anim_speed
var rot_speed := anim_speed
# We create a mini-random generator so that we have a
# randf_range function
# We don't want to use the cfc rng, because that is only to preserve
# the game state, and the below randomness is irrelevant
var rng = RandomNumberGenerator.new()
rng.randomize()
if style == CFConst.ShuffleStyle.CORGI:
csize = card_size * 0.65
random_x = CFUtils.randf_range(- csize.x, csize.x)
random_y = CFUtils.randf_range(- csize.y, csize.y)
random_rot = CFUtils.randf_range(-20, 20)
random_x = rng.randf_range(- csize.x, csize.x)
random_y = rng.randf_range(- csize.y, csize.y)
random_rot = rng.randf_range(-20, 20)
center_card_pop_position = starting_card_position \
+ Vector2(random_x, random_y)
start_pos_anim = Tween.TRANS_CIRC
Expand All @@ -1783,9 +1789,9 @@ func animate_shuffle(anim_speed : float, style : int) -> void:
# 2 is splash
elif style == CFConst.ShuffleStyle.SPLASH:
csize = card_size * 0.85
random_x = CFUtils.randf_range(- csize.x, csize.x)
random_y = CFUtils.randf_range(- csize.y, csize.y)
random_rot = CFUtils.randf_range(-180, 180)
random_x = rng.randf_range(- csize.x, csize.x)
random_y = rng.randf_range(- csize.y, csize.y)
random_rot = rng.randf_range(-180, 180)
center_card_pop_position = starting_card_position \
+ Vector2(random_x, random_y)
start_pos_anim = Tween.TRANS_ELASTIC
Expand All @@ -1802,9 +1808,9 @@ func animate_shuffle(anim_speed : float, style : int) -> void:
pos_speed = pos_speed
elif style == CFConst.ShuffleStyle.OVERHAND:
csize = card_size * 1.1
random_x = CFUtils.randf_range(- csize.x/10, csize.x/10)
random_y = CFUtils.randf_range(- csize.y, - csize.y/2)
random_rot = CFUtils.randf_range(-10, 10)
random_x = rng.randf_range(- csize.x/10, csize.x/10)
random_y = rng.randf_range(- csize.y, - csize.y/2)
random_rot = rng.randf_range(-10, 10)
center_card_pop_position = starting_card_position \
+ Vector2(random_x,random_y)
start_pos_anim = Tween.TRANS_CIRC
Expand Down
2 changes: 1 addition & 1 deletion src/dreamscape/Board.gd
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func _recalculate_predictions() -> void:
if end_turn.disabled:
return
yield(get_tree(), "idle_frame")
var snapshot_id = CFUtils.randi_range(1,100000)
var snapshot_id = int(rand_range(1,100000))
get_tree().call_group_flags(get_tree().GROUP_CALL_REALTIME, "combat_effects", "take_snapshot", snapshot_id)
# I want the enemies to be predicted serially
for enemy in get_tree().get_nodes_in_group("EnemyEntities"):
Expand Down
2 changes: 1 addition & 1 deletion src/dreamscape/CardTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func common_pre_run(sceng) -> void:
# We need to store the immersion before it's used by the scripts
# so that the X effects remember what it was
sceng.x_usage = cfc.NMAP.board.counters.get_counter("immersion")
var snapshot_id = CFUtils.randi_range(1,100000)
var snapshot_id = int(rand_range(1,100000))
sceng.predict(snapshot_id)


Expand Down
30 changes: 16 additions & 14 deletions src/dreamscape/HUtils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extends Reference
static func grab_random_texture(specific_dir: String = '') -> ImageTexture:
# The higher the number, the more likely the textures in that directory
# to be chosen

var directories := {
"res://shaders/textures/cc0textures/": 1,
"res://shaders/textures/pixabay/": 2,
Expand All @@ -25,7 +25,7 @@ static func grab_random_texture(specific_dir: String = '') -> ImageTexture:
var image = tex.get_data()
new_texture.create_from_image(image)
return(new_texture)

static func grab_texture(path: String) -> ImageTexture:
var new_texture := ImageTexture.new();
var tex = load(path)
Expand All @@ -37,22 +37,24 @@ static func rnd_color(single_color := false, base : float = 1) -> Vector3:
var r := 1.0 * base
var g := 1.0 * base
var b := 1.0 * base
var rng = RandomNumberGenerator.new()
rng.randomize()
while r > 0.7 * base and g > 0.7 * base and b > 0.7 * base:
r = CFUtils.randf_range(0.0,0.9 * base)
g = CFUtils.randf_range(0.0,0.9 * base)
b = CFUtils.randf_range(0.0,0.9 * base)
r = rng.randf_range(0.0,0.9 * base)
g = rng.randf_range(0.0,0.9 * base)
b = rng.randf_range(0.0,0.9 * base)
var final_color := Vector3(r,g,b)
if single_color:
var solid_color = CFUtils.randi_range(0,2)
var solid_color = rng.randi_range(0,2)
for rgb in [0,1,2]:
if rgb != solid_color:
final_color[rgb] *= 0.2
else:
final_color[rgb] = CFUtils.randf_range(0.7 * base,1.0 * base)
final_color[rgb] = rng.randf_range(0.7 * base,1.0 * base)
return(final_color)


# This method is used for scripts which want to modify a specific amount on a card's
# This method is used for scripts which want to modify a specific amount on a card's
# scripts, which relates to a specific purpose
# This is used for example, when a card applies two different effects, but we
# want to modify just one of them.
Expand All @@ -65,15 +67,15 @@ static func get_amount_key_by_purpose(purpose: String, card_properties: Dictiona
if not card_properties.has("_amounts"):
return(matching_keys)
# If the card properties do not have an "_amount_purpose_map" key
# Then we consider all "effect_stacks" keys to match the purpose
# Then we consider all "effect_stacks" keys to match the purpose
# (assuming there's only one effect being applied and the purpose is an effect)
if not card_properties.has("_amount_purpose_map"):
for key in card_properties["_amounts"]:
if "effect_stacks" in key:
matching_keys.append(key)
# If the card has an "_amount_purpose_map" key, its contents map each
# _amount key to specific effects.
# By comparing the key to the effect we want, we can discover which of the
# If the card has an "_amount_purpose_map" key, its contents map each
# _amount key to specific effects.
# By comparing the key to the effect we want, we can discover which of the
# amounts key correspond to which effect.
else:
for key in card_properties["_amount_purpose_map"]:
Expand Down Expand Up @@ -111,7 +113,7 @@ static func modify_amounts(properties: Dictionary, amount_name: String, value, p
new_value = current_value + float(value)
# For now, I assume no amounts will be negative
# (They should use is_inverted instead)
if new_value < 0:
if new_value < 0:
new_value = 0
if typeof(current_value) == TYPE_INT:
# Decreases are rounded down
Expand Down Expand Up @@ -199,7 +201,7 @@ static func get_random_background(type := 'any') -> Dictionary:
else:
bpath = "res://assets/backgrounds/dark/"
var return_res := {
"image": CFUtils.convert_texture_to_image(bpath + selected_background),
"image": CFUtils.convert_texture_to_image(bpath + selected_background),
"is_bright": selected_background in bright_backgrounds
}
return(return_res)

0 comments on commit b442046

Please sign in to comment.