73 lines
1.3 KiB
C#
73 lines
1.3 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class WorldSetup : Control
|
|
{
|
|
[Export] LineEdit seedInput;
|
|
[Export] RichTextLabel seedPreview;
|
|
|
|
public override void _Ready()
|
|
{
|
|
UIStyle.Apply(this);
|
|
UpdateSeedPreview();
|
|
}
|
|
|
|
public void OnSeedChanged(string text)
|
|
{
|
|
UpdateSeedPreview();
|
|
}
|
|
|
|
public void OnStartPressed()
|
|
{
|
|
GameData.seed = GetSelectedSeed();
|
|
GameData.loadSaveOnStart = false;
|
|
GameData.showTutorial = true;
|
|
GetTree().ChangeSceneToFile("res://Scenes/Game.tscn");
|
|
}
|
|
|
|
public void OnBackPressed()
|
|
{
|
|
GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn");
|
|
}
|
|
|
|
private int GetSelectedSeed()
|
|
{
|
|
string text = seedInput.Text.Trim();
|
|
if (text.Length <= 0)
|
|
{
|
|
return new Random().Next(1, int.MaxValue);
|
|
}
|
|
|
|
int numericSeed;
|
|
if (int.TryParse(text, out numericSeed))
|
|
{
|
|
return numericSeed;
|
|
}
|
|
|
|
return CreateTextSeed(text);
|
|
}
|
|
|
|
private int CreateTextSeed(string text)
|
|
{
|
|
int hash = 17;
|
|
foreach (char character in text)
|
|
{
|
|
hash = hash * 31 + character;
|
|
}
|
|
|
|
return Math.Abs(hash);
|
|
}
|
|
|
|
private void UpdateSeedPreview()
|
|
{
|
|
string text = seedInput.Text.Trim();
|
|
if (text.Length <= 0)
|
|
{
|
|
seedPreview.Text = "No seed entered. B.O.B. will pick one from the ruins.";
|
|
return;
|
|
}
|
|
|
|
seedPreview.Text = "Selected seed: " + GetSelectedSeed();
|
|
}
|
|
}
|