Skip to content

Commit

Permalink
rudimentary review system for puzzle objects
Browse files Browse the repository at this point in the history
  • Loading branch information
levimhuillet committed Sep 26, 2024
1 parent 42733a5 commit d3f51bc
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 20 deletions.
11 changes: 11 additions & 0 deletions Assets/IReviewable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AstroLab {
public interface IReviewable
{

}
}

11 changes: 11 additions & 0 deletions Assets/IReviewable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 97538578118472346, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_Name
value: LeoPuzzle
value: LeoPuzzle Variant
objectReference: {fileID: 0}
- target: {fileID: 97538578118472347, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_Pivot.x
Expand Down Expand Up @@ -807,6 +807,10 @@ PrefabInstance:
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2243000041275144143, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_SizeDelta.x
value: 420.99
objectReference: {fileID: 0}
- target: {fileID: 2243000041275144143, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand Down Expand Up @@ -1227,6 +1231,10 @@ PrefabInstance:
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3852573825701257943, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_SizeDelta.x
value: 420.992
objectReference: {fileID: 0}
- target: {fileID: 3852573825701257943, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand Down Expand Up @@ -2103,6 +2111,10 @@ PrefabInstance:
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456708861075769442, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_SizeDelta.x
value: 634.78
objectReference: {fileID: 0}
- target: {fileID: 6456708861075769442, guid: b9c5f31db124f4347b5fe18fead74770, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace AstroLab
{
public class UICategoryNotebookModule : UIInterfaceModule
{

[SerializeField] private ReviewQueue m_Queue;

[Space(5)]
[Header("Notebook")]
[SerializeField] private Button[] m_ItemButtons;
Expand Down Expand Up @@ -145,7 +142,7 @@ private void HandleIdentifyClicked()
string realId = FocusMgr.Instance.LastSelectedFocusable.CelestialObj.Data.IdentifyEntryID;

// TODO: dynamic points assignment
m_Queue.AddNewItem(guessId, FocusMgr.Instance.LastSelectedFocusable.CelestialObj, 7f, 3);
ReviewQueue.Instance.AddNewCelestialItem(guessId, FocusMgr.Instance.LastSelectedFocusable.CelestialObj, 7f, 3);
//if (guessId.Equals(realId))
//{
// FocusMgr.Instance.LastSelectedFocusable.CelestialObj.Identified = true;
Expand Down
12 changes: 11 additions & 1 deletion Assets/Project/Scripts/UI/Postcard/PostcardPuzzle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ public bool EvaluateFilled() {

public void OnFinishClicked() {
Log.Warn("[PostcardPuzzle] Clicked Finish!");

ReviewQueue.Instance.AddNewPuzzleItem(this, 7, 5);

if (EvaluateSolved()) {
Destroy(this);
// Destroy(this);
Log.Warn("[PostcardPuzzle] CORRECT! :D");
return;
}
Log.Warn("[PostcardPuzzle] INCORRECT D:");
}

public void OnReviewComplete(bool correct)
{
if (correct)
{
Destroy(this.gameObject);
}
}
}
}
57 changes: 46 additions & 11 deletions Assets/ReviewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class ReviewItem : MonoBehaviour {
[SerializeField] private Timer m_Timer;
[SerializeField] private int m_Points;
[SerializeField] private string m_Guess;
[SerializeField] private CelestialObject m_RefObject;
[SerializeField] private CelestialObject m_RefCelestialObject;
[SerializeField] private PostcardPuzzle m_RefPuzzleObject; // TODO: instead of these explicit checks for celestial vs. puzzle, unify under an IReviewable interface
[Space(4)]

[Header("Components")]
Expand All @@ -36,31 +37,65 @@ void Update() {
m_TimeDial.ArcFill = (1 - m_Timer.GetProgress());
}

public void Populate(ReviewQueue queue, string guess, CelestialObject obj, float time, int pts) {
public void PopulateCelestial(ReviewQueue queue, string guess, CelestialObject obj, float time, int pts) {
m_Queue = queue;
m_Timer = new Timer(time);
m_Guess = guess;
m_RefObject = obj;
m_RefCelestialObject = obj;
m_Points = pts;
m_Image.sprite = obj.Data.Represent2D;
}

public void PopulatePuzzle(ReviewQueue queue, PostcardPuzzle obj, float time, int pts)
{
m_Queue = queue;
m_Timer = new Timer(time);
m_RefPuzzleObject = obj;
m_Points = pts;
m_Image.sprite = null; // obj.Data.Represent2D;
}

private bool CheckCorrect() {
return m_Guess.Equals(m_RefObject.Data.IdentifyEntryID);
// TODO: instead of these explicit checks for celestial vs. puzzle, unify under an IReviewable interface
if (m_RefCelestialObject) {
// celestial object
return m_Guess.Equals(m_RefCelestialObject.Data.IdentifyEntryID);
}
else if (m_RefPuzzleObject) {
// postcard puzzle
return m_RefPuzzleObject.EvaluateSolved();
}

return false;
}

private void SetComplete(bool correct) {
GameConsts consts = FindObjectOfType<GameConsts>();

if (correct) {
m_Background.color = consts.CorrectColor;
m_RefObject.Identified = true;
GameMgr.Events.Dispatch(GameEvents.CelestialObjIdentified);
Log.Msg("Item identified! {0}", m_Guess);
if (m_RefCelestialObject) {
m_Background.color = consts.CorrectColor;
m_RefCelestialObject.Identified = true;
GameMgr.Events.Dispatch(GameEvents.CelestialObjIdentified);
Log.Msg("Item identified! {0}", m_Guess);
}
else if (m_RefPuzzleObject) {
Log.Msg("Puzzle completed successfully!");
m_RefPuzzleObject.OnReviewComplete(true);
}
} else {
m_Background.color = consts.IncorrectColor;
Log.Msg("Incorrect identification :( It's actually {0}", m_RefObject.Data.IdentifyEntryID);
m_Points = consts.IncorrectIDPenalty;
if (m_RefCelestialObject)
{
m_Background.color = consts.IncorrectColor;
Log.Msg("Incorrect identification :( It's actually {0}", m_RefCelestialObject.Data.IdentifyEntryID);
m_Points = consts.IncorrectIDPenalty;
}
else if (m_RefPuzzleObject)
{
Log.Msg("Puzzle completed unsuccessfully :(");
m_RefPuzzleObject.OnReviewComplete(false);
m_Points = consts.IncorrectIDPenalty;
}
}
m_Button.interactable = true;
}
Expand Down
29 changes: 26 additions & 3 deletions Assets/ReviewQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@

namespace AstroLab {
public class ReviewQueue : MonoBehaviour {
public static ReviewQueue Instance;

private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else if (Instance != this)
{
Destroy(this.gameObject);
return;
}
}

public List<ReviewItem> Items = new List<ReviewItem>();

[SerializeField] private ReviewItem ItemPrefab;
public void AddNewItem(string guess, CelestialObject refObject, float time, int pts) {
public void AddNewCelestialItem(string guess, CelestialObject refObject, float time, int pts) {
// TODO: check if item is already in queue
var NewItem = Instantiate(ItemPrefab, transform);
NewItem.PopulateCelestial(this, guess, refObject, time, pts);
Items.Add(NewItem);
}

public void AddNewPuzzleItem(PostcardPuzzle refObject, float time, int pts)
{
// TODO: check if item is already in queue
var NewItem = Instantiate(ItemPrefab, transform);
NewItem.Populate(this, guess, refObject, time, pts);
NewItem.PopulatePuzzle(this, refObject, time, pts);
Items.Add(NewItem);
}
}
}
}

0 comments on commit d3f51bc

Please sign in to comment.